Commit 2b2efa24d0
Changed files (4)
lib
std
test
lib/std/build/TranslateCStep.zig
@@ -47,7 +47,7 @@ pub fn setTarget(self: *TranslateCStep, target: CrossTarget) void {
/// Creates a step to build an executable from the translated source.
pub fn addExecutable(self: *TranslateCStep) *LibExeObjStep {
- return self.builder.addExecutableSource("translated_c", build.FileSource{ .generated = &self.output_file }, .static);
+ return self.builder.addExecutableSource("translated_c", build.FileSource{ .generated = &self.output_file });
}
pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
lib/std/build.zig
@@ -214,11 +214,11 @@ pub const Builder = struct {
}
pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
- return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src), .static);
+ return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src));
}
- pub fn addExecutableSource(builder: *Builder, name: []const u8, root_src: ?FileSource, linkage: LibExeObjStep.Linkage) *LibExeObjStep {
- return LibExeObjStep.createExecutable(builder, name, root_src, linkage);
+ pub fn addExecutableSource(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
+ return LibExeObjStep.createExecutable(builder, name, root_src);
}
pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
@@ -1363,7 +1363,7 @@ pub const LibExeObjStep = struct {
linker_script: ?FileSource = null,
version_script: ?[]const u8 = null,
out_filename: []const u8,
- linkage: Linkage,
+ linkage: ?Linkage = null,
version: ?Version,
build_mode: builtin.Mode,
kind: Kind,
@@ -1517,15 +1517,15 @@ pub const LibExeObjStep = struct {
}
pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
- return initExtraArgs(builder, name, root_src, .obj, .static, null);
+ return initExtraArgs(builder, name, root_src, .obj, null, null);
}
- pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, linkage: Linkage) *LibExeObjStep {
- return initExtraArgs(builder, name, root_src, .exe, linkage, null);
+ pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
+ return initExtraArgs(builder, name, root_src, .exe, null, null);
}
pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep {
- return initExtraArgs(builder, name, root_src, .@"test", .static, null);
+ return initExtraArgs(builder, name, root_src, .@"test", null, null);
}
fn initExtraArgs(
@@ -1533,7 +1533,7 @@ pub const LibExeObjStep = struct {
name_raw: []const u8,
root_src_raw: ?FileSource,
kind: Kind,
- linkage: Linkage,
+ linkage: ?Linkage,
ver: ?Version,
) *LibExeObjStep {
const name = builder.dupe(name_raw);
@@ -1613,15 +1613,15 @@ pub const LibExeObjStep = struct {
.obj => .Obj,
.exe, .@"test" => .Exe,
},
- .link_mode = switch (self.linkage) {
+ .link_mode = if (self.linkage) |some| @as(std.builtin.LinkMode, switch (some) {
.dynamic => .Dynamic,
.static => .Static,
- },
+ }) else null,
.version = self.version,
}) catch unreachable;
if (self.kind == .lib) {
- if (self.linkage == .static) {
+ if (self.linkage != null and self.linkage.? == .static) {
self.out_lib_filename = self.out_filename;
} else if (self.version) |version| {
if (target.isDarwin()) {
@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {
}
pub fn isDynamicLibrary(self: *LibExeObjStep) bool {
- return self.kind == .lib and self.linkage == .dynamic;
+ return self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic;
}
pub fn producesPdbFile(self: *LibExeObjStep) bool {
@@ -2298,7 +2298,7 @@ pub const LibExeObjStep = struct {
const full_path_lib = other.getOutputLibSource().getPath(builder);
try zig_args.append(full_path_lib);
- if (other.linkage == .dynamic and !self.target.isWindows()) {
+ if (other.linkage != null and other.linkage.? == .dynamic and !self.target.isWindows()) {
if (fs.path.dirname(full_path_lib)) |dirname| {
try zig_args.append("-rpath");
try zig_args.append(dirname);
@@ -2464,15 +2464,17 @@ pub const LibExeObjStep = struct {
zig_args.append("--name") catch unreachable;
zig_args.append(self.name) catch unreachable;
- if (self.kind == .lib and self.linkage == .dynamic) {
+ if (self.linkage) |some| switch (some) {
+ .dynamic => try zig_args.append("-dynamic"),
+ .static => try zig_args.append("-static"),
+ };
+ if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic) {
if (self.version) |version| {
zig_args.append("--version") catch unreachable;
zig_args.append(builder.fmt("{}", .{version})) catch unreachable;
}
}
- if (self.linkage == .dynamic) {
- try zig_args.append("-dynamic");
- }
+
if (self.bundle_compiler_rt) |x| {
if (x) {
try zig_args.append("-fcompiler-rt");
@@ -2801,7 +2803,7 @@ pub const LibExeObjStep = struct {
}
}
- if (self.kind == .lib and self.linkage == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) {
+ if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) {
try doAtomicSymLinks(builder.allocator, self.getOutputSource().getPath(builder), self.major_only_filename.?, self.name_only_filename.?);
}
}
test/src/compare_output.zig
@@ -126,7 +126,7 @@ pub const CompareOutputContext = struct {
}
const basename = case.sources.items[0].filename;
- const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?, .static);
+ const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?);
exe.setBuildMode(mode);
if (case.link_libc) {
exe.linkSystemLibrary("c");
@@ -147,7 +147,7 @@ pub const CompareOutputContext = struct {
}
const basename = case.sources.items[0].filename;
- const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?, .static);
+ const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?);
if (case.link_libc) {
exe.linkSystemLibrary("c");
}
test/tests.zig
@@ -656,7 +656,7 @@ pub const StackTracesContext = struct {
const b = self.b;
const src_basename = "source.zig";
const write_src = b.addWriteFile(src_basename, source);
- const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?, .static);
+ const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?);
exe.setBuildMode(mode);
const run_and_compare = RunAndCompareStep.create(