authorgravatar for xq@random-projects.netFelix "xq" Queißner <xq@random-projects.net> 2021-02-22 22:11:30+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-11 10:33:26+03:00
log8501bb04ada0a29b66ba2d87ec956a4cdff46cee
tree11f16f6e53d51a7f54182746b85296089a228372
parent4ed567d12e2670596ebc4bf42c710b4e3210e77e

Adds a lot of missing dupes, some more snakes.


2 files changed, 83 insertions(+), 76 deletions(-)

lib/std/build.zig+81-74
...@@ -206,7 +206,7 @@ pub const Builder = struct {...@@ -206,7 +206,7 @@ pub const Builder = struct {
206206
207 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {207 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {
208 return if (path) |p|208 return if (path) |p|
209 FileSource.relative(p)209 FileSource{ .path = p }
210 else210 else
211 null;211 null;
212 }212 }
...@@ -246,7 +246,7 @@ pub const Builder = struct {...@@ -246,7 +246,7 @@ pub const Builder = struct {
246 }246 }
247247
248 pub fn addTestSource(self: *Builder, root_src: FileSource) *LibExeObjStep {248 pub fn addTestSource(self: *Builder, root_src: FileSource) *LibExeObjStep {
249 return LibExeObjStep.createTest(self, "test", root_src);249 return LibExeObjStep.createTest(self, "test", root_src.dupe(self));
250 }250 }
251251
252 pub fn addAssemble(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {252 pub fn addAssemble(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
...@@ -255,7 +255,7 @@ pub const Builder = struct {...@@ -255,7 +255,7 @@ pub const Builder = struct {
255255
256 pub fn addAssembleSource(self: *Builder, name: []const u8, src: FileSource) *LibExeObjStep {256 pub fn addAssembleSource(self: *Builder, name: []const u8, src: FileSource) *LibExeObjStep {
257 const obj_step = LibExeObjStep.createObject(self, name, null);257 const obj_step = LibExeObjStep.createObject(self, name, null);
258 obj_step.addAssemblyFileSource(src);258 obj_step.addAssemblyFileSource(src.dupe(self));
259 return obj_step;259 return obj_step;
260 }260 }
261261
...@@ -341,7 +341,7 @@ pub const Builder = struct {...@@ -341,7 +341,7 @@ pub const Builder = struct {
341 }341 }
342342
343 pub fn addTranslateC(self: *Builder, source: FileSource) *TranslateCStep {343 pub fn addTranslateC(self: *Builder, source: FileSource) *TranslateCStep {
344 return TranslateCStep.create(self, source);344 return TranslateCStep.create(self, source.dupe(self));
345 }345 }
346346
347 pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind {347 pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind {
...@@ -898,18 +898,18 @@ pub const Builder = struct {...@@ -898,18 +898,18 @@ pub const Builder = struct {
898 }898 }
899899
900 ///`dest_rel_path` is relative to install prefix path900 ///`dest_rel_path` is relative to install prefix path
901 pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {901 pub fn addInstallFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
902 return self.addInstallFileWithDir(FileSource.relative(src_path), .Prefix, dest_rel_path);902 return self.addInstallFileWithDir(source.dupe(self), .Prefix, dest_rel_path);
903 }903 }
904904
905 ///`dest_rel_path` is relative to bin path905 ///`dest_rel_path` is relative to bin path
906 pub fn addInstallBinFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {906 pub fn addInstallBinFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
907 return self.addInstallFileWithDir(FileSource.relative(src_path), .Bin, dest_rel_path);907 return self.addInstallFileWithDir(source.dupe(self), .Bin, dest_rel_path);
908 }908 }
909909
910 ///`dest_rel_path` is relative to lib path910 ///`dest_rel_path` is relative to lib path
911 pub fn addInstallLibFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {911 pub fn addInstallLibFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
912 return self.addInstallFileWithDir(FileSource.relative(src_path), .Lib, dest_rel_path);912 return self.addInstallFileWithDir(source.dupe(self), .Lib, dest_rel_path);
913 }913 }
914914
915 pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {915 pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
...@@ -926,7 +926,7 @@ pub const Builder = struct {...@@ -926,7 +926,7 @@ pub const Builder = struct {
926 panic("dest_rel_path must be non-empty", .{});926 panic("dest_rel_path must be non-empty", .{});
927 }927 }
928 const install_step = self.allocator.create(InstallFileStep) catch unreachable;928 const install_step = self.allocator.create(InstallFileStep) catch unreachable;
929 install_step.* = InstallFileStep.init(self, source, install_dir, dest_rel_path);929 install_step.* = InstallFileStep.init(self, source.dupe(self), install_dir, dest_rel_path);
930 return install_step;930 return install_step;
931 }931 }
932932
...@@ -1236,12 +1236,20 @@ pub const GeneratedFile = struct {...@@ -1236,12 +1236,20 @@ pub const GeneratedFile = struct {
1236 }1236 }
1237};1237};
12381238
1239/// A file source is a reference to an existing or future file.
1240///
1239pub const FileSource = union(enum) {1241pub const FileSource = union(enum) {
1240 /// Relative to build root1242 /// A plain file path, relative to build root.
1241 path: []const u8,1243 path: []const u8,
1244
1245 /// A file that is generated by an interface. Those files usually are
1246 /// not available until built by a build step.
1242 generated: *const GeneratedFile,1247 generated: *const GeneratedFile,
12431248
1249 /// Returns a new file source that will have a relative path to the build root guaranteed.
1250 /// This should be preferred over setting `.path` directly as it documents that the files are in the project directory.
1244 pub fn relative(path: []const u8) FileSource {1251 pub fn relative(path: []const u8) FileSource {
1252 std.debug.assert(!std.fs.path.isAbsolute(path));
1245 return FileSource{ .path = path };1253 return FileSource{ .path = path };
1246 }1254 }
12471255
...@@ -1254,6 +1262,7 @@ pub const FileSource = union(enum) {...@@ -1254,6 +1262,7 @@ pub const FileSource = union(enum) {
1254 };1262 };
1255 }1263 }
12561264
1265 /// Adds dependencies this file source implies to the given step.
1257 pub fn addStepDependencies(self: FileSource, step: *Step) void {1266 pub fn addStepDependencies(self: FileSource, step: *Step) void {
1258 switch (self) {1267 switch (self) {
1259 .path => {},1268 .path => {},
...@@ -1271,6 +1280,7 @@ pub const FileSource = union(enum) {...@@ -1271,6 +1280,7 @@ pub const FileSource = union(enum) {
1271 return path;1280 return path;
1272 }1281 }
12731282
1283 /// Duplicates the file source for a given builder.
1274 pub fn dupe(self: FileSource, b: *Builder) FileSource {1284 pub fn dupe(self: FileSource, b: *Builder) FileSource {
1275 return switch (self) {1285 return switch (self) {
1276 .path => |p| .{ .path = b.dupePath(p) },1286 .path => |p| .{ .path = b.dupePath(p) },
...@@ -1284,10 +1294,9 @@ const BuildOptionArtifactArg = struct {...@@ -1284,10 +1294,9 @@ const BuildOptionArtifactArg = struct {
1284 artifact: *LibExeObjStep,1294 artifact: *LibExeObjStep,
1285};1295};
12861296
1287const BuildOptionWriteFileArg = struct {1297const BuildOptionFileSourceArg = struct {
1288 name: []const u8,1298 name: []const u8,
1289 write_file: *WriteFileStep,1299 source: FileSource,
1290 basename: []const u8,
1291};1300};
12921301
1293pub const LibExeObjStep = struct {1302pub const LibExeObjStep = struct {
...@@ -1295,7 +1304,7 @@ pub const LibExeObjStep = struct {...@@ -1295,7 +1304,7 @@ pub const LibExeObjStep = struct {
1295 builder: *Builder,1304 builder: *Builder,
1296 name: []const u8,1305 name: []const u8,
1297 target: CrossTarget = CrossTarget{},1306 target: CrossTarget = CrossTarget{},
1298 linker_script: ?[]const u8 = null,1307 linker_script: ?FileSource = null,
1299 version_script: ?[]const u8 = null,1308 version_script: ?[]const u8 = null,
1300 out_filename: []const u8,1309 out_filename: []const u8,
1301 is_dynamic: bool,1310 is_dynamic: bool,
...@@ -1338,7 +1347,7 @@ pub const LibExeObjStep = struct {...@@ -1338,7 +1347,7 @@ pub const LibExeObjStep = struct {
1338 packages: ArrayList(Pkg),1347 packages: ArrayList(Pkg),
1339 build_options_contents: std.ArrayList(u8),1348 build_options_contents: std.ArrayList(u8),
1340 build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg),1349 build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg),
1341 build_options_write_file_args: std.ArrayList(BuildOptionWriteFileArg),1350 build_options_file_source_args: std.ArrayList(BuildOptionFileSourceArg),
13421351
1343 object_src: []const u8,1352 object_src: []const u8,
13441353
...@@ -1358,7 +1367,7 @@ pub const LibExeObjStep = struct {...@@ -1358,7 +1367,7 @@ pub const LibExeObjStep = struct {
1358 /// Base address for an executable image.1367 /// Base address for an executable image.
1359 image_base: ?u64 = null,1368 image_base: ?u64 = null,
13601369
1361 libc_file: ?[]const u8 = null,1370 libc_file: ?FileSource = null,
13621371
1363 valgrind_support: ?bool = null,1372 valgrind_support: ?bool = null,
13641373
...@@ -1407,18 +1416,18 @@ pub const LibExeObjStep = struct {...@@ -1407,18 +1416,18 @@ pub const LibExeObjStep = struct {
1407 want_lto: ?bool = null,1416 want_lto: ?bool = null,
14081417
1409 const LinkObject = union(enum) {1418 const LinkObject = union(enum) {
1410 StaticPath: []const u8,1419 static_path: FileSource,
1411 OtherStep: *LibExeObjStep,1420 other_step: *LibExeObjStep,
1412 SystemLib: []const u8,1421 system_lib: []const u8,
1413 AssemblyFile: FileSource,1422 assembly_file: FileSource,
1414 CSourceFile: *CSourceFile,1423 c_source_file: *CSourceFile,
1415 CSourceFiles: *CSourceFiles,1424 c_source_files: *CSourceFiles,
1416 };1425 };
14171426
1418 const IncludeDir = union(enum) {1427 const IncludeDir = union(enum) {
1419 RawPath: []const u8,1428 raw_path: []const u8,
1420 RawPathSystem: []const u8,1429 raw_path_system: []const u8,
1421 OtherStep: *LibExeObjStep,1430 other_step: *LibExeObjStep,
1422 };1431 };
14231432
1424 const Kind = enum {1433 const Kind = enum {
...@@ -1508,7 +1517,7 @@ pub const LibExeObjStep = struct {...@@ -1508,7 +1517,7 @@ pub const LibExeObjStep = struct {
1508 .object_src = undefined,1517 .object_src = undefined,
1509 .build_options_contents = std.ArrayList(u8).init(builder.allocator),1518 .build_options_contents = std.ArrayList(u8).init(builder.allocator),
1510 .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator),1519 .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator),
1511 .build_options_write_file_args = std.ArrayList(BuildOptionWriteFileArg).init(builder.allocator),1520 .build_options_file_source_args = std.ArrayList(BuildOptionFileSourceArg).init(builder.allocator),
1512 .c_std = Builder.CStd.C99,1521 .c_std = Builder.CStd.C99,
1513 .override_lib_dir = null,1522 .override_lib_dir = null,
1514 .main_pkg_path = null,1523 .main_pkg_path = null,
...@@ -1613,8 +1622,8 @@ pub const LibExeObjStep = struct {...@@ -1613,8 +1622,8 @@ pub const LibExeObjStep = struct {
1613 return run_step;1622 return run_step;
1614 }1623 }
16151624
1616 pub fn setLinkerScriptPath(self: *LibExeObjStep, path: []const u8) void {1625 pub fn setLinkerScriptPath(self: *LibExeObjStep, source: FileSource) void {
1617 self.linker_script = self.builder.dupePath(path);1626 self.linker_script = source.dupe(self.builder);
1618 }1627 }
16191628
1620 pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {1629 pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {
...@@ -1633,7 +1642,7 @@ pub const LibExeObjStep = struct {...@@ -1633,7 +1642,7 @@ pub const LibExeObjStep = struct {
1633 }1642 }
1634 for (self.link_objects.items) |link_object| {1643 for (self.link_objects.items) |link_object| {
1635 switch (link_object) {1644 switch (link_object) {
1636 LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,1645 .system_lib => |n| if (mem.eql(u8, n, name)) return true,
1637 else => continue,1646 else => continue,
1638 }1647 }
1639 }1648 }
...@@ -1658,7 +1667,7 @@ pub const LibExeObjStep = struct {...@@ -1658,7 +1667,7 @@ pub const LibExeObjStep = struct {
1658 pub fn linkLibC(self: *LibExeObjStep) void {1667 pub fn linkLibC(self: *LibExeObjStep) void {
1659 if (!self.is_linking_libc) {1668 if (!self.is_linking_libc) {
1660 self.is_linking_libc = true;1669 self.is_linking_libc = true;
1661 self.link_objects.append(LinkObject{ .SystemLib = "c" }) catch unreachable;1670 self.link_objects.append(LinkObject{ .system_lib = "c" }) catch unreachable;
1662 }1671 }
1663 }1672 }
16641673
...@@ -1677,7 +1686,7 @@ pub const LibExeObjStep = struct {...@@ -1677,7 +1686,7 @@ pub const LibExeObjStep = struct {
1677 /// This one has no integration with anything, it just puts -lname on the command line.1686 /// This one has no integration with anything, it just puts -lname on the command line.
1678 /// Prefer to use `linkSystemLibrary` instead.1687 /// Prefer to use `linkSystemLibrary` instead.
1679 pub fn linkSystemLibraryName(self: *LibExeObjStep, name: []const u8) void {1688 pub fn linkSystemLibraryName(self: *LibExeObjStep, name: []const u8) void {
1680 self.link_objects.append(LinkObject{ .SystemLib = self.builder.dupe(name) }) catch unreachable;1689 self.link_objects.append(LinkObject{ .system_lib = self.builder.dupe(name) }) catch unreachable;
1681 }1690 }
16821691
1683 /// This links against a system library, exclusively using pkg-config to find the library.1692 /// This links against a system library, exclusively using pkg-config to find the library.
...@@ -1817,7 +1826,7 @@ pub const LibExeObjStep = struct {...@@ -1817,7 +1826,7 @@ pub const LibExeObjStep = struct {
1817 .files = files_copy,1826 .files = files_copy,
1818 .flags = flags_copy,1827 .flags = flags_copy,
1819 };1828 };
1820 self.link_objects.append(LinkObject{ .CSourceFiles = c_source_files }) catch unreachable;1829 self.link_objects.append(LinkObject{ .c_source_files = c_source_files }) catch unreachable;
1821 }1830 }
18221831
1823 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {1832 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {
...@@ -1830,7 +1839,8 @@ pub const LibExeObjStep = struct {...@@ -1830,7 +1839,8 @@ pub const LibExeObjStep = struct {
1830 pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void {1839 pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void {
1831 const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;1840 const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;
1832 c_source_file.* = source.dupe(self.builder);1841 c_source_file.* = source.dupe(self.builder);
1833 self.link_objects.append(LinkObject{ .CSourceFile = c_source_file }) catch unreachable;1842 self.link_objects.append(LinkObject{ .c_source_file = c_source_file }) catch unreachable;
1843 source.source.addStepDependencies(&self.step);
1834 }1844 }
18351845
1836 pub fn setVerboseLink(self: *LibExeObjStep, value: bool) void {1846 pub fn setVerboseLink(self: *LibExeObjStep, value: bool) void {
...@@ -1853,8 +1863,8 @@ pub const LibExeObjStep = struct {...@@ -1853,8 +1863,8 @@ pub const LibExeObjStep = struct {
1853 self.main_pkg_path = self.builder.dupePath(dir_path);1863 self.main_pkg_path = self.builder.dupePath(dir_path);
1854 }1864 }
18551865
1856 pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void {1866 pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?FileSource) void {
1857 self.libc_file = if (libc_file) |f| self.builder.dupe(f) else null;1867 self.libc_file = if (libc_file) |f| f.dupe(self.builder) else null;
1858 }1868 }
18591869
1860 /// Unless setOutputDir was called, this function must be called only in1870 /// Unless setOutputDir was called, this function must be called only in
...@@ -1900,18 +1910,18 @@ pub const LibExeObjStep = struct {...@@ -1900,18 +1910,18 @@ pub const LibExeObjStep = struct {
19001910
1901 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {1911 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
1902 self.link_objects.append(LinkObject{1912 self.link_objects.append(LinkObject{
1903 .AssemblyFile = .{ .path = self.builder.dupe(path) },1913 .assembly_file = .{ .path = self.builder.dupe(path) },
1904 }) catch unreachable;1914 }) catch unreachable;
1905 }1915 }
19061916
1907 pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void {1917 pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void {
1908 const source_duped = source.dupe(self.builder);1918 const source_duped = source.dupe(self.builder);
1909 self.link_objects.append(LinkObject{ .AssemblyFile = source_duped }) catch unreachable;1919 self.link_objects.append(LinkObject{ .assembly_file = source_duped }) catch unreachable;
1910 source_duped.addStepDependencies(&self.step);1920 source_duped.addStepDependencies(&self.step);
1911 }1921 }
19121922
1913 pub fn addObjectFile(self: *LibExeObjStep, path: []const u8) void {1923 pub fn addObjectFile(self: *LibExeObjStep, source: FileSource) void {
1914 self.link_objects.append(LinkObject{ .StaticPath = self.builder.dupe(path) }) catch unreachable;1924 self.link_objects.append(LinkObject{ .static_path = source.dupe(self.builder) }) catch unreachable;
1915 }1925 }
19161926
1917 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {1927 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {
...@@ -2020,26 +2030,24 @@ pub const LibExeObjStep = struct {...@@ -2020,26 +2030,24 @@ pub const LibExeObjStep = struct {
2020 /// The value is the path in the cache dir.2030 /// The value is the path in the cache dir.
2021 /// Adds a dependency automatically.2031 /// Adds a dependency automatically.
2022 /// basename refers to the basename of the WriteFileStep2032 /// basename refers to the basename of the WriteFileStep
2023 pub fn addBuildOptionWriteFile(2033 pub fn addBuildOptionFileSource(
2024 self: *LibExeObjStep,2034 self: *LibExeObjStep,
2025 name: []const u8,2035 name: []const u8,
2026 write_file: *WriteFileStep,2036 source: FileSource,
2027 basename: []const u8,
2028 ) void {2037 ) void {
2029 self.build_options_write_file_args.append(.{2038 self.build_options_file_source_args.append(.{
2030 .name = name,2039 .name = name,
2031 .write_file = write_file,2040 .source = source.dupe(self.builder),
2032 .basename = basename,
2033 }) catch unreachable;2041 }) catch unreachable;
2034 self.step.dependOn(&write_file.step);2042 source.addStepDependencies(&self.step);
2035 }2043 }
20362044
2037 pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void {2045 pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void {
2038 self.include_dirs.append(IncludeDir{ .RawPathSystem = self.builder.dupe(path) }) catch unreachable;2046 self.include_dirs.append(IncludeDir{ .raw_path_system = self.builder.dupe(path) }) catch unreachable;
2039 }2047 }
20402048
2041 pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {2049 pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {
2042 self.include_dirs.append(IncludeDir{ .RawPath = self.builder.dupe(path) }) catch unreachable;2050 self.include_dirs.append(IncludeDir{ .raw_path = self.builder.dupe(path) }) catch unreachable;
2043 }2051 }
20442052
2045 pub fn addLibPath(self: *LibExeObjStep, path: []const u8) void {2053 pub fn addLibPath(self: *LibExeObjStep, path: []const u8) void {
...@@ -2093,7 +2101,7 @@ pub const LibExeObjStep = struct {...@@ -2093,7 +2101,7 @@ pub const LibExeObjStep = struct {
20932101
2094 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });2102 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
2095 errdefer allocator.free(include_path);2103 errdefer allocator.free(include_path);
2096 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });2104 try self.include_dirs.append(IncludeDir{ .raw_path = include_path });
20972105
2098 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });2106 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
2099 try self.lib_paths.append(lib_path);2107 try self.lib_paths.append(lib_path);
...@@ -2114,13 +2122,13 @@ pub const LibExeObjStep = struct {...@@ -2114,13 +2122,13 @@ pub const LibExeObjStep = struct {
21142122
2115 fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void {2123 fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void {
2116 self.step.dependOn(&other.step);2124 self.step.dependOn(&other.step);
2117 self.link_objects.append(LinkObject{ .OtherStep = other }) catch unreachable;2125 self.link_objects.append(LinkObject{ .other_step = other }) catch unreachable;
2118 self.include_dirs.append(IncludeDir{ .OtherStep = other }) catch unreachable;2126 self.include_dirs.append(IncludeDir{ .other_step = other }) catch unreachable;
21192127
2120 // Inherit dependency on system libraries2128 // Inherit dependency on system libraries
2121 for (other.link_objects.items) |link_object| {2129 for (other.link_objects.items) |link_object| {
2122 switch (link_object) {2130 switch (link_object) {
2123 .SystemLib => |name| self.linkSystemLibrary(name),2131 .system_lib => |name| self.linkSystemLibrary(name),
2124 else => continue,2132 else => continue,
2125 }2133 }
2126 }2134 }
...@@ -2187,11 +2195,9 @@ pub const LibExeObjStep = struct {...@@ -2187,11 +2195,9 @@ pub const LibExeObjStep = struct {
2187 var prev_has_extra_flags = false;2195 var prev_has_extra_flags = false;
2188 for (self.link_objects.items) |link_object| {2196 for (self.link_objects.items) |link_object| {
2189 switch (link_object) {2197 switch (link_object) {
2190 .StaticPath => |static_path| {2198 .static_path => |static_path| try zig_args.append(static_path.getPath(builder)),
2191 try zig_args.append(builder.pathFromRoot(static_path));
2192 },
21932199
2194 .OtherStep => |other| switch (other.kind) {2200 .other_step => |other| switch (other.kind) {
2195 .Exe => unreachable,2201 .Exe => unreachable,
2196 .Test => unreachable,2202 .Test => unreachable,
2197 .Obj => {2203 .Obj => {
...@@ -2209,10 +2215,11 @@ pub const LibExeObjStep = struct {...@@ -2209,10 +2215,11 @@ pub const LibExeObjStep = struct {
2209 }2215 }
2210 },2216 },
2211 },2217 },
2212 .SystemLib => |name| {2218 .system_lib => |name| {
2213 try zig_args.append(builder.fmt("-l{s}", .{name}));2219 try zig_args.append(builder.fmt("-l{s}", .{name}));
2214 },2220 },
2215 .AssemblyFile => |asm_file| {2221
2222 .assembly_file => |asm_file| {
2216 if (prev_has_extra_flags) {2223 if (prev_has_extra_flags) {
2217 try zig_args.append("-extra-cflags");2224 try zig_args.append("-extra-cflags");
2218 try zig_args.append("--");2225 try zig_args.append("--");
...@@ -2221,7 +2228,7 @@ pub const LibExeObjStep = struct {...@@ -2221,7 +2228,7 @@ pub const LibExeObjStep = struct {
2221 try zig_args.append(asm_file.getPath(builder));2228 try zig_args.append(asm_file.getPath(builder));
2222 },2229 },
22232230
2224 .CSourceFile => |c_source_file| {2231 .c_source_file => |c_source_file| {
2225 if (c_source_file.args.len == 0) {2232 if (c_source_file.args.len == 0) {
2226 if (prev_has_extra_flags) {2233 if (prev_has_extra_flags) {
2227 try zig_args.append("-cflags");2234 try zig_args.append("-cflags");
...@@ -2238,7 +2245,7 @@ pub const LibExeObjStep = struct {...@@ -2238,7 +2245,7 @@ pub const LibExeObjStep = struct {
2238 try zig_args.append(c_source_file.source.getPath(builder));2245 try zig_args.append(c_source_file.source.getPath(builder));
2239 },2246 },
22402247
2241 .CSourceFiles => |c_source_files| {2248 .c_source_files => |c_source_files| {
2242 if (c_source_files.flags.len == 0) {2249 if (c_source_files.flags.len == 0) {
2243 if (prev_has_extra_flags) {2250 if (prev_has_extra_flags) {
2244 try zig_args.append("-cflags");2251 try zig_args.append("-cflags");
...@@ -2261,7 +2268,7 @@ pub const LibExeObjStep = struct {...@@ -2261,7 +2268,7 @@ pub const LibExeObjStep = struct {
22612268
2262 if (self.build_options_contents.items.len > 0 or2269 if (self.build_options_contents.items.len > 0 or
2263 self.build_options_artifact_args.items.len > 0 or2270 self.build_options_artifact_args.items.len > 0 or
2264 self.build_options_write_file_args.items.len > 0)2271 self.build_options_file_source_args.items.len > 0)
2265 {2272 {
2266 // Render build artifact and write file options at the last minute, now that the path is known.2273 // Render build artifact and write file options at the last minute, now that the path is known.
2267 //2274 //
...@@ -2274,11 +2281,11 @@ pub const LibExeObjStep = struct {...@@ -2274,11 +2281,11 @@ pub const LibExeObjStep = struct {
2274 self.builder.pathFromRoot(item.artifact.getOutputPath()),2281 self.builder.pathFromRoot(item.artifact.getOutputPath()),
2275 );2282 );
2276 }2283 }
2277 for (self.build_options_write_file_args.items) |item| {2284 for (self.build_options_file_source_args.items) |item| {
2278 self.addBuildOption(2285 self.addBuildOption(
2279 []const u8,2286 []const u8,
2280 item.name,2287 item.name,
2281 self.builder.pathFromRoot(item.write_file.getOutputPath(item.basename)),2288 item.source.getPath(self.builder),
2282 );2289 );
2283 }2290 }
22842291
...@@ -2349,7 +2356,7 @@ pub const LibExeObjStep = struct {...@@ -2349,7 +2356,7 @@ pub const LibExeObjStep = struct {
23492356
2350 if (self.libc_file) |libc_file| {2357 if (self.libc_file) |libc_file| {
2351 try zig_args.append("--libc");2358 try zig_args.append("--libc");
2352 try zig_args.append(builder.pathFromRoot(libc_file));2359 try zig_args.append(libc_file.getPath(self.builder));
2353 }2360 }
23542361
2355 switch (self.build_mode) {2362 switch (self.build_mode) {
...@@ -2451,7 +2458,7 @@ pub const LibExeObjStep = struct {...@@ -2451,7 +2458,7 @@ pub const LibExeObjStep = struct {
24512458
2452 if (self.linker_script) |linker_script| {2459 if (self.linker_script) |linker_script| {
2453 try zig_args.append("--script");2460 try zig_args.append("--script");
2454 try zig_args.append(builder.pathFromRoot(linker_script));2461 try zig_args.append(linker_script.getPath(builder));
2455 }2462 }
24562463
2457 if (self.version_script) |version_script| {2464 if (self.version_script) |version_script| {
...@@ -2526,15 +2533,15 @@ pub const LibExeObjStep = struct {...@@ -2526,15 +2533,15 @@ pub const LibExeObjStep = struct {
25262533
2527 for (self.include_dirs.items) |include_dir| {2534 for (self.include_dirs.items) |include_dir| {
2528 switch (include_dir) {2535 switch (include_dir) {
2529 .RawPath => |include_path| {2536 .raw_path => |include_path| {
2530 try zig_args.append("-I");2537 try zig_args.append("-I");
2531 try zig_args.append(self.builder.pathFromRoot(include_path));2538 try zig_args.append(self.builder.pathFromRoot(include_path));
2532 },2539 },
2533 .RawPathSystem => |include_path| {2540 .raw_path_system => |include_path| {
2534 try zig_args.append("-isystem");2541 try zig_args.append("-isystem");
2535 try zig_args.append(self.builder.pathFromRoot(include_path));2542 try zig_args.append(self.builder.pathFromRoot(include_path));
2536 },2543 },
2537 .OtherStep => |other| if (other.emit_h) {2544 .other_step => |other| if (other.emit_h) {
2538 const h_path = other.getOutputHPath();2545 const h_path = other.getOutputHPath();
2539 try zig_args.append("-isystem");2546 try zig_args.append("-isystem");
2540 try zig_args.append(fs.path.dirname(h_path).?);2547 try zig_args.append(fs.path.dirname(h_path).?);
...@@ -3086,11 +3093,11 @@ test "Builder.dupePkg()" {...@@ -3086,11 +3093,11 @@ test "Builder.dupePkg()" {
30863093
3087 var pkg_dep = Pkg{3094 var pkg_dep = Pkg{
3088 .name = "pkg_dep",3095 .name = "pkg_dep",
3089 .path = FileSource.relative("/not/a/pkg_dep.zig"),3096 .path = .{ .path = "/not/a/pkg_dep.zig" },
3090 };3097 };
3091 var pkg_top = Pkg{3098 var pkg_top = Pkg{
3092 .name = "pkg_top",3099 .name = "pkg_top",
3093 .path = FileSource.relative("/not/a/pkg_top.zig"),3100 .path = .{ .path = "/not/a/pkg_top.zig" },
3094 .dependencies = &[_]Pkg{pkg_dep},3101 .dependencies = &[_]Pkg{pkg_dep},
3095 };3102 };
3096 const dupe = builder.dupePkg(pkg_top);3103 const dupe = builder.dupePkg(pkg_top);
...@@ -3168,11 +3175,11 @@ test "LibExeObjStep.addPackage" {...@@ -3168,11 +3175,11 @@ test "LibExeObjStep.addPackage" {
31683175
3169 const pkg_dep = Pkg{3176 const pkg_dep = Pkg{
3170 .name = "pkg_dep",3177 .name = "pkg_dep",
3171 .path = FileSource.relative("/not/a/pkg_dep.zig"),3178 .path = .{ .path = "/not/a/pkg_dep.zig" },
3172 };3179 };
3173 const pkg_top = Pkg{3180 const pkg_top = Pkg{
3174 .name = "pkg_dep",3181 .name = "pkg_dep",
3175 .path = FileSource.relative("/not/a/pkg_top.zig"),3182 .path = .{ .path = "/not/a/pkg_top.zig" },
3176 .dependencies = &[_]Pkg{pkg_dep},3183 .dependencies = &[_]Pkg{pkg_dep},
3177 };3184 };
31783185
lib/std/build/run.zig+2-2
...@@ -71,7 +71,7 @@ pub const RunStep = struct {...@@ -71,7 +71,7 @@ pub const RunStep = struct {
7171
72 pub fn addFileSourceArg(self: *RunStep, file_source: build.FileSource) void {72 pub fn addFileSourceArg(self: *RunStep, file_source: build.FileSource) void {
73 self.argv.append(Arg{73 self.argv.append(Arg{
74 .file_source = file_source,74 .file_source = file_source.dupe(self.builder),
75 }) catch unreachable;75 }) catch unreachable;
76 file_source.addStepDependencies(&self.step);76 file_source.addStepDependencies(&self.step);
77 }77 }
...@@ -314,7 +314,7 @@ pub const RunStep = struct {...@@ -314,7 +314,7 @@ pub const RunStep = struct {
314 fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {314 fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {
315 for (artifact.link_objects.items) |link_object| {315 for (artifact.link_objects.items) |link_object| {
316 switch (link_object) {316 switch (link_object) {
317 .OtherStep => |other| {317 .other_step => |other| {
318 if (other.target.isWindows() and other.isDynamicLibrary()) {318 if (other.target.isWindows() and other.isDynamicLibrary()) {
319 self.addPathDir(fs.path.dirname(other.getOutputPath()).?);319 self.addPathDir(fs.path.dirname(other.getOutputPath()).?);
320 self.addPathForDynLibs(other);320 self.addPathForDynLibs(other);