-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.Build: add new functions to create artifacts/Step.Compile from existing module #20388
std.Build: add new functions to create artifacts/Step.Compile from existing module #20388
Conversation
I think that's the right move. Modeling modules as build steps would be convenient if it worked, but it's not really logically coherent, and if it causes issues (which, as you say, it does), that's our fault for misusing the abstraction! |
fe3d357
to
870dcec
Compare
Uses functions from ziglang/zig#20388 . Also fix error with no longer existing `std.rand` namespace. Signed-off-by: Eric Joldasov <[email protected]>
Uses functions from ziglang/zig#20388 . Also fix error with no longer existing `std.rand` namespace. Signed-off-by: Eric Joldasov <[email protected]>
Nice, I needed something like this the other day for TigerBeetle --- we have a vsr module, which we'd love to use as a dependency for other modules, but which also includes a bunch of internal tests. So, ideally, we'd be able to pass the same |
882431a
to
3f052df
Compare
This would be a convenient addition |
e9fee04
to
bf6d26f
Compare
bdbc671
to
bc74600
Compare
65e8d80
to
ba59cec
Compare
9bcdd13
to
be48c95
Compare
0c9c6ce
to
1c5cae4
Compare
eb64e26
to
afc77f0
Compare
@BratishkaErik, thanks for doing the finishing touches here. @andrewrk, are you happy for me to merge this? I've thoroughly reviewed the work locally (refactoring and reworking some parts) and applied the changes we discussed, so I'm happy with it, but figured I should check with you. |
I'm probably going to say "yes" but could you make it easier on me by typing up the corresponding release notes for this PR? That will make it very easy to evaluate, plus we need those if it is merged. (also make sure the "breaking" label is correctly applied, or not) |
Sure thing -- here are the release notes. They're pretty similar to the ones I wrote up above, just modified for the API we ended up implementing. Release NotesZig 0.14.0 modifies the build system APIs for creating Users of the legacy APIs can upgrade with minimal effort by just moving the module-specific parts of their pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "hello",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
}
const std = @import("std"); --> pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "hello",
.root_module = b.createModule(.{ // this line was added
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}), // this line was added
});
b.installArtifact(exe);
}
const std = @import("std"); And, to demostrate the benefits of the new API, here is an example build script which elegantly constructs a complex build graph of multiple modules: pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// First, we create our 3 modules.
const foo = b.createModule(.{
.root_source_file = b.path("src/foo.zig"),
.target = target,
.optimize = optimize,
});
const bar = b.createModule(.{
.root_source_file = b.path("src/bar.zig"),
.target = target,
.optimize = optimize,
});
const qux = b.createModule(.{
.root_source_file = b.path("src/qux.zig"),
.target = target,
.optimize = optimize,
});
// Next, we set up all of their dependencies.
foo.addImport("bar", bar);
foo.addImport("qux", qux);
bar.addImport("qux", qux);
qux.addImport("bar", bar); // mutual recursion!
// Finally, we will create all of our `Compile` steps.
// `foo` will be the root of an executable, but all 3 modules also have unit tests we want to run.
const foo_exe = b.addExecutable(.{
.name = "foo",
.root_module = foo,
});
b.installArtifact(foo_exe);
const foo_test = b.addTest(.{
.name = "foo",
.root_module = foo,
});
const bar_test = b.addTest(.{
.name = "bar",
.root_module = bar,
});
const qux_test = b.addTest(.{
.name = "qux",
.root_module = qux,
});
const test_step = b.step("test", "Run all unit tests");
test_step.dependOn(&b.addRunArtifact(foo_test).step);
test_step.dependOn(&b.addRunArtifact(bar_test).step);
test_step.dependOn(&b.addRunArtifact(qux_test).step);
}
const std = @import("std"); |
Oops, sorry for the redundant request. I hate that "show hidden items" UI on GitHub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK yeah I remember this now. Thanks for seeing it through!
I've applied "breaking" because:
|
Thanks! 🥳 |
b.host was deprecated in 0.13.0 and removed in ziglang/zig#20388
deprecated API removed in ziglang/zig#20388
Release notes neglect to mention |
|
It should definitely be mentioned when it is deleted so that people can search for the missing function in the release notes and find out what to do. That's the main purpose of the release notes. |
Continued where @mlugg left in #18752. I will not duplicate that description here, because this PR is just a revival.
Unfortunately, I could not figure out how to resolve recursive and mutual dependencies between modules with this model, so I leaved this change out.
Also, since modules are now exposed to the users that run
zig init
, I added some small comments that explain to user what is a module and how to use it.I wanted to add more comments that explain what is a package/artifact, how to use b.dependency() and etc., but this was going out of scope in this PR, I'm leaving it to the future. BTW I think
zig init
should be splitted again tozig init exe
andzig init lib
, it's easier to explain to users when you don't have this partial duplication.