Skip to content
Open
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
26 changes: 15 additions & 11 deletions build_defs/rust.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def rust_library(name:str, root:str, crate_name:str="", modules:list=None, deps:
)


def rust_binary(name:str, main:str, deps:list=None, edition:str='2021', features:list=None, build_root:str=None, build_deps:list|dict=None, build_compile_env:dict=None, build_run_env:dict=None, target_dir:str="target/debug/deps", visibility:list=None, _os:str=None, _arch:str=None):
def rust_binary(name:str, main:str, deps:list=[], edition:str='2021', features:list=None, build_root:str=None, build_deps:list|dict=None, build_compile_env:dict=None, build_run_env:dict=None, target_dir:str="target/debug/deps", visibility:list=None, _os:str=None, _arch:str=None):
"""Defines a build rule for a Rust standalone binary.

Args:
Expand Down Expand Up @@ -218,15 +218,19 @@ def rust_binary(name:str, main:str, deps:list=None, edition:str='2021', features

# All this really does is ensure that rust_proto_libraries build before the pre_build function.
# TODO: is there a better way of doing this?
collect_deps = genrule(
name = f"_{name}#target_deps",
cmd = [
f"mkdir $OUTS",
f"mv $SRCS $OUTS",
],
srcs = deps,
outs = [target_dir],
)
if len(deps) > 0:
collect_deps = [genrule(
name = f"_{name}#target_deps",
cmd = [
f"mkdir $OUTS",
f"mv $SRCS $OUTS",
],
srcs = deps,
outs = [target_dir],
)]
else:
collect_deps = []

cmd, tools = _rustc_cmds(
crate_name=name,
edition=edition,
Expand All @@ -240,7 +244,7 @@ def rust_binary(name:str, main:str, deps:list=None, edition:str='2021', features
binary = True,
outs = [name],
cmd = cmd,
deps = deps + [collect_deps],
deps = deps + collect_deps,
visibility = visibility,
requires = ['rust'],
tools = tools,
Expand Down
8 changes: 8 additions & 0 deletions examples/hello_world/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subinclude("//build_defs:rust")

rust_binary(
name = "hello_world",
main = "src/main.rs",
edition = "2021",
)

4 changes: 4 additions & 0 deletions examples/hello_world/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("Hello, world!");
}