Skip to content

Commit

Permalink
Add basic rustc example
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Jul 14, 2022
1 parent 68bd054 commit cc4288c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/rust/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[buildfile]
name=TARGETS

[repositories]
root = .
17 changes: 17 additions & 0 deletions examples/rust/rules.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def _rust_binary_impl(ctx):
file = ctx.attr.file
out = ctx.actions.declare_output("main")

cmd = cmd_args(["rustc", "--crate-type=bin", file, "-o", out.as_output()])

ctx.actions.run(cmd, category="compile")

return [DefaultInfo(default_outputs = [out]), RunInfo(args=cmd_args([out]))]


rust_binary = rule(
implementation = _rust_binary_impl,
attrs = {
"file": attr.source()
},
)
6 changes: 6 additions & 0 deletions examples/rust/rustc/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("//rules.bzl", "rust_binary")

rust_binary(
name = "main",
file = "./main.rs"
)
3 changes: 3 additions & 0 deletions examples/rust/rustc/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("hello from rustc");
}

0 comments on commit cc4288c

Please sign in to comment.