From 2fdc8a5510550ec3187db6c167713751bed17a6c Mon Sep 17 00:00:00 2001 From: Andrzej J Skalski Date: Sun, 28 Dec 2025 10:37:40 -0300 Subject: [PATCH 1/2] fix to fix --- build_defs/rust.build_defs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/build_defs/rust.build_defs b/build_defs/rust.build_defs index 77c31e2..94d2072 100644 --- a/build_defs/rust.build_defs +++ b/build_defs/rust.build_defs @@ -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 deps: + 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, @@ -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, From d25944d27055297435b458d5c8057f14966e89d2 Mon Sep 17 00:00:00 2001 From: Andrzej J Skalski Date: Mon, 29 Dec 2025 13:45:30 -0300 Subject: [PATCH 2/2] fixed empty deps and added an example --- build_defs/rust.build_defs | 4 ++-- examples/hello_world/BUILD | 8 ++++++++ examples/hello_world/src/main.rs | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 examples/hello_world/BUILD create mode 100644 examples/hello_world/src/main.rs diff --git a/build_defs/rust.build_defs b/build_defs/rust.build_defs index 94d2072..b5aaf2a 100644 --- a/build_defs/rust.build_defs +++ b/build_defs/rust.build_defs @@ -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: @@ -218,7 +218,7 @@ 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? - if deps: + if len(deps) > 0: collect_deps = [genrule( name = f"_{name}#target_deps", cmd = [ diff --git a/examples/hello_world/BUILD b/examples/hello_world/BUILD new file mode 100644 index 0000000..f29d699 --- /dev/null +++ b/examples/hello_world/BUILD @@ -0,0 +1,8 @@ +subinclude("//build_defs:rust") + +rust_binary( + name = "hello_world", + main = "src/main.rs", + edition = "2021", +) + diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs new file mode 100644 index 0000000..24e4cf8 --- /dev/null +++ b/examples/hello_world/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Hello, world!"); +} +