buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

CXX Custom Flavors not Picked Up

Open melonchucker opened this issue 2 years ago • 5 comments

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.

melonchucker avatar Nov 19 '23 15:11 melonchucker

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.

ndmitchell avatar Nov 22 '23 14:11 ndmitchell

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

cormacrelf avatar Nov 24 '23 08:11 cormacrelf

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.

ndmitchell avatar Nov 24 '23 08:11 ndmitchell

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

melonchucker avatar Nov 26 '23 13:11 melonchucker

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.

ndmitchell avatar Nov 27 '23 10:11 ndmitchell