How to select cmake binary based on host platform instead of target platform?
- Dominant language
- Rust
- Stars
- 4.4k
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to cross-compile some static cxx libs using cmake within a genrule. The target platform is linux x86_64 and the my laptop (host) is macos arm64. The error message is `buck-out/v2/gen/root/fa160be2e4e88f1c/third-party/__abseil-cpp-build__/sh/genrule.sh: line 5: ../../../tools/__cmake-linux-x86_64-archive__/cmake-linux-x86_64-archive/bin/cmake: cannot execute binary file`. So suspecting that the cmake that is being selected to run is linux instead of the intended macos.
Is there some way to select cmake based on host instead of target platform?
```bazel
# third-party/BUCK
genrule(
name = "protobuf-build",
cmd = "$(location //tools:cmake-archive)/`cat $(location //tools:cmake-path)` -S$(location :protobuf-src) -B. -DCMAKE_INSTALL_PREFIX=$OUT -DCMAKE_CXX_STANDARD=20 -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_PREFIX_PATH=$(location :abseil-cpp-build) -Dprotobuf_ABSL_PROVIDER=package && make -j8 && make install",
out = "protobuf-build",
)
# tools/BUCK
alias(
name = "cmake-archive",
actual = select({
"@root//platforms/config:linux-x86_64": ":cmake-linux-x86_64-archive",
"@root//platforms/config:macos-arm64": ":cmake-macos-arm64-archive",
}),
visibility = [
"//third-party:abseil-cpp-build",
"//third-party:protobuf-build",
],
)
alias(
name = "cmake-path",
actual = select({
"@prelude//os:linux": ":cmake-linux-path",
"@prelude//os:macos": ":cmake-macos-path",
}),
visibility = [
"//third-party:abseil-cpp-build",
"//third-party:protobuf-build",
],
)
http_archive(
name = "cmake-linux-x86_64-archive",
sha256 = "ac31f077ef3378641fa25a3cb980d21b2f083982d3149a8f2eb9154f2b53696b",
strip_prefix = "cmake-3.30.1-linux-x86_64",
urls = ["https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-linux-x86_64.tar.gz"],
)
genrule(name = "cmake-linux-path", cmd = "echo bin/cmake> $OUT", out = "cmake-linux-path")
http_archive(
name = "cmake-macos-arm64-archive",
sha256 = "51e12618829b811bba6f033ee8f39f6192da1b6abb20d82a7899d5134e879a4c",
strip_prefix = "cmake-3.30.1-macos-universal",
urls = ["https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-macos-universal.tar.gz"],
)
genrule(name = "cmake-macos-path", cmd = "echo CMake.app/Contents/bin/cmake> $OUT", out = "cmake-macos-path")
# platforms/config/BUCK
config_setting(
name = "linux-x86_64",
constraint_values = [
"@prelude//cpu/constraints:x86_64",
"@prelude//os/constraints:linux",
],
)
config_setting(
name = "macos-arm64",
constraint_values = [
"@prelude//cpu/constraints:arm64",
"@prelude//os/constraints:macos",
],
)
```
Contributor guide
Assessment
This issue has not been assessed yet.