Skip to content

Commit 5f6a0b9

Browse files
[Bazel] Auto detect platform specific configs (#32)
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).
1 parent fe5bbe1 commit 5f6a0b9

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

.bazelrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated
3333
build:clang_linux --linkopt=-fuse-ld=lld --host_linkopt=-fuse-ld=lld
3434
build:clang_linux --config=generic_clang
3535

36-
build:clang_osx --config=generic_clang
36+
build:clang_macos --config=generic_clang
37+
38+
# Automatically detect host platform to pick config
39+
common --enable_platform_specific_config
40+
build:linux --config=clang_linux
41+
build:macos --config=clang_macos
3742

3843
# Other compilation modes
3944
build:opt --compilation_mode=opt

.github/workflows/bazelBuildAndTestLlvm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
-v "$(pwd)":"/opt/src/mlir-tcp" \
6565
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
6666
mlir-tcp:ci \
67-
bazel test --config=clang_linux @llvm-project//mlir/...
67+
bazel test @llvm-project//mlir/...

.github/workflows/bazelBuildAndTestStablehlo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
-v "$(pwd)":"/opt/src/mlir-tcp" \
6565
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
6666
mlir-tcp:ci \
67-
bazel test --config=clang_linux @stablehlo//...
67+
bazel test @stablehlo//...

.github/workflows/bazelBuildAndTestTcp.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ jobs:
7171
-v "$(pwd)":"/opt/src/mlir-tcp" \
7272
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
7373
mlir-tcp:ci \
74-
bazel run --config=clang_linux //:buildifier
74+
bazel run //:buildifier
7575
if [ -n "$(git status --porcelain)" ]; then
76-
echo "Please 'bazel run --config=clang_linux //:buildifier' and commit changes."
76+
echo "Please 'bazel run //:buildifier' and commit changes."
7777
exit 1
7878
fi
7979
@@ -83,12 +83,12 @@ jobs:
8383
-v "$(pwd)":"/opt/src/mlir-tcp" \
8484
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
8585
mlir-tcp:ci \
86-
bazel build --config=clang_linux //:tcp-opt
86+
bazel build //:tcp-opt
8787
8888
- name: Bazel test mlir-tcp (lit tests, aot compile tests)
8989
run: |
9090
docker run --rm \
9191
-v "$(pwd)":"/opt/src/mlir-tcp" \
9292
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
9393
mlir-tcp:ci \
94-
bazel test --config=clang_linux //test/...
94+
bazel test //test/...

.github/workflows/bazelBuildAndTestTorchmlir.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
-v "$(pwd)":"/opt/src/mlir-tcp" \
6565
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
6666
mlir-tcp:ci \
67-
bazel test --config=clang_linux @torch-mlir//...
67+
bazel test @torch-mlir//...

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ To build TCP using Bazel, follow these steps:
2323

2424
2. You can now build `tcp-opt` by running:
2525
```shell
26-
bazel build --config=clang_linux //:tcp-opt
26+
bazel build //:tcp-opt
2727
```
28-
(replace `linux` with `osx` for Mac)
2928

3029
3. To run TCP lit and aot compile tests:
3130
```shell
32-
bazel test --config=clang_linux //test/...
31+
bazel test //test/...
3332
```
3433

3534
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:
@@ -38,14 +37,14 @@ We welcome contributions to `mlir-tcp`. If you do contribute, please finalize yo
3837
find . -type f -name "*.cpp" -o -name "*.h" | xargs clang-format -i
3938

4039
# buildifer
41-
bazel run --config=clang_linux //:buildifier
40+
bazel run //:buildifier
4241
```
4342

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

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

8887
### `gdb` debugging
8988

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

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

112111
Do this and re-run:
113112
```shell
114-
bazel build --config=clang_linux @llvm-project//llvm:llvm-symbolizer
113+
bazel build @llvm-project//llvm:llvm-symbolizer
115114
export LLVM_SYMBOLIZER_PATH=`pwd`/bazel-bin/external/llvm-project/llvm/llvm-symbolizer
116115
```

0 commit comments

Comments
 (0)