| ... | @@ -258,9 +258,14 @@ pub const Builder = struct { | ... | @@ -258,9 +258,14 @@ pub const Builder = struct { |
| 258 | })); | 258 | })); |
| 259 | } | 259 | } |
| 260 | | 260 | |
| 261 | pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep { | 261 | pub fn addSharedLibrary( |
| | 262 | self: *Builder, |
| | 263 | name: []const u8, |
| | 264 | root_src: ?[]const u8, |
| | 265 | kind: LibExeObjStep.SharedLibKind, |
| | 266 | ) *LibExeObjStep { |
| 262 | const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null; | 267 | const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null; |
| 263 | return LibExeObjStep.createSharedLibrary(self, name, root_src_param, ver); | 268 | return LibExeObjStep.createSharedLibrary(self, name, root_src_param, kind); |
| 264 | } | 269 | } |
| 265 | | 270 | |
| 266 | pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { | 271 | pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| ... | @@ -338,11 +343,13 @@ pub const Builder = struct { | ... | @@ -338,11 +343,13 @@ pub const Builder = struct { |
| 338 | return TranslateCStep.create(self, source); | 343 | return TranslateCStep.create(self, source); |
| 339 | } | 344 | } |
| 340 | | 345 | |
| 341 | pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) Version { | 346 | pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind { |
| 342 | return Version{ | 347 | return .{ |
| 343 | .major = major, | 348 | .versioned = .{ |
| 344 | .minor = minor, | 349 | .major = major, |
| 345 | .patch = patch, | 350 | .minor = minor, |
| | 351 | .patch = patch, |
| | 352 | }, |
| 346 | }; | 353 | }; |
| 347 | } | 354 | } |
| 348 | | 355 | |
| ... | @@ -1167,7 +1174,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1167,7 +1174,7 @@ pub const LibExeObjStep = struct { |
| 1167 | version_script: ?[]const u8 = null, | 1174 | version_script: ?[]const u8 = null, |
| 1168 | out_filename: []const u8, | 1175 | out_filename: []const u8, |
| 1169 | is_dynamic: bool, | 1176 | is_dynamic: bool, |
| 1170 | version: Version, | 1177 | version: ?Version, |
| 1171 | build_mode: builtin.Mode, | 1178 | build_mode: builtin.Mode, |
| 1172 | kind: Kind, | 1179 | kind: Kind, |
| 1173 | major_only_filename: []const u8, | 1180 | major_only_filename: []const u8, |
| ... | @@ -1271,33 +1278,41 @@ pub const LibExeObjStep = struct { | ... | @@ -1271,33 +1278,41 @@ pub const LibExeObjStep = struct { |
| 1271 | Test, | 1278 | Test, |
| 1272 | }; | 1279 | }; |
| 1273 | | 1280 | |
| 1274 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, ver: Version) *LibExeObjStep { | 1281 | const SharedLibKind = union(enum) { |
| | 1282 | versioned: Version, |
| | 1283 | unversioned: void, |
| | 1284 | }; |
| | 1285 | |
| | 1286 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, kind: SharedLibKind) *LibExeObjStep { |
| 1275 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 1287 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1276 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, ver); | 1288 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, switch (kind) { |
| | 1289 | .versioned => |ver| ver, |
| | 1290 | .unversioned => null, |
| | 1291 | }); |
| 1277 | return self; | 1292 | return self; |
| 1278 | } | 1293 | } |
| 1279 | | 1294 | |
| 1280 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | 1295 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { |
| 1281 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 1296 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1282 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, builder.version(0, 0, 0)); | 1297 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, null); |
| 1283 | return self; | 1298 | return self; |
| 1284 | } | 1299 | } |
| 1285 | | 1300 | |
| 1286 | pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | 1301 | pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { |
| 1287 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 1302 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1288 | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); | 1303 | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, null); |
| 1289 | return self; | 1304 | return self; |
| 1290 | } | 1305 | } |
| 1291 | | 1306 | |
| 1292 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, is_dynamic: bool) *LibExeObjStep { | 1307 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, is_dynamic: bool) *LibExeObjStep { |
| 1293 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 1308 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1294 | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, is_dynamic, builder.version(0, 0, 0)); | 1309 | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, is_dynamic, null); |
| 1295 | return self; | 1310 | return self; |
| 1296 | } | 1311 | } |
| 1297 | | 1312 | |
| 1298 | pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep { | 1313 | pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep { |
| 1299 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 1314 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 1300 | self.* = initExtraArgs(builder, name, root_src, Kind.Test, false, builder.version(0, 0, 0)); | 1315 | self.* = initExtraArgs(builder, name, root_src, Kind.Test, false, null); |
| 1301 | return self; | 1316 | return self; |
| 1302 | } | 1317 | } |
| 1303 | | 1318 | |
| ... | @@ -1307,7 +1322,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1307,7 +1322,7 @@ pub const LibExeObjStep = struct { |
| 1307 | root_src: ?FileSource, | 1322 | root_src: ?FileSource, |
| 1308 | kind: Kind, | 1323 | kind: Kind, |
| 1309 | is_dynamic: bool, | 1324 | is_dynamic: bool, |
| 1310 | ver: Version, | 1325 | ver: ?Version, |
| 1311 | ) LibExeObjStep { | 1326 | ) LibExeObjStep { |
| 1312 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { | 1327 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { |
| 1313 | panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); | 1328 | panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); |
| ... | @@ -1379,17 +1394,17 @@ pub const LibExeObjStep = struct { | ... | @@ -1379,17 +1394,17 @@ pub const LibExeObjStep = struct { |
| 1379 | self.target.staticLibSuffix(), | 1394 | self.target.staticLibSuffix(), |
| 1380 | }); | 1395 | }); |
| 1381 | self.out_lib_filename = self.out_filename; | 1396 | self.out_lib_filename = self.out_filename; |
| 1382 | } else { | 1397 | } else if (self.version) |version| { |
| 1383 | if (self.target.isDarwin()) { | 1398 | if (self.target.isDarwin()) { |
| 1384 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{ | 1399 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{ |
| 1385 | self.name, | 1400 | self.name, |
| 1386 | self.version.major, | 1401 | version.major, |
| 1387 | self.version.minor, | 1402 | version.minor, |
| 1388 | self.version.patch, | 1403 | version.patch, |
| 1389 | }); | 1404 | }); |
| 1390 | self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{ | 1405 | self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{ |
| 1391 | self.name, | 1406 | self.name, |
| 1392 | self.version.major, | 1407 | version.major, |
| 1393 | }); | 1408 | }); |
| 1394 | self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name}); | 1409 | self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name}); |
| 1395 | self.out_lib_filename = self.out_filename; | 1410 | self.out_lib_filename = self.out_filename; |
| ... | @@ -1399,14 +1414,25 @@ pub const LibExeObjStep = struct { | ... | @@ -1399,14 +1414,25 @@ pub const LibExeObjStep = struct { |
| 1399 | } else { | 1414 | } else { |
| 1400 | self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{ | 1415 | self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{ |
| 1401 | self.name, | 1416 | self.name, |
| 1402 | self.version.major, | 1417 | version.major, |
| 1403 | self.version.minor, | 1418 | version.minor, |
| 1404 | self.version.patch, | 1419 | version.patch, |
| 1405 | }); | 1420 | }); |
| 1406 | self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major }); | 1421 | self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, version.major }); |
| 1407 | self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name}); | 1422 | self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name}); |
| 1408 | self.out_lib_filename = self.out_filename; | 1423 | self.out_lib_filename = self.out_filename; |
| 1409 | } | 1424 | } |
| | 1425 | } else { |
| | 1426 | if (self.target.isDarwin()) { |
| | 1427 | self.out_filename = self.builder.fmt("lib{}.dylib", .{self.name}); |
| | 1428 | self.out_lib_filename = self.out_filename; |
| | 1429 | } else if (self.target.isWindows()) { |
| | 1430 | self.out_filename = self.builder.fmt("{}.dll", .{self.name}); |
| | 1431 | self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name}); |
| | 1432 | } else { |
| | 1433 | self.out_filename = self.builder.fmt("lib{}.so", .{self.name}); |
| | 1434 | self.out_lib_filename = self.out_filename; |
| | 1435 | } |
| 1410 | } | 1436 | } |
| 1411 | }, | 1437 | }, |
| 1412 | } | 1438 | } |
| ... | @@ -2041,14 +2067,16 @@ pub const LibExeObjStep = struct { | ... | @@ -2041,14 +2067,16 @@ pub const LibExeObjStep = struct { |
| 2041 | zig_args.append(self.name) catch unreachable; | 2067 | zig_args.append(self.name) catch unreachable; |
| 2042 | | 2068 | |
| 2043 | if (self.kind == Kind.Lib and self.is_dynamic) { | 2069 | if (self.kind == Kind.Lib and self.is_dynamic) { |
| 2044 | zig_args.append("--ver-major") catch unreachable; | 2070 | if (self.version) |version| { |
| 2045 | zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable; | 2071 | zig_args.append("--ver-major") catch unreachable; |
| | 2072 | zig_args.append(builder.fmt("{}", .{version.major})) catch unreachable; |
| 2046 | | 2073 | |
| 2047 | zig_args.append("--ver-minor") catch unreachable; | 2074 | zig_args.append("--ver-minor") catch unreachable; |
| 2048 | zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable; | 2075 | zig_args.append(builder.fmt("{}", .{version.minor})) catch unreachable; |
| 2049 | | 2076 | |
| 2050 | zig_args.append("--ver-patch") catch unreachable; | 2077 | zig_args.append("--ver-patch") catch unreachable; |
| 2051 | zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable; | 2078 | zig_args.append(builder.fmt("{}", .{version.patch})) catch unreachable; |
| | 2079 | } |
| 2052 | } | 2080 | } |
| 2053 | if (self.is_dynamic) { | 2081 | if (self.is_dynamic) { |
| 2054 | try zig_args.append("-dynamic"); | 2082 | try zig_args.append("-dynamic"); |
| ... | @@ -2289,7 +2317,7 @@ pub const LibExeObjStep = struct { | ... | @@ -2289,7 +2317,7 @@ pub const LibExeObjStep = struct { |
| 2289 | } | 2317 | } |
| 2290 | } | 2318 | } |
| 2291 | | 2319 | |
| 2292 | if (self.kind == Kind.Lib and self.is_dynamic and self.target.wantSharedLibSymLinks()) { | 2320 | if (self.kind == Kind.Lib and self.is_dynamic and self.version != null and self.target.wantSharedLibSymLinks()) { |
| 2293 | try doAtomicSymLinks(builder.allocator, self.getOutputPath(), self.major_only_filename, self.name_only_filename); | 2321 | try doAtomicSymLinks(builder.allocator, self.getOutputPath(), self.major_only_filename, self.name_only_filename); |
| 2294 | } | 2322 | } |
| 2295 | } | 2323 | } |
| ... | @@ -2333,8 +2361,10 @@ pub const InstallArtifactStep = struct { | ... | @@ -2333,8 +2361,10 @@ pub const InstallArtifactStep = struct { |
| 2333 | | 2361 | |
| 2334 | builder.pushInstalledFile(self.dest_dir, artifact.out_filename); | 2362 | builder.pushInstalledFile(self.dest_dir, artifact.out_filename); |
| 2335 | if (self.artifact.isDynamicLibrary()) { | 2363 | if (self.artifact.isDynamicLibrary()) { |
| 2336 | builder.pushInstalledFile(.Lib, artifact.major_only_filename); | 2364 | if (self.artifact.version != null) { |
| 2337 | builder.pushInstalledFile(.Lib, artifact.name_only_filename); | 2365 | builder.pushInstalledFile(.Lib, artifact.major_only_filename); |
| | 2366 | builder.pushInstalledFile(.Lib, artifact.name_only_filename); |
| | 2367 | } |
| 2338 | if (self.artifact.target.isWindows()) { | 2368 | if (self.artifact.target.isWindows()) { |
| 2339 | builder.pushInstalledFile(.Lib, artifact.out_lib_filename); | 2369 | builder.pushInstalledFile(.Lib, artifact.out_lib_filename); |
| 2340 | } | 2370 | } |
| ... | @@ -2354,7 +2384,7 @@ pub const InstallArtifactStep = struct { | ... | @@ -2354,7 +2384,7 @@ pub const InstallArtifactStep = struct { |
| 2354 | | 2384 | |
| 2355 | const full_dest_path = builder.getInstallPath(self.dest_dir, self.artifact.out_filename); | 2385 | const full_dest_path = builder.getInstallPath(self.dest_dir, self.artifact.out_filename); |
| 2356 | try builder.updateFile(self.artifact.getOutputPath(), full_dest_path); | 2386 | try builder.updateFile(self.artifact.getOutputPath(), full_dest_path); |
| 2357 | if (self.artifact.isDynamicLibrary() and self.artifact.target.wantSharedLibSymLinks()) { | 2387 | if (self.artifact.isDynamicLibrary() and self.artifact.version != null and self.artifact.target.wantSharedLibSymLinks()) { |
| 2358 | try doAtomicSymLinks(builder.allocator, full_dest_path, self.artifact.major_only_filename, self.artifact.name_only_filename); | 2388 | try doAtomicSymLinks(builder.allocator, full_dest_path, self.artifact.major_only_filename, self.artifact.name_only_filename); |
| 2359 | } | 2389 | } |
| 2360 | if (self.pdb_dir) |pdb_dir| { | 2390 | if (self.pdb_dir) |pdb_dir| { |