Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to select cmake binary based on host platform instead of target platform? #731

Open
Lev1ty opened this issue Aug 2, 2024 · 0 comments

Comments

@Lev1ty
Copy link
Contributor

Lev1ty commented Aug 2, 2024

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?

# 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",
    ],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant