-
-
Save adamhjk/5cf04d3e0e7fadd12ea34d985c78d3ad to your computer and use it in GitHub Desktop.
Brutalist buck2 + cargo rule
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
load("//build-rules/cargo.bzl", "cargo_library") | |
cargo_library( | |
name = "dal", | |
package = "dal", | |
build_type = "debug", | |
srcs = glob(["lib/dal/**/*.rs", "lib/dal/build.rs"]), | |
out = "libdal" | |
) |
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
def cargo_library_impl(ctx: "context") -> ["provider"]: | |
script = ctx.actions.write("cargo-build.sh", """#!/bin/bash | |
set -euxo pipefail | |
cargo build -p $1 | |
mkdir -p $4 | |
cp target/$2/$3.* $4 | |
""", is_executable = True); | |
out = ctx.actions.declare_output(ctx.attrs.out, dir = True) | |
args = cmd_args([script, ctx.attrs.package, ctx.attrs.build_type, ctx.attrs.out, out.as_output()]) | |
args.hidden([ctx.attrs.srcs]) | |
args.hidden([ctx.attrs.deps]) | |
ctx.actions.run(args, category = "cargo", identifier = "build", local_only = True) | |
return [DefaultInfo(default_outputs = [out])] | |
cargo_library = rule(impl = cargo_library_impl, attrs = { | |
"package": attrs.string(doc = "Cargo package name"), | |
"srcs": attrs.list(attrs.source(), doc = """List of package.json files to track"""), | |
"deps": attrs.list(attrs.source(), default = [], doc="A buck2 dep"), | |
"build_type": attrs.string(), | |
"out": attrs.string(doc="the basename of the file(s) in target to track as output"), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment