| ... | @@ -206,7 +206,7 @@ pub const Builder = struct { | ... | @@ -206,7 +206,7 @@ pub const Builder = struct { |
| 206 | | 206 | |
| 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 | else | 210 | 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 | } |
| 247 | | 247 | |
| 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 | } |
| 251 | | 251 | |
| 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 { |
| 255 | | 255 | |
| 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 | } |
| 261 | | 261 | |
| ... | @@ -341,7 +341,7 @@ pub const Builder = struct { | ... | @@ -341,7 +341,7 @@ pub const Builder = struct { |
| 341 | } | 341 | } |
| 342 | | 342 | |
| 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 | } |
| 346 | | 346 | |
| 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 | } |
| 899 | | 899 | |
| 900 | ///`dest_rel_path` is relative to install prefix path | 900 | ///`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 | } |
| 904 | | 904 | |
| 905 | ///`dest_rel_path` is relative to bin path | 905 | ///`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 | } |
| 909 | | 909 | |
| 910 | ///`dest_rel_path` is relative to lib path | 910 | ///`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 | } |
| 914 | | 914 | |
| 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 | } |
| 932 | | 932 | |
| ... | @@ -1236,12 +1236,20 @@ pub const GeneratedFile = struct { | ... | @@ -1236,12 +1236,20 @@ pub const GeneratedFile = struct { |
| 1236 | } | 1236 | } |
| 1237 | }; | 1237 | }; |
| 1238 | | 1238 | |
| | 1239 | /// A file source is a reference to an existing or future file. |
| | 1240 | /// |
| 1239 | pub const FileSource = union(enum) { | 1241 | pub const FileSource = union(enum) { |
| 1240 | /// Relative to build root | 1242 | /// 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, |
| 1243 | | 1248 | |
| | 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 | } |
| 1247 | | 1255 | |
| ... | @@ -1254,6 +1262,7 @@ pub const FileSource = union(enum) { | ... | @@ -1254,6 +1262,7 @@ pub const FileSource = union(enum) { |
| 1254 | }; | 1262 | }; |
| 1255 | } | 1263 | } |
| 1256 | | 1264 | |
| | 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 | } |
| 1273 | | 1282 | |
| | 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 | }; |
| 1286 | | 1296 | |
| 1287 | const BuildOptionWriteFileArg = struct { | 1297 | const BuildOptionFileSourceArg = struct { |
| 1288 | name: []const u8, | 1298 | name: []const u8, |
| 1289 | write_file: *WriteFileStep, | 1299 | source: FileSource, |
| 1290 | basename: []const u8, | | |
| 1291 | }; | 1300 | }; |
| 1292 | | 1301 | |
| 1293 | pub const LibExeObjStep = struct { | 1302 | pub 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), |
| 1342 | | 1351 | |
| 1343 | object_src: []const u8, | 1352 | object_src: []const u8, |
| 1344 | | 1353 | |
| ... | @@ -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, |
| 1360 | | 1369 | |
| 1361 | libc_file: ?[]const u8 = null, | 1370 | libc_file: ?FileSource = null, |
| 1362 | | 1371 | |
| 1363 | valgrind_support: ?bool = null, | 1372 | valgrind_support: ?bool = null, |
| 1364 | | 1373 | |
| ... | @@ -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, |
| 1408 | | 1417 | |
| 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 | }; |
| 1417 | | 1426 | |
| 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 | }; |
| 1423 | | 1432 | |
| 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 | } |
| 1615 | | 1624 | |
| 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 | } |
| 1619 | | 1628 | |
| 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 | } |
| 1664 | | 1673 | |
| ... | @@ -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 | } |
| 1682 | | 1691 | |
| 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 | } |
| 1822 | | 1831 | |
| 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 | } |
| 1835 | | 1845 | |
| 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 | } |
| 1855 | | 1865 | |
| 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 | } |
| 1859 | | 1869 | |
| 1860 | /// Unless setOutputDir was called, this function must be called only in | 1870 | /// 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 { |
| 1900 | | 1910 | |
| 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 | } |
| 1906 | | 1916 | |
| 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 | } |
| 1912 | | 1922 | |
| 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 | } |
| 1916 | | 1926 | |
| 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 WriteFileStep | 2032 | /// 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 | } |
| 2036 | | 2044 | |
| 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 | } |
| 2040 | | 2048 | |
| 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 | } |
| 2044 | | 2052 | |
| 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 { |
| 2093 | | 2101 | |
| 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 }); |
| 2097 | | 2105 | |
| 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 { |
| 2114 | | 2122 | |
| 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; |
| 2119 | | 2127 | |
| 2120 | // Inherit dependency on system libraries | 2128 | // 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 | }, | | |
| 2193 | | 2199 | |
| 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 | }, |
| 2223 | | 2230 | |
| 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 | }, |
| 2240 | | 2247 | |
| 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 { |
| 2261 | | 2268 | |
| 2262 | if (self.build_options_contents.items.len > 0 or | 2269 | if (self.build_options_contents.items.len > 0 or |
| 2263 | self.build_options_artifact_args.items.len > 0 or | 2270 | 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 | } |
| 2284 | | 2291 | |
| ... | @@ -2349,7 +2356,7 @@ pub const LibExeObjStep = struct { | ... | @@ -2349,7 +2356,7 @@ pub const LibExeObjStep = struct { |
| 2349 | | 2356 | |
| 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 | } |
| 2354 | | 2361 | |
| 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 { |
| 2451 | | 2458 | |
| 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 | } |
| 2456 | | 2463 | |
| 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 { |
| 2526 | | 2533 | |
| 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()" { |
| 3086 | | 3093 | |
| 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" { |
| 3168 | | 3175 | |
| 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 | }; |
| 3178 | | 3185 | |