mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 14:24:43 +00:00
Merge pull request #13717 from GethDW/option-fix
std.build.Builder: fix for Allocator changes
This commit is contained in:
commit
a943422672
5 changed files with 49 additions and 1 deletions
|
|
@ -532,7 +532,7 @@ pub const Builder = struct {
|
||||||
options.appendAssumeCapacity(field.name);
|
options.appendAssumeCapacity(field.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
break :blk options.toOwnedSlice();
|
break :blk options.toOwnedSlice() catch unreachable;
|
||||||
} else null;
|
} else null;
|
||||||
const available_option = AvailableOption{
|
const available_option = AvailableOption{
|
||||||
.name = name,
|
.name = name,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,17 @@ const tests = @import("tests.zig");
|
||||||
pub fn addCases(cases: *tests.StandaloneContext) void {
|
pub fn addCases(cases: *tests.StandaloneContext) void {
|
||||||
cases.add("test/standalone/hello_world/hello.zig");
|
cases.add("test/standalone/hello_world/hello.zig");
|
||||||
cases.addC("test/standalone/hello_world/hello_libc.zig");
|
cases.addC("test/standalone/hello_world/hello_libc.zig");
|
||||||
|
|
||||||
|
cases.addBuildFile("test/standalone/options/build.zig", .{
|
||||||
|
.extra_argv = &.{
|
||||||
|
"-Dbool_true",
|
||||||
|
"-Dbool_false=false",
|
||||||
|
"-Dint=1234",
|
||||||
|
"-De=two",
|
||||||
|
"-Dstring=hello",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
cases.add("test/standalone/cat/main.zig");
|
cases.add("test/standalone/cat/main.zig");
|
||||||
if (builtin.zig_backend == .stage1) { // https://github.com/ziglang/zig/issues/6025
|
if (builtin.zig_backend == .stage1) { // https://github.com/ziglang/zig/issues/6025
|
||||||
cases.add("test/standalone/issue_9693/main.zig");
|
cases.add("test/standalone/issue_9693/main.zig");
|
||||||
|
|
|
||||||
22
test/standalone/options/build.zig
Normal file
22
test/standalone/options/build.zig
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.build.Builder) void {
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
|
const main = b.addTest("src/main.zig");
|
||||||
|
main.setTarget(target);
|
||||||
|
main.setBuildMode(mode);
|
||||||
|
|
||||||
|
const options = b.addOptions();
|
||||||
|
main.addOptions("build_options", options);
|
||||||
|
options.addOption(bool, "bool_true", b.option(bool, "bool_true", "t").?);
|
||||||
|
options.addOption(bool, "bool_false", b.option(bool, "bool_false", "f").?);
|
||||||
|
options.addOption(u32, "int", b.option(u32, "int", "i").?);
|
||||||
|
const E = enum { one, two, three };
|
||||||
|
options.addOption(E, "e", b.option(E, "e", "e").?);
|
||||||
|
options.addOption([]const u8, "string", b.option([]const u8, "string", "s").?);
|
||||||
|
|
||||||
|
const test_step = b.step("test", "Run unit tests");
|
||||||
|
test_step.dependOn(&main.step);
|
||||||
|
}
|
||||||
12
test/standalone/options/src/main.zig
Normal file
12
test/standalone/options/src/main.zig
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
|
const build_options = @import("build_options");
|
||||||
|
|
||||||
|
test "build options" {
|
||||||
|
comptime assert(build_options.bool_true);
|
||||||
|
comptime assert(!build_options.bool_false);
|
||||||
|
comptime assert(build_options.int == 1234);
|
||||||
|
comptime assert(build_options.e == .two);
|
||||||
|
comptime assert(std.mem.eql(u8, build_options.string, "hello"));
|
||||||
|
}
|
||||||
|
|
@ -1043,6 +1043,7 @@ pub const StandaloneContext = struct {
|
||||||
requires_stage2: bool = false,
|
requires_stage2: bool = false,
|
||||||
use_emulation: bool = false,
|
use_emulation: bool = false,
|
||||||
requires_symlinks: bool = false,
|
requires_symlinks: bool = false,
|
||||||
|
extra_argv: []const []const u8 = &.{},
|
||||||
}) void {
|
}) void {
|
||||||
const b = self.b;
|
const b = self.b;
|
||||||
|
|
||||||
|
|
@ -1063,6 +1064,8 @@ pub const StandaloneContext = struct {
|
||||||
zig_args.append("--build-file") catch unreachable;
|
zig_args.append("--build-file") catch unreachable;
|
||||||
zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
|
zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
|
||||||
|
|
||||||
|
zig_args.appendSlice(features.extra_argv) catch unreachable;
|
||||||
|
|
||||||
zig_args.append("test") catch unreachable;
|
zig_args.append("test") catch unreachable;
|
||||||
|
|
||||||
if (b.verbose) {
|
if (b.verbose) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue