Skip to content

Commit

Permalink
Merge pull request #92 from aherrmann/progress-message
Browse files Browse the repository at this point in the history
fix: root source file in progress message
  • Loading branch information
aherrmann authored Jun 24, 2023
2 parents 8692fc8 + bae2e71 commit d4054f1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion zig/private/zig_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _zig_binary_impl(ctx):

ctx.actions.run(
outputs = outputs,
inputs = depset(direct = direct_inputs, transitive = transitive_inputs),
inputs = depset(direct = direct_inputs, transitive = transitive_inputs, order = "preorder"),
executable = zigtoolchaininfo.zig_exe_path,
tools = zigtoolchaininfo.zig_files,
arguments = ["build-exe", args],
Expand Down
2 changes: 1 addition & 1 deletion zig/private/zig_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _zig_library_impl(ctx):

ctx.actions.run(
outputs = outputs,
inputs = depset(direct = direct_inputs, transitive = transitive_inputs),
inputs = depset(direct = direct_inputs, transitive = transitive_inputs, order = "preorder"),
executable = zigtoolchaininfo.zig_exe_path,
tools = zigtoolchaininfo.zig_files,
arguments = ["build-lib", args],
Expand Down
2 changes: 1 addition & 1 deletion zig/private/zig_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _zig_test_impl(ctx):

ctx.actions.run(
outputs = outputs,
inputs = depset(direct = direct_inputs, transitive = transitive_inputs),
inputs = depset(direct = direct_inputs, transitive = transitive_inputs, order = "preorder"),
executable = zigtoolchaininfo.zig_exe_path,
tools = zigtoolchaininfo.zig_files,
arguments = ["test", "--test-no-exec", args],
Expand Down
19 changes: 19 additions & 0 deletions zig/tests/package-binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@rules_zig//zig:defs.bzl", "zig_binary", "zig_package")

exports_files(
["main.zig"],
visibility = ["//zig/tests:__pkg__"],
)

zig_package(
name = "data",
main = "data.zig",
visibility = ["//zig/tests:__pkg__"],
)

zig_binary(
name = "binary",
main = "main.zig",
visibility = ["//zig/tests:__pkg__"],
deps = [":data"],
)
1 change: 1 addition & 0 deletions zig/tests/package-binary/data.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const hello_world = "Hello world!\n";
8 changes: 8 additions & 0 deletions zig/tests/package-binary/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const std = @import("std");
const data = @import("data");

pub fn main() void {
std.io.getStdOut().writeAll(
data.hello_world,
) catch unreachable;
}
41 changes: 41 additions & 0 deletions zig/tests/rules_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,46 @@ def _test_multiple_sources_binary(name):
)
return [":" + name]

def _package_binary_test_impl(ctx):
env = analysistest.begin(ctx)
target = analysistest.target_under_test(env)
default = target[DefaultInfo]

executable = default.files_to_run.executable
main = ctx.file.main

build = [
action
for action in analysistest.target_actions(env)
if action.mnemonic == "ZigBuildExe"
]
asserts.equals(env, 1, len(build), "zig_binary should generate one ZigBuildExe action.")
build = build[0]

# The position in the action input and output matters for the progress_message.
asserts.equals(env, main, build.inputs.to_list()[0], "the main source should be the first input.")
asserts.equals(env, executable, build.outputs.to_list()[0], "the binary should be the first output.")

return analysistest.end(env)

_package_binary_test = analysistest.make(
_package_binary_test_impl,
attrs = {
"main": attr.label(
allow_single_file = True,
mandatory = True,
),
},
)

def _test_package_binary(name):
_package_binary_test(
name = name,
target_under_test = "//zig/tests/package-binary:binary",
main = "//zig/tests/package-binary:main.zig",
)
return [":" + name]

def _c_sources_binary_test_impl(ctx):
env = analysistest.begin(ctx)

Expand Down Expand Up @@ -152,6 +192,7 @@ def rules_test_suite(name):
tests = []
tests += _test_simple_binary(name = "simple_binary_test")
tests += _test_multiple_sources_binary(name = "multiple_sources_binary_test")
tests += _test_package_binary(name = "package_binary_test")
tests += _test_c_sources_binary(name = "c_sources_binary_test")
native.test_suite(
name = name,
Expand Down

0 comments on commit d4054f1

Please sign in to comment.