aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-11-10 15:23:18 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-11-10 15:24:10 -0700
commit6904cd828edb34217cd4d54e8f6fe5bb91cb4858 (patch)
treed588f2e9c8bd30f3dfb3efd13937af6cc86f857a /src/Compilation.zig
parent3110b21c4ba5840f6074a0f76e1186c9958915e8 (diff)
downloadzig-6904cd828edb34217cd4d54e8f6fe5bb91cb4858.tar.gz
zig-6904cd828edb34217cd4d54e8f6fe5bb91cb4858.zip
add missing -m<os>-version-min CLI args to clang
This fixes some code generation issues when targeting macOS and compiling C/C++ code.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 65fa296ca4..b3cb9e31f0 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -613,6 +613,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
cache.hash.addBytes(options.target.cpu.model.name);
cache.hash.add(options.target.cpu.features.ints);
cache.hash.add(options.target.os.tag);
+ cache.hash.add(options.target.os.getVersionRange());
cache.hash.add(options.is_native_os);
cache.hash.add(options.target.abi);
cache.hash.add(ofmt);
@@ -642,7 +643,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
hash.addOptionalBytes(root_pkg.root_src_directory.path);
hash.add(valgrind);
hash.add(single_threaded);
- hash.add(options.target.os.getVersionRange());
hash.add(dll_export_fns);
hash.add(options.is_test);
hash.add(options.is_compiler_rt_or_libc);
@@ -1619,7 +1619,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
const out_dep_path: ?[]const u8 = if (comp.disable_c_depfile or !ext.clangSupportsDepFile())
null
else
- try std.fmt.allocPrint(arena, "{}.d", .{out_obj_path});
+ try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path});
try comp.addCCArgs(arena, &argv, ext, out_dep_path);
try argv.ensureCapacity(argv.items.len + 3);
@@ -1849,10 +1849,39 @@ pub fn addCCArgs(
try argv.append(try std.fmt.allocPrint(arena, "-mcmodel={}", .{@tagName(mcmodel)}));
}
- // windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning.
- // So for this target, we disable this warning.
- if (target.os.tag == .windows and target.abi.isGnu()) {
- try argv.append("-Wno-pragma-pack");
+ switch (target.os.tag) {
+ .windows => {
+ // windows.h has files such as pshpack1.h which do #pragma packing,
+ // triggering a clang warning. So for this target, we disable this warning.
+ if (target.abi.isGnu()) {
+ try argv.append("-Wno-pragma-pack");
+ }
+ },
+ .macos => {
+ // Pass the proper -m<os>-version-min argument for darwin.
+ const ver = target.os.version_range.semver.min;
+ try argv.append(try std.fmt.allocPrint(arena, "-mmacos-version-min={d}.{d}.{d}", .{
+ ver.major, ver.minor, ver.patch,
+ }));
+ },
+ .ios, .tvos, .watchos => switch (target.cpu.arch) {
+ // Pass the proper -m<os>-version-min argument for darwin.
+ .i386, .x86_64 => {
+ const ver = target.os.version_range.semver.min;
+ try argv.append(try std.fmt.allocPrint(
+ arena,
+ "-m{s}-simulator-version-min={d}.{d}.{d}",
+ .{ @tagName(target.os.tag), ver.major, ver.minor, ver.patch },
+ ));
+ },
+ else => {
+ const ver = target.os.version_range.semver.min;
+ try argv.append(try std.fmt.allocPrint(arena, "-m{s}-version-min={d}.{d}.{d}", .{
+ @tagName(target.os.tag), ver.major, ver.minor, ver.patch,
+ }));
+ },
+ },
+ else => {},
}
if (!comp.bin_file.options.strip) {