Skip to content

Commit

Permalink
[Bazel] Auto detect platform specific configs (#32)
Browse files Browse the repository at this point in the history
This let's us drop the annoying `--config=clang_linux` from every bazel
build/run/test command. Also simplifies clangd compilation database
generation PR a bit (follow-on).
  • Loading branch information
sjain-stanford authored Jan 18, 2024
1 parent fe5bbe1 commit 5f6a0b9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
7 changes: 6 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated
build:clang_linux --linkopt=-fuse-ld=lld --host_linkopt=-fuse-ld=lld
build:clang_linux --config=generic_clang

build:clang_osx --config=generic_clang
build:clang_macos --config=generic_clang

# Automatically detect host platform to pick config
common --enable_platform_specific_config
build:linux --config=clang_linux
build:macos --config=clang_macos

# Other compilation modes
build:opt --compilation_mode=opt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bazelBuildAndTestLlvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux @llvm-project//mlir/...
bazel test @llvm-project//mlir/...
2 changes: 1 addition & 1 deletion .github/workflows/bazelBuildAndTestStablehlo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux @stablehlo//...
bazel test @stablehlo//...
8 changes: 4 additions & 4 deletions .github/workflows/bazelBuildAndTestTcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel run --config=clang_linux //:buildifier
bazel run //:buildifier
if [ -n "$(git status --porcelain)" ]; then
echo "Please 'bazel run --config=clang_linux //:buildifier' and commit changes."
echo "Please 'bazel run //:buildifier' and commit changes."
exit 1
fi
Expand All @@ -83,12 +83,12 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel build --config=clang_linux //:tcp-opt
bazel build //:tcp-opt
- name: Bazel test mlir-tcp (lit tests, aot compile tests)
run: |
docker run --rm \
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux //test/...
bazel test //test/...
2 changes: 1 addition & 1 deletion .github/workflows/bazelBuildAndTestTorchmlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux @torch-mlir//...
bazel test @torch-mlir//...
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ To build TCP using Bazel, follow these steps:

2. You can now build `tcp-opt` by running:
```shell
bazel build --config=clang_linux //:tcp-opt
bazel build //:tcp-opt
```
(replace `linux` with `osx` for Mac)

3. To run TCP lit and aot compile tests:
```shell
bazel test --config=clang_linux //test/...
bazel test //test/...
```

We welcome contributions to `mlir-tcp`. If you do contribute, please finalize your PR with clang-format and bazel buildifier to ensure the C++ sources and BUILD files are formatted consistently:
Expand All @@ -38,14 +37,14 @@ We welcome contributions to `mlir-tcp`. If you do contribute, please finalize yo
find . -type f -name "*.cpp" -o -name "*.h" | xargs clang-format -i

# buildifer
bazel run --config=clang_linux //:buildifier
bazel run //:buildifier
```

When bumping upstream dependencies (LLVM, Torch-MLIR, StableHLO), you may validate the set of "green commits" by running the corresponding third-party tests:
```shell
bazel test --config=clang_linux @llvm-project//mlir/...
bazel test --config=clang_linux @torch-mlir//...
bazel test --config=clang_linux @stablehlo//...
bazel test @llvm-project//mlir/...
bazel test @torch-mlir//...
bazel test @stablehlo//...
```

The following CI workflows are automatically triggered anytime upstream dependencies (`deps.bzl`) are updated:
Expand Down Expand Up @@ -82,14 +81,14 @@ LLVM_DEBUG(llvm::dbgs() << "This only shows up when -debug or -debug-only=bar is
Then run with the `-debug-only=foo,bar` flag to cuts out messages that aren't associated with the passed `DEBUG_TYPE`s.
```shell
bazel run --config=clang_linux //:tcp-opt -- --some-pass `pwd`/test.mlir -debug-only=foo,bar
bazel run //:tcp-opt -- --some-pass `pwd`/test.mlir -debug-only=foo,bar
```

### `gdb` debugging

To debug `tcp-opt` with [gdb](https://www.sourceware.org/gdb/):
```shell
bazel build --config=clang_linux --config=gdb //:tcp-opt
bazel build --config=gdb //:tcp-opt

gdb --args bazel-bin/tcp-opt -h
```
Expand All @@ -111,6 +110,6 @@ Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or

Do this and re-run:
```shell
bazel build --config=clang_linux @llvm-project//llvm:llvm-symbolizer
bazel build @llvm-project//llvm:llvm-symbolizer
export LLVM_SYMBOLIZER_PATH=`pwd`/bazel-bin/external/llvm-project/llvm/llvm-symbolizer
```

0 comments on commit 5f6a0b9

Please sign in to comment.