authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 12:00:25+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 12:00:25+02:00
log3ece3f83f3457544d58dad5f56dd7ba338f07d9a
treecc4c6cd2c9c34793b29931d5cf23aecb9068448b
parent2e28ab153c39df77403eb64f282589349f05921d

macho: clean up helpers for std.SemanticVersion <-> Apple version formatting


1 files changed, 17 insertions(+), 17 deletions(-)

src/link/MachO/load_commands.zig+17-17
......@@ -269,7 +269,7 @@ pub fn writeVersionMinLC(platform: Platform, sdk_version: ?std.SemanticVersion,
269269 try lc_writer.writeAll(mem.asBytes(&macho.version_min_command{
270270 .cmd = cmd,
271271 .version = platform.toAppleVersion(),
272 .sdk = if (sdk_version) |ver| Platform.semanticVersionToAppleVersion(ver) else platform.toAppleVersion(),
272 .sdk = if (sdk_version) |ver| semanticVersionToAppleVersion(ver) else platform.toAppleVersion(),
273273 }));
274274}
275275
......@@ -279,7 +279,7 @@ pub fn writeBuildVersionLC(platform: Platform, sdk_version: ?std.SemanticVersion
279279 .cmdsize = cmdsize,
280280 .platform = platform.toApplePlatform(),
281281 .minos = platform.toAppleVersion(),
282 .sdk = if (sdk_version) |ver| Platform.semanticVersionToAppleVersion(ver) else platform.toAppleVersion(),
282 .sdk = if (sdk_version) |ver| semanticVersionToAppleVersion(ver) else platform.toAppleVersion(),
283283 .ntools = 1,
284284 });
285285 try lc_writer.writeAll(mem.asBytes(&macho.build_tool_version{
......@@ -383,21 +383,6 @@ pub const Platform = struct {
383383 }
384384 return false;
385385 }
386
387 pub inline fn semanticVersionToAppleVersion(version: std.SemanticVersion) u32 {
388 const major = version.major;
389 const minor = version.minor;
390 const patch = version.patch;
391 return (@as(u32, @intCast(major)) << 16) | (@as(u32, @intCast(minor)) << 8) | @as(u32, @intCast(patch));
392 }
393
394 inline fn appleVersionToSemanticVersion(version: u32) std.SemanticVersion {
395 return .{
396 .major = @as(u16, @truncate(version >> 16)),
397 .minor = @as(u8, @truncate(version >> 8)),
398 .patch = @as(u8, @truncate(version)),
399 };
400 }
401386};
402387
403388const SupportedPlatforms = struct {
......@@ -419,6 +404,21 @@ const supported_platforms = [_]SupportedPlatforms{
419404 .{ .watchos, .simulator, 0x60000, 0x20000, null },
420405};
421406
407pub inline fn semanticVersionToAppleVersion(version: std.SemanticVersion) u32 {
408 const major = version.major;
409 const minor = version.minor;
410 const patch = version.patch;
411 return (@as(u32, @intCast(major)) << 16) | (@as(u32, @intCast(minor)) << 8) | @as(u32, @intCast(patch));
412}
413
414inline fn appleVersionToSemanticVersion(version: u32) std.SemanticVersion {
415 return .{
416 .major = @as(u16, @truncate(version >> 16)),
417 .minor = @as(u8, @truncate(version >> 8)),
418 .patch = @as(u8, @truncate(version)),
419 };
420}
421
422422pub fn inferSdkVersionFromSdkPath(path: []const u8) ?std.SemanticVersion {
423423 const stem = std.fs.path.stem(path);
424424 const start = for (stem, 0..) |c, i| {