-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple execution platforms with system_cxx_toolchain
Summary: As mentioned in facebook/buck2#612, I have a C++ project that can be built for either Linux or Windows, without any cross-compilation so Linux and Windows are also the two execution platforms. Since there is remote execution, I wanted to be able to build for Linux from my Windows machine using RE, and vice versa. From the response I got in the above issue, I need to add an `exec_dep` to the toolchain, pointing a compiler target, that then has a `target_compatible_with` with the execution platform the compiler can run on. I tried to add the `target_compatible_with` directly to the toolchain but it didn't work, probably intentional. So I moved some parts of the current system_cxx_toolchain to a separate `NativeCompiler` provider that is then returned by some rules defining a compiler. This compiler target then has the `target_compatible_with` attribute. Can this be merged or should I just have this toolchain in my own repository? It seems useful for everyone, the only disadvantage I can see being that it is not fully backwards compatible. Hopefully I didn't completely misunderstand how execution platforms are supposed to be used. I improved the Visual Studio example to use this new updated toolchain to easily support remote execution. ## Manual testing I used the Visual Studio example and setup my RE workers with Buildbarn. Unfortunately Buildbarn's Windows workers don't currently work with the linking step, I haven't investigated why. The build targeting Windows made from a Windows host works because the linking is done locally but the one done from a Linux host fails. ### Local builds #### Windows ``` buck2 build --target-platforms //buck2_utils/platforms:windows_debug :main ``` Passes #### Linux ``` buck2 build --target-platforms //buck2_utils/platforms:linux_debug :main ``` Passes ### Remote builds #### From Windows ##### Target Windows ``` buck2 build --no-remote-cache -c buck2_re_client.enabled=true --target-platforms //buck2_utils/platforms:windows_debug :main ``` Passes ##### Target Linux ``` buck2 build --no-remote-cache -c buck2_re_client.enabled=true --target-platforms //buck2_utils/platforms:linux_debug :main ``` Passes #### From Linux ##### Target Windows ``` buck2 build --no-remote-cache -c buck2_re_client.enabled=true --target-platforms //buck2_utils/platforms:windows_debug :main ``` Linking fails (The system cannot open the device or file specified.) ##### Target Linux ``` buck2 build --no-remote-cache -c buck2_re_client.enabled=true --target-platforms //buck2_utils/platforms:linux_debug :main ``` Passes X-link: facebook/buck2#629 Reviewed By: JakobDegen Differential Revision: D58667378 Pulled By: KapJI fbshipit-source-id: 3934dd105900d094de71690a7097d7c3909e8cf9
- Loading branch information
1 parent
6c0aa04
commit bf692ab
Showing
5 changed files
with
256 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load("@prelude//utils:source_listing.bzl", "source_listing") | ||
load(":tools.bzl", "path_clang_tools") | ||
|
||
oncall("build_infra") | ||
|
||
source_listing() | ||
|
||
path_clang_tools( | ||
name = "path_clang_tools", | ||
visibility = ["PUBLIC"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under both the MIT license found in the | ||
# LICENSE-MIT file in the root directory of this source tree and the Apache | ||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory | ||
# of this source tree. | ||
|
||
load("@prelude//toolchains:cxx.bzl", "CxxToolsInfo") | ||
|
||
def _path_clang_tools_impl(_ctx) -> list[Provider]: | ||
return [ | ||
DefaultInfo(), | ||
CxxToolsInfo( | ||
compiler = "clang", | ||
compiler_type = "clang", | ||
cxx_compiler = "clang++", | ||
asm_compiler = "clang", | ||
asm_compiler_type = "clang", | ||
rc_compiler = None, | ||
cvtres_compiler = None, | ||
archiver = "ar", | ||
archiver_type = "gnu", | ||
linker = "clang++", | ||
linker_type = "gnu", | ||
), | ||
] | ||
|
||
path_clang_tools = rule( | ||
impl = _path_clang_tools_impl, | ||
attrs = {}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.