facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.53k stars 215 forks source link

CXX Custom Flavors not Picked Up #504

Open melonchucker opened 10 months ago

melonchucker commented 10 months ago

Trying to cross compile with GCC, but making changes in .buckconfig don't seem to get picked up. I followed the examples provided on the buck2 docs here

.buckconfig:

[cxx#xcompile]
host_platform = linux-x86_64
cc = /<path-to-gcc>/arm-linux-gcc
cxx = /<path-to-g++>/arm-linux-gcc
...

BUCK:

cxx_binary(
    name = "main",
    srcs = ["main.cpp"],
    link_style = "static",
)

When I run buck2 build :main#xcompile I get: Cannot handle flavor `xcompile` on target `root//:main#xcompile`. Most flavors are unsupported in Buck2.

ndmitchell commented 10 months ago

I'm afraid any docs under legacy aren't really true. They are docs for Buck1. Someone is working on removing them right now, in response to your entirely reasonable misunderstanding.

The right path for making a GCC binary would be to produce a toolchain, like https://github.com/facebook/buck2/blob/4b508d80f92852431a0cf24da554d39e245315db/prelude/toolchains/cxx.bzl#L175C1-L192C1. So you would create a system_cxx_toolchain for normal GCC, a separate one for arm-linux-gcc (changing the compiler/linker fields). I'd get that working, name your system_cxx_toolchain for ARM as toolchains//:cxx.

Once you have that building I imagine you want to use select on a toolchain alias to select which one based on constraints//arch:arm64. I suggest getting cross compilation only working first, then second trying to make it able to both normal and cross compile.

cormacrelf commented 10 months ago

toolchain_alias is not in prelude. I think it should be. I've needed it too.

Currently there's only an example in https://github.com/facebook/buck2/blob/main/examples/bootstrap/toolchains/toolchain.bzl

ndmitchell commented 10 months ago

I've put up an internal patch moving toolchain_alias into the prelude. Should land open source on Tuesday after everyone is back from Thanksgiving.

melonchucker commented 10 months ago

Awesome! I'll give toolchain_alias a shot when I get back from Thanksgiving.

I'm afraid any docs under legacy aren't really true. They are docs for Buck1. Someone is working on removing them right now, in response to your entirely reasonable misunderstanding.

The right path for making a GCC binary would be to produce a toolchain, like https://github.com/facebook/buck2/blob/4b508d80f92852431a0cf24da554d39e245315db/prelude/toolchains/cxx.bzl#L175C1-L192C1. So you would create a system_cxx_toolchain for normal GCC, a separate one for arm-linux-gcc (changing the compiler/linker fields). I'd get that working, name your system_cxx_toolchain for ARM as toolchains//:cxx.

Once you have that building I imagine you want to use select on a toolchain alias to select which one based on constraints//arch:arm64. I suggest getting cross compilation only working first, then second trying to make it able to both normal and cross compile.

Is there a open ticket for the Buck1->Buck2 doc changes? I didn't see one when I searched.
I can link to that and close this one out, since it looks like toolchains are the right way to use a different compiler and not flavors

ndmitchell commented 10 months ago

We have an internal ticket for it but not a GitHub one. I'll let @lmvasquezg decide whether it's nearly done or needs an external ticket too.