mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-03-01 04:56:50 +00:00
Add buck2 CI
This commit is contained in:
parent
8e5e1f590e
commit
dcbc8773d5
36
.buckconfig
36
.buckconfig
@ -1,23 +1,17 @@
|
||||
[repositories]
|
||||
repo = .
|
||||
prelude = tools/buck/buck2/prelude
|
||||
toolchains = tools/buck/toolchains
|
||||
ovr_config = tools/buck/buck2/prelude
|
||||
buck = none
|
||||
fbcode = none
|
||||
fbsource = none
|
||||
|
||||
[project]
|
||||
# We use some symlinks in the source tree, but they get eliminated by `cargo
|
||||
# publish` and `cargo vendor` so this allow_symlinks setting should not be
|
||||
# required downstream.
|
||||
allow_symlinks = allow
|
||||
# Hide BUCK files under target/package/ from `buck build ...`. Otherwise:
|
||||
# $ buck build ...
|
||||
# //target/package/cxx-0.3.0/tests:ffi references non-existing file or directory 'target/package/cxx-0.3.0/tests/ffi/lib.rs'
|
||||
ignore = target
|
||||
|
||||
# Hide BUCK files under target/package/ from `buck build ...`. Otherwise:
|
||||
# $ buck build ...
|
||||
# //target/package/cxx-0.3.0/tests:ffi references non-existing file or directory 'target/package/cxx-0.3.0/tests/ffi/lib.rs'
|
||||
ignore = target
|
||||
|
||||
[cxx]
|
||||
cxxflags = -std=c++11
|
||||
|
||||
[rust]
|
||||
default_edition = required
|
||||
rustc_flags = \
|
||||
-Clink-arg=-fuse-ld=lld \
|
||||
-Crelocation-model=dynamic-no-pic \
|
||||
--cap-lints=allow
|
||||
|
||||
[defaults.rust_library]
|
||||
type = check
|
||||
[parser]
|
||||
target_platform_detector_spec = target://...->ovr_config//platforms:default
|
||||
|
@ -1 +0,0 @@
|
||||
last
|
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@ -62,6 +62,26 @@ jobs:
|
||||
env:
|
||||
RUSTFLAGS: --cfg compile_error_if_alloc --cfg cxx_experimental_no_alloc ${{env.RUSTFLAGS}}
|
||||
|
||||
buck:
|
||||
name: Buck
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request'
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- uses: dtolnay/install@buck2
|
||||
- name: Install lld
|
||||
run: sudo apt-get install lld
|
||||
- name: Vendor dependencies
|
||||
run: |
|
||||
cp third-party/Cargo.lock .
|
||||
cargo vendor --versioned-dirs --locked third-party/vendor
|
||||
- run: buck2 run demo
|
||||
- run: buck2 build ...
|
||||
|
||||
bazel:
|
||||
name: Bazel
|
||||
runs-on: ubuntu-latest
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "tools/buck/buck2"]
|
||||
path = tools/buck/buck2
|
||||
url = https://github.com/facebookincubator/buck2
|
17
BUCK
17
BUCK
@ -15,7 +15,10 @@ rust_library(
|
||||
|
||||
rust_binary(
|
||||
name = "codegen",
|
||||
srcs = glob(["gen/cmd/src/**/*.rs"]) + ["gen/cmd/src/gen/include/cxx.h"],
|
||||
srcs = glob(["gen/cmd/src/**/*.rs"]) + [
|
||||
"gen/cmd/src/gen",
|
||||
"gen/cmd/src/syntax",
|
||||
],
|
||||
crate = "cxxbridge",
|
||||
edition = "2018",
|
||||
visibility = ["PUBLIC"],
|
||||
@ -41,7 +44,7 @@ cxx_library(
|
||||
|
||||
rust_library(
|
||||
name = "macro",
|
||||
srcs = glob(["macro/src/**/*.rs"]),
|
||||
srcs = glob(["macro/src/**/*.rs"]) + ["macro/src/syntax"],
|
||||
crate = "cxxbridge_macro",
|
||||
edition = "2018",
|
||||
proc_macro = True,
|
||||
@ -54,7 +57,10 @@ rust_library(
|
||||
|
||||
rust_library(
|
||||
name = "build",
|
||||
srcs = glob(["gen/build/src/**/*.rs"]),
|
||||
srcs = glob(["gen/build/src/**/*.rs"]) + [
|
||||
"gen/build/src/gen",
|
||||
"gen/build/src/syntax",
|
||||
],
|
||||
edition = "2018",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
@ -70,7 +76,10 @@ rust_library(
|
||||
|
||||
rust_library(
|
||||
name = "lib",
|
||||
srcs = glob(["gen/lib/src/**/*.rs"]),
|
||||
srcs = glob(["gen/lib/src/**/*.rs"]) + [
|
||||
"gen/lib/src/gen",
|
||||
"gen/lib/src/syntax",
|
||||
],
|
||||
edition = "2018",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
|
@ -29,6 +29,6 @@ cxx_library(
|
||||
|
||||
cxx_library(
|
||||
name = "blobstore-include",
|
||||
exported_deps = ["//:core"],
|
||||
exported_headers = ["include/blobstore.h"],
|
||||
deps = ["//:core"],
|
||||
)
|
||||
|
10
tests/BUCK
10
tests/BUCK
@ -32,20 +32,26 @@ cxx_library(
|
||||
":bridge/source",
|
||||
":module/source",
|
||||
],
|
||||
headers = {
|
||||
exported_deps = ["//:core"],
|
||||
exported_headers = {
|
||||
"ffi/lib.rs.h": ":bridge/header",
|
||||
"ffi/module.rs.h": ":module/header",
|
||||
"ffi/tests.h": "ffi/tests.h",
|
||||
},
|
||||
deps = ["//:core"],
|
||||
)
|
||||
|
||||
rust_cxx_bridge(
|
||||
name = "bridge",
|
||||
src = "ffi/lib.rs",
|
||||
deps = [
|
||||
":impl",
|
||||
],
|
||||
)
|
||||
|
||||
rust_cxx_bridge(
|
||||
name = "module",
|
||||
src = "ffi/module.rs",
|
||||
deps = [
|
||||
":impl",
|
||||
],
|
||||
)
|
||||
|
1
tools/buck/buck2
Submodule
1
tools/buck/buck2
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit c117530548ddc3ec1e85b5af52e5fe678b32dff0
|
@ -1,8 +0,0 @@
|
||||
def genrule(cmd, **kwargs):
|
||||
# Resolve a distracting inconsistency between Buck and Bazel.
|
||||
# Bazel creates the directory for your output file, while Buck expects the
|
||||
# cmd to create it.
|
||||
#
|
||||
# TODO: send this as a PR to Buck, because Bazel's behavior here is better.
|
||||
cmd = "mkdir -p `dirname ${OUT}`; " + cmd
|
||||
native.genrule(cmd = cmd, **kwargs)
|
@ -1,19 +1,17 @@
|
||||
load("//tools/buck:genrule.bzl", "genrule")
|
||||
|
||||
def rust_cxx_bridge(name, src, deps = []):
|
||||
genrule(
|
||||
native.genrule(
|
||||
name = "%s/header" % name,
|
||||
out = src + ".h",
|
||||
cmd = "cp $(location :%s/generated)/generated.h ${OUT}" % name,
|
||||
)
|
||||
|
||||
genrule(
|
||||
native.genrule(
|
||||
name = "%s/source" % name,
|
||||
out = src + ".cc",
|
||||
cmd = "cp $(location :%s/generated)/generated.cc ${OUT}" % name,
|
||||
)
|
||||
|
||||
genrule(
|
||||
native.genrule(
|
||||
name = "%s/generated" % name,
|
||||
srcs = [src],
|
||||
out = ".",
|
||||
@ -21,14 +19,14 @@ def rust_cxx_bridge(name, src, deps = []):
|
||||
type = "cxxbridge",
|
||||
)
|
||||
|
||||
cxx_library(
|
||||
native.cxx_library(
|
||||
name = name,
|
||||
srcs = [":%s/source" % name],
|
||||
preferred_linkage = "static",
|
||||
deps = deps + [":%s/include" % name],
|
||||
exported_deps = deps + [":%s/include" % name],
|
||||
)
|
||||
|
||||
cxx_library(
|
||||
native.cxx_library(
|
||||
name = "%s/include" % name,
|
||||
exported_headers = [":%s/header" % name],
|
||||
)
|
||||
|
@ -1,5 +1,3 @@
|
||||
load("//tools/buck:genrule.bzl", "genrule")
|
||||
|
||||
def rust_library(
|
||||
name,
|
||||
srcs,
|
||||
@ -9,7 +7,7 @@ def rust_library(
|
||||
build_script = None,
|
||||
**kwargs):
|
||||
if build_script:
|
||||
rust_binary(
|
||||
native.rust_binary(
|
||||
name = "%s@build" % name,
|
||||
srcs = srcs + [build_script],
|
||||
crate = "build",
|
||||
@ -19,7 +17,7 @@ def rust_library(
|
||||
rustc_flags = rustc_flags,
|
||||
)
|
||||
|
||||
genrule(
|
||||
native.genrule(
|
||||
name = "%s@cfg" % name,
|
||||
out = "output",
|
||||
cmd = "env RUSTC=rustc TARGET= $(exe :%s@build) | sed -n s/^cargo:rustc-cfg=/--cfg=/p > ${OUT}" % name,
|
||||
|
16
tools/buck/toolchains/BUCK
Normal file
16
tools/buck/toolchains/BUCK
Normal file
@ -0,0 +1,16 @@
|
||||
load(":toolchain.bzl", "cxx_toolchain", "python_bootstrap_toolchain", "rust_toolchain")
|
||||
|
||||
cxx_toolchain(
|
||||
name = "cxx",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
python_bootstrap_toolchain(
|
||||
name = "python_bootstrap",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
rust_toolchain(
|
||||
name = "rust",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
118
tools/buck/toolchains/toolchain.bzl
Normal file
118
tools/buck/toolchains/toolchain.bzl
Normal file
@ -0,0 +1,118 @@
|
||||
load(
|
||||
"@prelude//cxx:cxx_toolchain_types.bzl",
|
||||
"BinaryUtilitiesInfo",
|
||||
"CCompilerInfo",
|
||||
"CxxCompilerInfo",
|
||||
"CxxPlatformInfo",
|
||||
"CxxToolchainInfo",
|
||||
"LinkerInfo",
|
||||
)
|
||||
load("@prelude//cxx:headers.bzl", "HeaderMode")
|
||||
load("@prelude//linking:link_info.bzl", "LinkStyle")
|
||||
load("@prelude//python_bootstrap:python_bootstrap.bzl", "PythonBootstrapToolchainInfo")
|
||||
load("@prelude//rust:rust_toolchain.bzl", "RustPlatformInfo", "RustToolchainInfo")
|
||||
|
||||
DEFAULT_MAKE_COMP_DB = "@prelude//cxx/tools:make_comp_db"
|
||||
|
||||
def _cxx_toolchain(ctx):
|
||||
"""
|
||||
A very simple toolchain that is hardcoded to the current environment.
|
||||
"""
|
||||
return [
|
||||
DefaultInfo(),
|
||||
CxxToolchainInfo(
|
||||
mk_comp_db = ctx.attrs.make_comp_db,
|
||||
linker_info = LinkerInfo(
|
||||
linker = RunInfo(args = ["g++"]),
|
||||
linker_flags = ["-lstdc++"],
|
||||
archiver = RunInfo(args = ["ar", "rcs"]),
|
||||
type = "gnu",
|
||||
link_binaries_locally = True,
|
||||
archive_objects_locally = True,
|
||||
use_archiver_flags = False,
|
||||
static_dep_runtime_ld_flags = [],
|
||||
static_pic_dep_runtime_ld_flags = [],
|
||||
shared_dep_runtime_ld_flags = [],
|
||||
independent_shlib_interface_linker_flags = [],
|
||||
mk_shlib_intf = ctx.attrs.make_shlib_intf,
|
||||
link_style = LinkStyle(ctx.attrs.link_style),
|
||||
link_weight = 1,
|
||||
binary_extension = "",
|
||||
object_file_extension = "o",
|
||||
shared_library_name_format = "lib{}.so",
|
||||
shared_library_versioned_name_format = "lib{}.so.{}",
|
||||
static_library_extension = "a",
|
||||
),
|
||||
binary_utilities_info = BinaryUtilitiesInfo(
|
||||
nm = RunInfo(args = ["nm"]),
|
||||
ranlib = RunInfo(args = ["raninfo"]),
|
||||
strip = RunInfo(args = ["strip"]),
|
||||
),
|
||||
cxx_compiler_info = CxxCompilerInfo(
|
||||
compiler = RunInfo(args = ["clang++"]),
|
||||
preprocessor_flags = [],
|
||||
compiler_flags = [],
|
||||
compiler_type = "clang",
|
||||
),
|
||||
c_compiler_info = CCompilerInfo(
|
||||
preprocessor_flags = [],
|
||||
),
|
||||
header_mode = HeaderMode("symlink_tree_only"),
|
||||
),
|
||||
CxxPlatformInfo(name = "x86_64"),
|
||||
]
|
||||
|
||||
cxx_toolchain = rule(
|
||||
impl = _cxx_toolchain,
|
||||
attrs = {
|
||||
"link_style": attrs.string(default = "static"),
|
||||
"make_comp_db": attrs.dep(providers = [RunInfo], default = DEFAULT_MAKE_COMP_DB),
|
||||
"make_shlib_intf": attrs.dep(providers = [RunInfo], default = DEFAULT_MAKE_COMP_DB),
|
||||
},
|
||||
is_toolchain_rule = True,
|
||||
)
|
||||
|
||||
def _python_bootstrap_toolchain(_ctx):
|
||||
return [
|
||||
DefaultInfo(),
|
||||
PythonBootstrapToolchainInfo(
|
||||
interpreter = "python3",
|
||||
),
|
||||
]
|
||||
|
||||
python_bootstrap_toolchain = rule(
|
||||
impl = _python_bootstrap_toolchain,
|
||||
attrs = {},
|
||||
is_toolchain_rule = True,
|
||||
)
|
||||
|
||||
def _rust_toolchain(ctx):
|
||||
return [
|
||||
DefaultInfo(),
|
||||
RustToolchainInfo(
|
||||
allow_lints = [],
|
||||
clippy_driver = "clippy-driver",
|
||||
compiler = "rustc",
|
||||
deny_lints = [],
|
||||
rustc_action = ctx.attrs.rustc_action[RunInfo],
|
||||
rustc_binary_flags = [],
|
||||
rustc_check_flags = [],
|
||||
rustc_flags = ["-Clink-arg=-fuse-ld=lld"],
|
||||
rustc_target_triple = "x86_64-unknown-linux-gnu",
|
||||
rustc_test_flags = [],
|
||||
rustdoc = "rustdoc",
|
||||
rustdoc_flags = [],
|
||||
warn_lints = [],
|
||||
),
|
||||
RustPlatformInfo(
|
||||
name = "x86_64",
|
||||
),
|
||||
]
|
||||
|
||||
rust_toolchain = rule(
|
||||
impl = _rust_toolchain,
|
||||
attrs = {
|
||||
"rustc_action": attrs.dep(providers = [RunInfo], default = "prelude//rust/tools:rustc_action"),
|
||||
},
|
||||
is_toolchain_rule = True,
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user