diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 96c055eec..14cc3e69f 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -13,12 +13,24 @@ jobs: steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 - - run: echo CARGO_HOME=$GITHUB_WORKSPACE/.cargo >> $GITHUB_ENV + - run: |- + echo CARGO_HOME=$GITHUB_WORKSPACE/.cargo >> $GITHUB_ENV + echo $GITHUB_WORKSPACE/target/debug >> $GITHUB_PATH shell: bash - run: cargo build --locked - run: cargo test - - run: |- + - uses: dtolnay/install-buck2@latest + - name: Build example project (Ubuntu, macOS) + run: |- cd example - ./setup.sh # run reindeer buckify - cat ./third-party/BUCK - shell: bash + reindeer --third-party-dir third-party buckify + buck2 init --git + buck2 run "//project:test" + if: matrix.os == 'ubuntu' || matrix.os == 'macos' + - name: Build example project (Windows) + run: |- + cd example + & reindeer --third-party-dir third-party buckify + & buck2 init --git + & buck2 run "//project:test" + if: matrix.os == 'windows' diff --git a/example/.buckconfig b/example/.buckconfig index 5299f045d..6c0632827 100644 --- a/example/.buckconfig +++ b/example/.buckconfig @@ -1,4 +1,19 @@ +[repositories] +root = . +prelude = prelude +toolchains = toolchains +none = none + +[repository_aliases] +config = prelude +fbcode = none +fbsource = none +buck = none + +[parser] +target_platform_detector_spec = target:root//...->prelude//platforms:default + [rust] -default_edition = 2018 +default_edition = 2021 remap_src_paths = yes rustc_check_flags = --cap-lints=warn diff --git a/example/third-party/fixups/blake3/fixups.toml b/example/third-party/fixups/blake3/fixups.toml index b9d4180ec..8d888e08d 100644 --- a/example/third-party/fixups/blake3/fixups.toml +++ b/example/third-party/fixups/blake3/fixups.toml @@ -1,21 +1,7 @@ -buildscript = [] +[[buildscript]] -[[platform_fixup.'cfg(target_arch = "x86_64")'.buildscript]] -[platform_fixup.'cfg(target_arch = "x86_64")'.buildscript.cxx_library] +[buildscript.cxx_library] name = "blake3_avx512" srcs = ["c/blake3_avx512.c"] compiler_flags = ["-mavx512f", "-mavx512vl"] headers = ["c/*.h"] - -[[platform_fixup.'cfg(target_arch = "arm")'.buildscript]] -[platform_fixup.'cfg(target_arch = "arm")'.buildscript.cxx_library] -name = "blake3_neon-armv7" -srcs = ["c/blake3_neon.c"] -compiler_flags = ["-mfpu=neon-vfpv4", "-mfloat-abi=hard"] -headers = ["c/*.h"] - -[[platform_fixup.'cfg(target_arch = "aarch64")'.buildscript]] -[platform_fixup.'cfg(target_arch = "aarch64")'.buildscript.cxx_library] -name = "blake3_neon-aarch64" -srcs = ["c/blake3_neon.c"] -headers = ["c/*.h"] diff --git a/example/third-party/macros/rust_third_party.bzl b/example/third-party/macros/rust_third_party.bzl index 21df9ae50..ca1583be1 100644 --- a/example/third-party/macros/rust_third_party.bzl +++ b/example/third-party/macros/rust_third_party.bzl @@ -1,76 +1,7 @@ # @nolint -load(":iterable.bzl", "iterable") -load(":new_sets.bzl", "sets") -load(":type_defs.bzl", "is_dict") - -# Get current target platform - hard-coded for example, matches one of the platforms -# defined in reindeer.toml. -def _get_plat(): - return "linux-x86_64" - -def extend(orig, new): - if orig == None: - ret = new - elif new == None: - ret = orig - elif is_dict(orig): - ret = orig.copy() - ret.update(new) - else: # list - ret = orig + new - return ret - -# Add platform-specific args to args for a given platform. This assumes there's some static configuration -# for target platform (_get_plat) which isn't very flexible. A better approach would be to construct -# srcs/deps/etc with `select` to conditionally configure each target, but that's out of scope for this. -def platform_attrs(platformname, platformattrs, attrs): - for attr in sets.to_list(sets.make(iterable.concat(attrs.keys(), platformattrs.get(platformname, {}).keys()))): - new = extend(attrs.get(attr), platformattrs.get(platformname, {}).get(attr)) - attrs[attr] = new - return attrs - -def third_party_rust_library(name, platform = {}, dlopen_enable = False, python_ext = None, **kwargs): - # This works around a bug in Buck, which complains if srcs is missing - but that can happen if all - # the sources are mapped_srcs - if "srcs" not in kwargs: - kwargs["srcs"] = [] - - # Rust crates which are python extensions need special handling to make sure they get linked - # properly. This is not enough on its own - it still assumes there's a dependency on the python - # library. - if dlopen_enable or python_ext: - # This is all pretty ELF/Linux-specific - linker_flags = ["-shared"] - if python_ext: - linker_flags.append("-uPyInit_{}".format(python_ext)) - kwargs["preferred_linkage"] = "static" - cxx_binary(name = name + "-so", link_style = "static_pic", linker_flags = linker_flags, deps = [":" + name]) - - kwargs = platform_attrs(_get_plat(), platform, kwargs) - - rustc_flags = kwargs.get("rustc_flags", []) - kwargs["rustc_flags"] = ["--cap-lints=allow"] + rustc_flags - - rust_library(name, **kwargs) - -# `platform` is a map from a platform (defined in reindeer.toml) to the attributes -# specific to that platform. -def third_party_rust_binary(name, platform = {}, **kwargs): - # This works around a bug in Buck, which complains if srcs is missing - but that can happen if all - # the sources are mapped_srcs - if "srcs" not in kwargs: - kwargs["srcs"] = [] - - kwargs = platform_attrs(_get_plat(), platform, kwargs) - - rustc_flags = kwargs.get("rustc_flags", []) - kwargs["rustc_flags"] = ["--cap-lints=allow"] + rustc_flags - - rust_binary(name, **kwargs) - def third_party_rust_cxx_library(name, **kwargs): - cxx_library(name, **kwargs) + native.cxx_library(name = name, **kwargs) def third_party_rust_prebuilt_cxx_library(name, **kwargs): - prebuilt_cxx_library(name, **kwargs) + native.prebuilt_cxx_library(name = name, **kwargs) diff --git a/example/third-party/reindeer.toml b/example/third-party/reindeer.toml index 7838b8eb0..5c6b63268 100644 --- a/example/third-party/reindeer.toml +++ b/example/third-party/reindeer.toml @@ -157,17 +157,25 @@ target_vendor = ["pc"] # Name of the generated file file_name = "BUCK" # default -# Rules used for various kinds of targets. These rules don't directly correspond -# with BUCK rules - they have extra attributes such as per-platform settings. -# The intent is that you provide a set of macro definitions which resolve them -# to appropriate underlying rules suitable for your environment. (This may also -# work for Buck-like build systems such as Bazel.) -rust_library = "third_party_rust_library" # A plain Rust library -rust_binary = "third_party_rust_binary" # A Rust executable +# Rules used for various kinds of targets. These rules don't directly +# correspond with BUCK rules - they have extra attributes such as +# per-platform settings. The intent is that you provide a set of macro +# definitions which resolve them to appropriate underlying rules +# suitable for your environment. (This may also work for Buck-like +# build systems such as Bazel.) +rust_library = "cargo.rust_library" # A plain Rust library +rust_binary = "cargo.rust_binary" # A Rust executable cxx_library = "third_party_rust_cxx_library" # A C++ library (mostly for Rust -> C dependencies) prebuilt_cxx_library = "third_party_rust_prebuilt_cxx_library" # A prebuilt library (mostly for Rust -> C dependencies) buildscript_genrule = "buildscript_run" # Rule for running a build script to produce rustc args and generated sources +# Load the macros to which the rules above will resolve. +buckfile_imports = """ +load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run") +load("@prelude//rust:cargo_package.bzl", "cargo") +load("//third-party/macros:rust_third_party.bzl", "third_party_rust_cxx_library", "third_party_rust_prebuilt_cxx_library") +""" + # Banner comment for the generated BUCK File. generated_file_header = """ ## @@ -177,15 +185,3 @@ generated_file_header = """ ## See README.md for directions on how to update this. ## """ - -# Load the macros to which the rules above will resolve. -buckfile_imports = """ -load( - "//third-party/macros:rust_third_party.bzl", - "third_party_rust_library", # names match above - "third_party_rust_binary", - "third_party_rust_cxx_library", - "third_party_rust_prebuilt_cxx_library", -) -load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run") -""" diff --git a/example/toolchains/.buckconfig b/example/toolchains/.buckconfig new file mode 100644 index 000000000..e69de29bb diff --git a/example/toolchains/BUCK b/example/toolchains/BUCK new file mode 100644 index 000000000..c4031ed47 --- /dev/null +++ b/example/toolchains/BUCK @@ -0,0 +1,2 @@ +load("@prelude//toolchains:demo.bzl", "system_demo_toolchains") +system_demo_toolchains()