Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github action that builds the example project #37

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
15 changes: 15 additions & 0 deletions example/.buckconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
[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
remap_src_paths = yes
Expand Down
Empty file added example/.buckroot
Empty file.
18 changes: 2 additions & 16 deletions example/third-party/fixups/blake3/fixups.toml
Original file line number Diff line number Diff line change
@@ -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"]
73 changes: 2 additions & 71 deletions example/third-party/macros/rust_third_party.bzl
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 15 additions & 19 deletions example/third-party/reindeer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
##
Expand All @@ -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")
"""
Empty file added example/toolchains/.buckconfig
Empty file.
2 changes: 2 additions & 0 deletions example/toolchains/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
load("@prelude//toolchains:demo.bzl", "system_demo_toolchains")
system_demo_toolchains()
Loading