-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create self-contained cxx_zig_toolchain (#22)
Summary: Closes #20 Adds `prelude//toolchains/cxx/zig` with a C/C++ toolchain based on `zig cc`. The doc-string of the added module contains a description and examples configurations. Also adds an example to the repository that builds a C++ library and a binary depending on that library using this toolchain. Note, for that example to work in the open source buck2 tree the following additional patch needs to be applied: ```diff diff --git a/.buckconfig b/.buckconfig deleted file mode 100644 index c32af92..0000000 --- a/.buckconfig +++ /dev/null @@ -1,19 +0,0 @@ -[repositories] -root = . -prelude = prelude -ovr_config = prelude -shim = shim -toolchains = shim -fbcode = shim -fbcode_macros = shim -fbsource = shim -buck = shim - -[buildfile] -name = TARGETS - -[build] -execution_platforms = ovr_config//platforms:default - -[parser] -target_platform_detector_spec = target://...->ovr_config//platforms:default diff --git a/prelude/cxx/tools/TARGETS.v2 b/prelude/cxx/tools/TARGETS.v2 index 2030d2f..5db1689 100644 --- a/prelude/cxx/tools/TARGETS.v2 +++ b/prelude/cxx/tools/TARGETS.v2 @@ -1,4 +1,3 @@ -load("fbcode_macros//build_defs/lib:python_common.bzl", "get_ldflags", "get_strip_mode") load(":defs.bzl", "cxx_hacks", "omnibus_environment") prelude = native @@ -538,7 +537,7 @@ omnibus_environment( # We override the binary-level ldflags with library level ldfalgs for # shared roots. We include 2 important things: stripping binaries, and not # discarding GPU code. - shared_root_ld_flags = get_ldflags("", "", "omnibus_root", get_strip_mode("", ""), "") + [ + shared_root_ld_flags = [ "-Wl,--no-discard-section=.nv_fatbin", "-Wl,--no-discard-section=.nvFatBinSegment", # Reorder nv_fatbin after the bss section to avoid overflow ``` Pull Request resolved: #22 Reviewed By: arlyon Differential Revision: D40179209 Pulled By: arlyon fbshipit-source-id: d334f2ad4563281f78ba3f479b8defd09616cabf
- Loading branch information
1 parent
0e49ce5
commit b8e5cf0
Showing
12 changed files
with
1,138 additions
and
0 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,18 @@ | ||
[repositories] | ||
self = . | ||
ovr_config = prelude | ||
prelude = prelude | ||
toolchains = toolchains | ||
buck = no | ||
fbcode = no | ||
fbcode_macros = no | ||
fbsource = no | ||
|
||
[buildfile] | ||
name = BUILD | ||
|
||
[build] | ||
execution_platforms = ovr_config//platforms:default | ||
|
||
[parser] | ||
target_platform_detector_spec = target://...->ovr_config//platforms:default |
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,13 @@ | ||
load("@prelude//platforms:defs.bzl", "execution_platform") | ||
|
||
cxx_library( | ||
name = "lib", | ||
srcs = ["lib.cc"], | ||
headers = ["lib.h"], | ||
) | ||
|
||
cxx_binary( | ||
name = "main", | ||
srcs = ["main.cc"], | ||
deps = [":lib"], | ||
) |
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,6 @@ | ||
#include "lib.h" | ||
#include <iostream> | ||
|
||
void hello() { | ||
std::cout << "Hello World!\n"; | ||
} |
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 @@ | ||
void hello(); |
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,5 @@ | ||
#include "lib.h" | ||
|
||
int main() { | ||
hello(); | ||
} |
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,6 @@ | ||
[repositories] | ||
toolchains = . | ||
prelude = ../prelude | ||
|
||
[buildfile] | ||
name = BUILD |
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,19 @@ | ||
load("@prelude//toolchains/cxx/zig:defs.bzl", "download_zig_distribution", "cxx_zig_toolchain") | ||
# TODO Replace by prelude toolchain once available | ||
load("@toolchains//python:defs.bzl", "system_python_bootstrap_toolchain") | ||
|
||
download_zig_distribution( | ||
name = "zig", | ||
version = "0.9.1", | ||
) | ||
|
||
cxx_zig_toolchain( | ||
name = "cxx", | ||
distribution = ":zig", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
system_python_bootstrap_toolchain( | ||
name = "python_bootstrap", | ||
visibility = ["PUBLIC"], | ||
) |
32 changes: 32 additions & 0 deletions
32
examples/toolchains/cxx_zig_toolchain/toolchains/README.md
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,32 @@ | ||
This example tests the `zig cc` based self-contained C/C++ toolchain. | ||
|
||
To build it within the open source tree of buck2 to you need to | ||
* Create a symlink for the prelude | ||
``` | ||
ln -s ../../../prelude prelude | ||
``` | ||
* Remove the top-level `.buckconfig` | ||
``` | ||
rm ../../../.buckconfig | ||
``` | ||
* Apply the following patch to the prelude | ||
``` | ||
diff --git a/prelude/cxx/tools/TARGETS.v2 b/prelude/cxx/tools/TARGETS.v2 | ||
index 2030d2f..5db1689 100644 | ||
--- a/prelude/cxx/tools/TARGETS.v2 | ||
+++ b/prelude/cxx/tools/TARGETS.v2 | ||
@@ -1,4 +1,3 @@ | ||
-load("@fbcode_macros//build_defs/lib:python_common.bzl", "get_ldflags", "get_strip_mode") | ||
load(":defs.bzl", "cxx_hacks", "omnibus_environment") | ||
prelude = native | ||
@@ -538,7 +537,7 @@ omnibus_environment( | ||
# We override the binary-level ldflags with library level ldfalgs for | ||
# shared roots. We include 2 important things: stripping binaries, and not | ||
# discarding GPU code. | ||
- shared_root_ld_flags = get_ldflags("", "", "omnibus_root", get_strip_mode("", ""), "") + [ | ||
+ shared_root_ld_flags = [ | ||
"-Wl,--no-discard-section=.nv_fatbin", | ||
"-Wl,--no-discard-section=.nvFatBinSegment", | ||
# Reorder nv_fatbin after the bss section to avoid overflow | ||
``` |
19 changes: 19 additions & 0 deletions
19
examples/toolchains/cxx_zig_toolchain/toolchains/python/defs.bzl
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,19 @@ | ||
load( | ||
"@prelude//python_bootstrap:python_bootstrap.bzl", | ||
"PythonBootstrapToolchainInfo", | ||
) | ||
|
||
def _system_python_bootstrap_toolchain(_ctx): | ||
return [ | ||
DefaultInfo(), | ||
PythonBootstrapToolchainInfo( | ||
interpreter = RunInfo(args = ["python3"]), | ||
), | ||
] | ||
|
||
system_python_bootstrap_toolchain = rule( | ||
impl = _system_python_bootstrap_toolchain, | ||
attrs = { | ||
}, | ||
is_toolchain_rule = True, | ||
) |
Oops, something went wrong.