|
| 1 | +# Building and Testing the clang-format 5.0.1 Docker Container for aarch64 |
| 2 | + |
| 3 | +This directory contains the Dockerfile and build script for creating a Docker container with clang-format 5.0.1 for Linux aarch64/ARM64 architecture. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Docker installed and running |
| 8 | +- For aarch64 builds: Docker running on an aarch64 host, or Docker buildx configured for cross-platform builds |
| 9 | +- Git repository with at least 20 commits (for testing the format task) |
| 10 | + |
| 11 | +## Building the Container |
| 12 | + |
| 13 | +### Option 1: Build Locally (Recommended for Testing) |
| 14 | + |
| 15 | +If you're on an aarch64 machine or have buildx configured: |
| 16 | + |
| 17 | +```bash |
| 18 | +cd dev-tools/docker |
| 19 | +docker build --no-cache -t ml-check-style-aarch64:local check_style_image_aarch64 |
| 20 | +``` |
| 21 | + |
| 22 | +This will: |
| 23 | +- Build the image with tag `ml-check-style-aarch64:local` |
| 24 | +- Take approximately 30-60 minutes (building LLVM from source) |
| 25 | +- Create an image with clang-format 5.0.1 installed |
| 26 | + |
| 27 | +### Option 2: Using the Build Script |
| 28 | + |
| 29 | +The build script is designed for pushing to the Elastic registry: |
| 30 | + |
| 31 | +```bash |
| 32 | +cd dev-tools/docker |
| 33 | +./build_check_style_image_aarch64.sh |
| 34 | +``` |
| 35 | + |
| 36 | +**Note**: This requires authentication to `docker.elastic.co`. For local testing, use Option 1. |
| 37 | + |
| 38 | +### Option 3: Cross-Platform Build (if not on aarch64) |
| 39 | + |
| 40 | +If you're not on an aarch64 machine, you can use Docker buildx: |
| 41 | + |
| 42 | +```bash |
| 43 | +# Enable buildx (if not already enabled) |
| 44 | +docker buildx create --name multiarch --use |
| 45 | +docker buildx inspect --bootstrap |
| 46 | + |
| 47 | +# Build for aarch64 |
| 48 | +cd dev-tools/docker |
| 49 | +docker buildx build --platform linux/arm64 --no-cache -t ml-check-style-aarch64:local -f check_style_image_aarch64/Dockerfile check_style_image_aarch64 --load |
| 50 | +``` |
| 51 | + |
| 52 | +## Testing the Container |
| 53 | + |
| 54 | +### 1. Verify clang-format Version |
| 55 | + |
| 56 | +First, verify that clang-format 5.0.1 is correctly installed: |
| 57 | + |
| 58 | +```bash |
| 59 | +docker run --rm ml-check-style-aarch64:local clang-format --version |
| 60 | +``` |
| 61 | + |
| 62 | +Expected output: |
| 63 | +``` |
| 64 | +clang-format version 5.0.1 (tags/RELEASE_501/final) |
| 65 | +``` |
| 66 | + |
| 67 | +### 2. Test Formatting a Single File |
| 68 | + |
| 69 | +Test that clang-format works on a sample file: |
| 70 | + |
| 71 | +```bash |
| 72 | +# Create a test file with formatting issues |
| 73 | +cat > /tmp/test_format.cc << 'EOF' |
| 74 | +int main(){return 0;} |
| 75 | +EOF |
| 76 | + |
| 77 | +# Format it |
| 78 | +docker run --rm -v /tmp:/tmp ml-check-style-aarch64:local clang-format -i /tmp/test_format.cc |
| 79 | + |
| 80 | +# Check the result |
| 81 | +cat /tmp/test_format.cc |
| 82 | +``` |
| 83 | + |
| 84 | +### 3. Test Formatting Files from Recent Commits |
| 85 | + |
| 86 | +Test the complete workflow that will be used in the VS Code task: |
| 87 | + |
| 88 | +```bash |
| 89 | +# From the repository root |
| 90 | +cd /path/to/ml-cpp |
| 91 | + |
| 92 | +# Get files changed in last 20 commits and format them |
| 93 | +docker run --rm \ |
| 94 | + -v $(pwd):/ml-cpp \ |
| 95 | + -u $(id -u):$(id -g) \ |
| 96 | + ml-check-style-aarch64:local \ |
| 97 | + bash -c 'cd /ml-cpp && git diff --name-only --diff-filter=ACMRT HEAD~20 HEAD | grep -E "\.(cc|h)$" | grep -v "^3rd_party" | grep -v "^build-setup" | xargs -r clang-format -i' |
| 98 | + |
| 99 | +# Check git status to see what was changed |
| 100 | +git status |
| 101 | +``` |
| 102 | + |
| 103 | +### 4. Test with a Dry Run (Preview Changes) |
| 104 | + |
| 105 | +To see what files would be formatted without actually changing them: |
| 106 | + |
| 107 | +```bash |
| 108 | +cd /path/to/ml-cpp |
| 109 | + |
| 110 | +# Get list of files that would be formatted |
| 111 | +docker run --rm \ |
| 112 | + -v $(pwd):/ml-cpp \ |
| 113 | + ml-check-style-aarch64:local \ |
| 114 | + bash -c 'cd /ml-cpp && git diff --name-only --diff-filter=ACMRT HEAD~20 HEAD | grep -E "\.(cc|h)$" | grep -v "^3rd_party" | grep -v "^build-setup"' |
| 115 | +``` |
| 116 | + |
| 117 | +### 5. Test the VS Code Task Command |
| 118 | + |
| 119 | +You can test the exact command that will be used in the VS Code task: |
| 120 | + |
| 121 | +```bash |
| 122 | +cd /path/to/ml-cpp |
| 123 | + |
| 124 | +docker run --rm \ |
| 125 | + -v $(pwd):/ml-cpp \ |
| 126 | + -u $(id -u):$(id -g) \ |
| 127 | + ml-check-style-aarch64:local \ |
| 128 | + bash -c 'cd /ml-cpp && git diff --name-only --diff-filter=ACMRT HEAD~20 HEAD | grep -E "\.(cc|h)$" | grep -v "^3rd_party" | grep -v "^build-setup" | xargs -r clang-format -i' |
| 129 | +``` |
| 130 | + |
| 131 | +## Using in VS Code |
| 132 | + |
| 133 | +### Setting Up the Task |
| 134 | + |
| 135 | +1. Create or edit `.vscode/tasks.json` in your workspace root: |
| 136 | + |
| 137 | +```json |
| 138 | +{ |
| 139 | + "version": "2.0.0", |
| 140 | + "tasks": [ |
| 141 | + { |
| 142 | + "label": "Format changed files (last 20 commits)", |
| 143 | + "type": "shell", |
| 144 | + "command": "docker run --rm -v ${workspaceFolder}:/ml-cpp -u $(id -u):$(id -g) ml-check-style-aarch64:local bash -c 'cd /ml-cpp && git diff --name-only --diff-filter=ACMRT HEAD~20 HEAD | grep -E \"\\.(cc|h)$\" | grep -v \"^3rd_party\" | grep -v \"^build-setup\" | xargs -r clang-format -i'", |
| 145 | + "problemMatcher": [], |
| 146 | + "presentation": { |
| 147 | + "reveal": "always", |
| 148 | + "panel": "shared" |
| 149 | + } |
| 150 | + } |
| 151 | + ] |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +**Note**: Change `ml-check-style-aarch64:local` to `docker.elastic.co/ml-dev/ml-check-style-aarch64:1` if using the official registry image. |
| 156 | + |
| 157 | +### Running the Task |
| 158 | + |
| 159 | +1. Open Command Palette (`Cmd+Shift+P` on macOS, `Ctrl+Shift+P` on Linux/Windows) |
| 160 | +2. Type "Tasks: Run Task" |
| 161 | +3. Select "Format changed files (last 20 commits)" |
| 162 | +4. The task will format all `.cc` and `.h` files changed in the last 20 commits |
| 163 | + |
| 164 | +## Troubleshooting |
| 165 | + |
| 166 | +### Issue: "clang-format version mismatch" |
| 167 | +- **Solution**: The build may have failed. Check the Docker build logs for errors. |
| 168 | +- Rebuild the container with `--no-cache` flag |
| 169 | + |
| 170 | +### Issue: "Permission denied" when formatting files |
| 171 | +- **Solution**: Ensure you're using `-u $(id -u):$(id -g)` in the docker run command |
| 172 | +- This ensures files are created with your user ID |
| 173 | + |
| 174 | +### Issue: "No files to format" |
| 175 | +- **Solution**: Check that you have at least 20 commits in your repository |
| 176 | +- Try reducing the number: change `HEAD~20` to `HEAD~10` or `HEAD~5` |
| 177 | + |
| 178 | +### Issue: Build fails with "No such file or directory" for LLVM |
| 179 | +- **Solution**: The LLVM release URLs might have changed. Check `https://releases.llvm.org/5.0.1/` for correct filenames |
| 180 | + |
| 181 | +### Issue: Build takes too long |
| 182 | +- **Solution**: This is expected - building LLVM from source takes 30-60 minutes |
| 183 | +- The build only compiles clang-format (not full LLVM) to minimize time |
| 184 | +- Consider using a pre-built image from the registry if available |
| 185 | + |
| 186 | +## Verifying the Build |
| 187 | + |
| 188 | +After building, you can inspect the image: |
| 189 | + |
| 190 | +```bash |
| 191 | +# Check image size |
| 192 | +docker images ml-check-style-aarch64:local |
| 193 | + |
| 194 | +# Inspect the image |
| 195 | +docker inspect ml-check-style-aarch64:local |
| 196 | + |
| 197 | +# Check what's installed |
| 198 | +docker run --rm ml-check-style-aarch64:local ls -la /usr/local/bin/clang-format |
| 199 | +``` |
| 200 | + |
| 201 | +## Next Steps |
| 202 | + |
| 203 | +Once the container is built and tested: |
| 204 | +1. Test formatting on a few files manually |
| 205 | +2. Add the VS Code task to your workspace |
| 206 | +3. Run the task to format files from recent commits |
| 207 | +4. Review the changes with `git diff` before committing |
| 208 | + |
0 commit comments