-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
zig build: The breakings will continue until morale improves. #14498
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
063888a
std.build: implement passing options to dependency packages
andrewrk 71ff60f
std.build: eliminate setTarget and setBuildMode
andrewrk 73cf7b6
update build.zig API usage
andrewrk 36e2d99
combine std.build and std.build.Builder into std.Build
andrewrk 60c4bef
build.zig: remove dead list of unused source files
andrewrk 5129fae
std.Build: accept host Target in create()
andrewrk 9a29f4e
langref updates for new std.Build API
andrewrk 34b3145
update test case for new std.builtin.OptimizeMode API
andrewrk 7754468
fix init-exe, init-lib templates
andrewrk 16cdd12
rename std.Build.LibExeObjStep to std.Build.CompileStep
andrewrk 13a9616
std.Build: add deprecated declarations
andrewrk 90e48d4
std.Build: avoid use of catch unreachable
andrewrk 2f58926
move compiler's CType logic to std.Target
andrewrk 3c1fc3f
std.Build.ConfigHeaderStep: support more types
andrewrk 7d14bae
tests: fix missing target for C ABI tests
andrewrk 8d37c6f
std.Build.CompileStep: fix API usage in unit test
andrewrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,67 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.build.Builder) void { | ||
// Although this function looks imperative, note that its job is to | ||
// declaratively construct a build graph that will be executed by an external | ||
// runner. | ||
pub fn build(b: *std.Build) void { | ||
// Standard target options allows the person running `zig build` to choose | ||
// what target to build for. Here we do not override the defaults, which | ||
// means any target is allowed, and the default is native. Other options | ||
// for restricting supported target set are available. | ||
const target = b.standardTargetOptions(.{}); | ||
|
||
// Standard release options allow the person running `zig build` to select | ||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | ||
const mode = b.standardReleaseOptions(); | ||
// Standard optimization options allow the person running `zig build` to select | ||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not | ||
// set a preferred release mode, allowing the user to decide how to optimize. | ||
andrewrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const exe = b.addExecutable("$", "src/main.zig"); | ||
exe.setTarget(target); | ||
exe.setBuildMode(mode); | ||
const exe = b.addExecutable(.{ | ||
.name = "$", | ||
// In this case the main source file is merely a path, however, in more | ||
// complicated build scripts, this could be a generated file. | ||
.root_source_file = .{ .path = "src/main.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
// This declares intent for the executable to be installed into the | ||
// standard location when the user invokes the "install" step (the default | ||
// step when running `zig build`). | ||
exe.install(); | ||
|
||
// This *creates* a RunStep in the build graph, to be executed when another | ||
// step is evaluated that depends on it. The next line below will establish | ||
// such a dependency. | ||
const run_cmd = exe.run(); | ||
|
||
// By making the run step depend on the install step, it will be run from the | ||
// installation directory rather than directly from within the cache directory. | ||
// This is not necessary, however, if the application depends on other installed | ||
// files, this ensures they will be present and in the expected location. | ||
run_cmd.step.dependOn(b.getInstallStep()); | ||
|
||
// This allows the user to pass arguments to the application in the build | ||
// command itself, like this: `zig build run -- arg1 arg2 etc` | ||
if (b.args) |args| { | ||
run_cmd.addArgs(args); | ||
} | ||
|
||
// This creates a build step. It will be visible in the `zig build --help` menu, | ||
// and can be selected like this: `zig build run` | ||
// This will evaluate the `run` step rather than the default, which is "install". | ||
const run_step = b.step("run", "Run the app"); | ||
run_step.dependOn(&run_cmd.step); | ||
|
||
const exe_tests = b.addTest("src/main.zig"); | ||
exe_tests.setTarget(target); | ||
exe_tests.setBuildMode(mode); | ||
// Creates a step for unit testing. | ||
const exe_tests = b.addTest(.{ | ||
.root_source_file = .{ .path = "src/main.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
// Similar to creating the run step earlier, this exposes a `test` step to | ||
// the `zig build --help` menu, providing a way for the user to request | ||
// running the unit tests. | ||
const test_step = b.step("test", "Run unit tests"); | ||
test_step.dependOn(&exe_tests.step); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.build.Builder) void { | ||
// Standard release options allow the person running `zig build` to select | ||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | ||
const mode = b.standardReleaseOptions(); | ||
// Although this function looks imperative, note that its job is to | ||
// declaratively construct a build graph that will be executed by an external | ||
// runner. | ||
pub fn build(b: *std.Build) void { | ||
// Standard target options allows the person running `zig build` to choose | ||
// what target to build for. Here we do not override the defaults, which | ||
// means any target is allowed, and the default is native. Other options | ||
// for restricting supported target set are available. | ||
const target = b.standardTargetOptions(.{}); | ||
|
||
const lib = b.addStaticLibrary("$", "src/main.zig"); | ||
lib.setBuildMode(mode); | ||
// Standard optimization options allow the person running `zig build` to select | ||
andrewrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not | ||
// set a preferred release mode, allowing the user to decide how to optimize. | ||
andrewrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const lib = b.addStaticLibrary(.{ | ||
.name = "$", | ||
// In this case the main source file is merely a path, however, in more | ||
// complicated build scripts, this could be a generated file. | ||
.root_source_file = .{ .path = "src/main.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
// This declares intent for the library to be installed into the standard | ||
// location when the user invokes the "install" step (the default step when | ||
// running `zig build`). | ||
lib.install(); | ||
|
||
const main_tests = b.addTest("src/main.zig"); | ||
main_tests.setBuildMode(mode); | ||
// Creates a step for unit testing. | ||
const main_tests = b.addTest(.{ | ||
.root_source_file = .{ .path = "src/main.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
// This creates a build step. It will be visible in the `zig build --help` menu, | ||
// and can be selected like this: `zig build test` | ||
// This will evaluate the `test` step rather than the default, which is "install". | ||
const test_step = b.step("test", "Run library tests"); | ||
test_step.dependOn(&main_tests.step); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.