authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-10 15:23:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-10 15:24:57-07:00
log0405698696acea924609ccd2e9c96064245f8df1
tree1ef61c5c4cd08bb2b74f87af6e9bc4ff8f769e46
parent73455eaf4277f84f6ea3c3180429d611aaa62264

add missing -m<os>-version-min CLI args to clang

This fixes some code generation issues when targeting macOS and compiling C/C++ code.

1 files changed, 35 insertions(+), 6 deletions(-)

src/Compilation.zig+35-6
......@@ -613,6 +613,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
613613 cache.hash.addBytes(options.target.cpu.model.name);
614614 cache.hash.add(options.target.cpu.features.ints);
615615 cache.hash.add(options.target.os.tag);
616 cache.hash.add(options.target.os.getVersionRange());
616617 cache.hash.add(options.is_native_os);
617618 cache.hash.add(options.target.abi);
618619 cache.hash.add(ofmt);
......@@ -642,7 +643,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
642643 hash.addOptionalBytes(root_pkg.root_src_directory.path);
643644 hash.add(valgrind);
644645 hash.add(single_threaded);
645 hash.add(options.target.os.getVersionRange());
646646 hash.add(dll_export_fns);
647647 hash.add(options.is_test);
648648 hash.add(options.is_compiler_rt_or_libc);
......@@ -1619,7 +1619,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
16191619 const out_dep_path: ?[]const u8 = if (comp.disable_c_depfile or !ext.clangSupportsDepFile())
16201620 null
16211621 else
1622 try std.fmt.allocPrint(arena, "{}.d", .{out_obj_path});
1622 try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path});
16231623 try comp.addCCArgs(arena, &argv, ext, out_dep_path);
16241624
16251625 try argv.ensureCapacity(argv.items.len + 3);
......@@ -1849,10 +1849,39 @@ pub fn addCCArgs(
18491849 try argv.append(try std.fmt.allocPrint(arena, "-mcmodel={}", .{@tagName(mcmodel)}));
18501850 }
18511851
1852 // windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning.
1853 // So for this target, we disable this warning.
1854 if (target.os.tag == .windows and target.abi.isGnu()) {
1855 try argv.append("-Wno-pragma-pack");
1852 switch (target.os.tag) {
1853 .windows => {
1854 // windows.h has files such as pshpack1.h which do #pragma packing,
1855 // triggering a clang warning. So for this target, we disable this warning.
1856 if (target.abi.isGnu()) {
1857 try argv.append("-Wno-pragma-pack");
1858 }
1859 },
1860 .macos => {
1861 // Pass the proper -m<os>-version-min argument for darwin.
1862 const ver = target.os.version_range.semver.min;
1863 try argv.append(try std.fmt.allocPrint(arena, "-mmacos-version-min={d}.{d}.{d}", .{
1864 ver.major, ver.minor, ver.patch,
1865 }));
1866 },
1867 .ios, .tvos, .watchos => switch (target.cpu.arch) {
1868 // Pass the proper -m<os>-version-min argument for darwin.
1869 .i386, .x86_64 => {
1870 const ver = target.os.version_range.semver.min;
1871 try argv.append(try std.fmt.allocPrint(
1872 arena,
1873 "-m{s}-simulator-version-min={d}.{d}.{d}",
1874 .{ @tagName(target.os.tag), ver.major, ver.minor, ver.patch },
1875 ));
1876 },
1877 else => {
1878 const ver = target.os.version_range.semver.min;
1879 try argv.append(try std.fmt.allocPrint(arena, "-m{s}-version-min={d}.{d}.{d}", .{
1880 @tagName(target.os.tag), ver.major, ver.minor, ver.patch,
1881 }));
1882 },
1883 },
1884 else => {},
18561885 }
18571886
18581887 if (!comp.bin_file.options.strip) {