| ... | ... | @@ -174,7 +174,7 @@ pub const Builder = struct { |
| 174 | 174 | .is_release = false, |
| 175 | 175 | .override_lib_dir = null, |
| 176 | 176 | .install_path = undefined, |
| 177 | | .vcpkg_root = VcpkgRoot{ .Unattempted = {} }, |
| 177 | .vcpkg_root = VcpkgRoot{ .unattempted = {} }, |
| 178 | 178 | .args = null, |
| 179 | 179 | }; |
| 180 | 180 | try self.top_level_steps.append(&self.install_tls); |
| ... | ... | @@ -212,7 +212,7 @@ pub const Builder = struct { |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| 215 | | return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src), false); |
| 215 | return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src), .static); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | pub const addExecutableSource = LibExeObjStep.createExecutable; |
| ... | ... | @@ -250,7 +250,7 @@ pub const Builder = struct { |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | pub fn addAssemble(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep { |
| 253 | | return addAssembleSource(self, name, FileSource.relative(src)); |
| 253 | return addAssembleSource(self, name, .{ .path = src }); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | pub fn addAssembleSource(self: *Builder, name: []const u8, src: FileSource) *LibExeObjStep { |
| ... | ... | @@ -876,7 +876,7 @@ pub const Builder = struct { |
| 876 | 876 | |
| 877 | 877 | ///`dest_rel_path` is relative to prefix path |
| 878 | 878 | pub fn installFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void { |
| 879 | | self.getInstallStep().dependOn(&self.addInstallFileWithDir(FileSource.relative(src_path), .Prefix, dest_rel_path).step); |
| 879 | self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .Prefix, dest_rel_path).step); |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | pub fn installDirectory(self: *Builder, options: InstallDirectoryOptions) void { |
| ... | ... | @@ -885,12 +885,12 @@ pub const Builder = struct { |
| 885 | 885 | |
| 886 | 886 | ///`dest_rel_path` is relative to bin path |
| 887 | 887 | pub fn installBinFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void { |
| 888 | | self.getInstallStep().dependOn(&self.addInstallFileWithDir(FileSource.relative(src_path), .Bin, dest_rel_path).step); |
| 888 | self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .Bin, dest_rel_path).step); |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | ///`dest_rel_path` is relative to lib path |
| 892 | 892 | pub fn installLibFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void { |
| 893 | | self.getInstallStep().dependOn(&self.addInstallFileWithDir(FileSource.relative(src_path), .Lib, dest_rel_path).step); |
| 893 | self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .Lib, dest_rel_path).step); |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void { |
| ... | ... | @@ -1239,7 +1239,7 @@ pub const GeneratedFile = struct { |
| 1239 | 1239 | /// A file source is a reference to an existing or future file. |
| 1240 | 1240 | /// |
| 1241 | 1241 | pub const FileSource = union(enum) { |
| 1242 | | /// A plain file path, relative to build root. |
| 1242 | /// A plain file path, relative to build root or absolute. |
| 1243 | 1243 | path: []const u8, |
| 1244 | 1244 | |
| 1245 | 1245 | /// A file that is generated by an interface. Those files usually are |
| ... | ... | @@ -1270,13 +1270,12 @@ pub const FileSource = union(enum) { |
| 1270 | 1270 | } |
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | | /// Should only be called during make(), returns an absolute path to the file. |
| 1273 | /// Should only be called during make(), returns a path relative to the build root or absolute. |
| 1274 | 1274 | pub fn getPath(self: FileSource, builder: *Builder) []const u8 { |
| 1275 | 1275 | const path = switch (self) { |
| 1276 | 1276 | .path => |p| builder.pathFromRoot(p), |
| 1277 | 1277 | .generated => |gen| gen.getPath(), |
| 1278 | 1278 | }; |
| 1279 | | std.debug.assert(std.fs.path.isAbsolute(path)); |
| 1280 | 1279 | return path; |
| 1281 | 1280 | } |
| 1282 | 1281 | |
| ... | ... | @@ -1307,7 +1306,7 @@ pub const LibExeObjStep = struct { |
| 1307 | 1306 | linker_script: ?FileSource = null, |
| 1308 | 1307 | version_script: ?[]const u8 = null, |
| 1309 | 1308 | out_filename: []const u8, |
| 1310 | | is_dynamic: bool, |
| 1309 | linkage: Linkage, |
| 1311 | 1310 | version: ?Version, |
| 1312 | 1311 | build_mode: builtin.Mode, |
| 1313 | 1312 | kind: Kind, |
| ... | ... | @@ -1442,9 +1441,11 @@ pub const LibExeObjStep = struct { |
| 1442 | 1441 | unversioned: void, |
| 1443 | 1442 | }; |
| 1444 | 1443 | |
| 1444 | pub const Linkage = enum { dynamic, static }; |
| 1445 | |
| 1445 | 1446 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, kind: SharedLibKind) *LibExeObjStep { |
| 1446 | 1447 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1447 | | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, switch (kind) { |
| 1448 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, .dynamic, switch (kind) { |
| 1448 | 1449 | .versioned => |ver| ver, |
| 1449 | 1450 | .unversioned => null, |
| 1450 | 1451 | }); |
| ... | ... | @@ -1453,25 +1454,25 @@ pub const LibExeObjStep = struct { |
| 1453 | 1454 | |
| 1454 | 1455 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { |
| 1455 | 1456 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1456 | | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, null); |
| 1457 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, .static, null); |
| 1457 | 1458 | return self; |
| 1458 | 1459 | } |
| 1459 | 1460 | |
| 1460 | 1461 | pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { |
| 1461 | 1462 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1462 | | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, null); |
| 1463 | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, .static, null); |
| 1463 | 1464 | return self; |
| 1464 | 1465 | } |
| 1465 | 1466 | |
| 1466 | | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, is_dynamic: bool) *LibExeObjStep { |
| 1467 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, linkage: Linkage) *LibExeObjStep { |
| 1467 | 1468 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1468 | | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, is_dynamic, null); |
| 1469 | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, linkage, null); |
| 1469 | 1470 | return self; |
| 1470 | 1471 | } |
| 1471 | 1472 | |
| 1472 | 1473 | pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep { |
| 1473 | 1474 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1474 | | self.* = initExtraArgs(builder, name, root_src, Kind.Test, false, null); |
| 1475 | self.* = initExtraArgs(builder, name, root_src, Kind.Test, .static, null); |
| 1475 | 1476 | return self; |
| 1476 | 1477 | } |
| 1477 | 1478 | |
| ... | ... | @@ -1480,7 +1481,7 @@ pub const LibExeObjStep = struct { |
| 1480 | 1481 | name_raw: []const u8, |
| 1481 | 1482 | root_src_raw: ?FileSource, |
| 1482 | 1483 | kind: Kind, |
| 1483 | | is_dynamic: bool, |
| 1484 | linkage: Linkage, |
| 1484 | 1485 | ver: ?Version, |
| 1485 | 1486 | ) LibExeObjStep { |
| 1486 | 1487 | const name = builder.dupe(name_raw); |
| ... | ... | @@ -1494,7 +1495,7 @@ pub const LibExeObjStep = struct { |
| 1494 | 1495 | .verbose_link = false, |
| 1495 | 1496 | .verbose_cc = false, |
| 1496 | 1497 | .build_mode = builtin.Mode.Debug, |
| 1497 | | .is_dynamic = is_dynamic, |
| 1498 | .linkage = linkage, |
| 1498 | 1499 | .kind = kind, |
| 1499 | 1500 | .root_src = root_src, |
| 1500 | 1501 | .name = name, |
| ... | ... | @@ -1553,12 +1554,15 @@ pub const LibExeObjStep = struct { |
| 1553 | 1554 | .Obj => .Obj, |
| 1554 | 1555 | .Exe, .Test => .Exe, |
| 1555 | 1556 | }, |
| 1556 | | .link_mode = if (self.is_dynamic) .Dynamic else .Static, |
| 1557 | .link_mode = switch (self.linkage) { |
| 1558 | .dynamic => std.builtin.LinkMode.Dynamic, |
| 1559 | .static => std.builtin.LinkMode.Static, |
| 1560 | }, |
| 1557 | 1561 | .version = self.version, |
| 1558 | 1562 | }) catch unreachable; |
| 1559 | 1563 | |
| 1560 | 1564 | if (self.kind == .Lib) { |
| 1561 | | if (!self.is_dynamic) { |
| 1565 | if (self.linkage == .static) { |
| 1562 | 1566 | self.out_lib_filename = self.out_filename; |
| 1563 | 1567 | } else if (self.version) |version| { |
| 1564 | 1568 | if (target.isDarwin()) { |
| ... | ... | @@ -1655,7 +1659,7 @@ pub const LibExeObjStep = struct { |
| 1655 | 1659 | } |
| 1656 | 1660 | |
| 1657 | 1661 | pub fn isDynamicLibrary(self: *LibExeObjStep) bool { |
| 1658 | | return self.kind == Kind.Lib and self.is_dynamic; |
| 1662 | return self.kind == Kind.Lib and self.linkage == .dynamic; |
| 1659 | 1663 | } |
| 1660 | 1664 | |
| 1661 | 1665 | pub fn producesPdbFile(self: *LibExeObjStep) bool { |
| ... | ... | @@ -1920,8 +1924,13 @@ pub const LibExeObjStep = struct { |
| 1920 | 1924 | source_duped.addStepDependencies(&self.step); |
| 1921 | 1925 | } |
| 1922 | 1926 | |
| 1923 | | pub fn addObjectFile(self: *LibExeObjStep, source: FileSource) void { |
| 1927 | pub fn addObjectFile(self: *LibExeObjStep, source_file: []const u8) void { |
| 1928 | self.addObjectFileSource(.{ .path = source_file }); |
| 1929 | } |
| 1930 | |
| 1931 | pub fn addObjectFileSource(self: *LibExeObjStep, source: FileSource) void { |
| 1924 | 1932 | self.link_objects.append(LinkObject{ .static_path = source.dupe(self.builder) }) catch unreachable; |
| 1933 | source.addStepDependencies(&self.step); |
| 1925 | 1934 | } |
| 1926 | 1935 | |
| 1927 | 1936 | pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void { |
| ... | ... | @@ -2063,15 +2072,24 @@ pub const LibExeObjStep = struct { |
| 2063 | 2072 | } |
| 2064 | 2073 | |
| 2065 | 2074 | pub fn addPackage(self: *LibExeObjStep, package: Pkg) void { |
| 2066 | | package.path.addStepDependencies(&self.step); |
| 2067 | 2075 | self.packages.append(self.builder.dupePkg(package)) catch unreachable; |
| 2076 | self.addRecursiveBuildDeps(package); |
| 2077 | } |
| 2078 | |
| 2079 | fn addRecursiveBuildDeps(self: *LibExeObjStep, package: Pkg) void { |
| 2080 | package.path.addStepDependencies(&self.step); |
| 2081 | if (package.dependencies) |deps| { |
| 2082 | for (deps) |dep| { |
| 2083 | self.addRecursiveBuildDeps(dep); |
| 2084 | } |
| 2085 | } |
| 2068 | 2086 | } |
| 2069 | 2087 | |
| 2070 | 2088 | pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void { |
| 2071 | | self.packages.append(Pkg{ |
| 2089 | self.addPackage(Pkg{ |
| 2072 | 2090 | .name = self.builder.dupe(name), |
| 2073 | 2091 | .path = .{ .path = self.builder.dupe(pkg_index_path) }, |
| 2074 | | }) catch unreachable; |
| 2092 | }); |
| 2075 | 2093 | } |
| 2076 | 2094 | |
| 2077 | 2095 | /// If Vcpkg was found on the system, it will be added to include and lib |
| ... | ... | @@ -2081,20 +2099,20 @@ pub const LibExeObjStep = struct { |
| 2081 | 2099 | // after findVcpkgRoot and have only one switch statement, but the compiler |
| 2082 | 2100 | // cannot resolve the error set. |
| 2083 | 2101 | switch (self.builder.vcpkg_root) { |
| 2084 | | .Unattempted => { |
| 2102 | .unattempted => { |
| 2085 | 2103 | self.builder.vcpkg_root = if (try findVcpkgRoot(self.builder.allocator)) |root| |
| 2086 | | VcpkgRoot{ .Found = root } |
| 2104 | VcpkgRoot{ .found = root } |
| 2087 | 2105 | else |
| 2088 | | .NotFound; |
| 2106 | .not_found; |
| 2089 | 2107 | }, |
| 2090 | | .NotFound => return error.VcpkgNotFound, |
| 2091 | | .Found => {}, |
| 2108 | .not_found => return error.VcpkgNotFound, |
| 2109 | .found => {}, |
| 2092 | 2110 | } |
| 2093 | 2111 | |
| 2094 | 2112 | switch (self.builder.vcpkg_root) { |
| 2095 | | .Unattempted => unreachable, |
| 2096 | | .NotFound => return error.VcpkgNotFound, |
| 2097 | | .Found => |root| { |
| 2113 | .unattempted => unreachable, |
| 2114 | .not_found => return error.VcpkgNotFound, |
| 2115 | .found => |root| { |
| 2098 | 2116 | const allocator = self.builder.allocator; |
| 2099 | 2117 | const triplet = try self.target.vcpkgTriplet(allocator, linkage); |
| 2100 | 2118 | defer self.builder.allocator.free(triplet); |
| ... | ... | @@ -2207,7 +2225,7 @@ pub const LibExeObjStep = struct { |
| 2207 | 2225 | const full_path_lib = other.getOutputLibPath(); |
| 2208 | 2226 | try zig_args.append(full_path_lib); |
| 2209 | 2227 | |
| 2210 | | if (other.is_dynamic and !self.target.isWindows()) { |
| 2228 | if (other.linkage == .dynamic and !self.target.isWindows()) { |
| 2211 | 2229 | if (fs.path.dirname(full_path_lib)) |dirname| { |
| 2212 | 2230 | try zig_args.append("-rpath"); |
| 2213 | 2231 | try zig_args.append(dirname); |
| ... | ... | @@ -2373,13 +2391,13 @@ pub const LibExeObjStep = struct { |
| 2373 | 2391 | zig_args.append("--name") catch unreachable; |
| 2374 | 2392 | zig_args.append(self.name) catch unreachable; |
| 2375 | 2393 | |
| 2376 | | if (self.kind == Kind.Lib and self.is_dynamic) { |
| 2394 | if (self.kind == Kind.Lib and self.linkage == .dynamic) { |
| 2377 | 2395 | if (self.version) |version| { |
| 2378 | 2396 | zig_args.append("--version") catch unreachable; |
| 2379 | 2397 | zig_args.append(builder.fmt("{}", .{version})) catch unreachable; |
| 2380 | 2398 | } |
| 2381 | 2399 | } |
| 2382 | | if (self.is_dynamic) { |
| 2400 | if (self.linkage == .dynamic) { |
| 2383 | 2401 | try zig_args.append("-dynamic"); |
| 2384 | 2402 | } |
| 2385 | 2403 | if (self.bundle_compiler_rt) |x| { |
| ... | ... | @@ -2682,7 +2700,7 @@ pub const LibExeObjStep = struct { |
| 2682 | 2700 | } |
| 2683 | 2701 | } |
| 2684 | 2702 | |
| 2685 | | if (self.kind == Kind.Lib and self.is_dynamic and self.version != null and self.target.wantSharedLibSymLinks()) { |
| 2703 | if (self.kind == .Lib and self.linkage == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) { |
| 2686 | 2704 | try doAtomicSymLinks(builder.allocator, self.getOutputPath(), self.major_only_filename.?, self.name_only_filename.?); |
| 2687 | 2705 | } |
| 2688 | 2706 | } |
| ... | ... | @@ -3033,15 +3051,15 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 { |
| 3033 | 3051 | } |
| 3034 | 3052 | |
| 3035 | 3053 | const VcpkgRoot = union(VcpkgRootStatus) { |
| 3036 | | Unattempted: void, |
| 3037 | | NotFound: void, |
| 3038 | | Found: []const u8, |
| 3054 | unattempted: void, |
| 3055 | not_found: void, |
| 3056 | found: []const u8, |
| 3039 | 3057 | }; |
| 3040 | 3058 | |
| 3041 | 3059 | const VcpkgRootStatus = enum { |
| 3042 | | Unattempted, |
| 3043 | | NotFound, |
| 3044 | | Found, |
| 3060 | unattempted, |
| 3061 | not_found, |
| 3062 | found, |
| 3045 | 3063 | }; |
| 3046 | 3064 | |
| 3047 | 3065 | pub const VcpkgLinkage = std.builtin.LinkMode; |