Skip to content

Commit 35b1e75

Browse files
committed
remove special darwin os version min handling
now it is integrated with zig's target OS range.
1 parent ded005c commit 35b1e75

15 files changed

+95
-226
lines changed

lib/std/target.zig

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ pub const Target = struct {
147147
.cloudabi,
148148
.dragonfly,
149149
.fuchsia,
150-
.ios,
151150
.kfreebsd,
152151
.lv2,
153152
.solaris,
@@ -162,8 +161,6 @@ pub const Target = struct {
162161
.amdhsa,
163162
.ps4,
164163
.elfiamcu,
165-
.tvos,
166-
.watchos,
167164
.mesa3d,
168165
.contiki,
169166
.amdpal,
@@ -187,6 +184,24 @@ pub const Target = struct {
187184
.max = .{ .major = 10, .minor = 15, .patch = 3 },
188185
},
189186
},
187+
.ios => return .{
188+
.semver = .{
189+
.min = .{ .major = 12, .minor = 0 },
190+
.max = .{ .major = 13, .minor = 4, .patch = 0 },
191+
},
192+
},
193+
.watchos => return .{
194+
.semver = .{
195+
.min = .{ .major = 6, .minor = 0 },
196+
.max = .{ .major = 6, .minor = 2, .patch = 0 },
197+
},
198+
},
199+
.tvos => return .{
200+
.semver = .{
201+
.min = .{ .major = 13, .minor = 0 },
202+
.max = .{ .major = 13, .minor = 4, .patch = 0 },
203+
},
204+
},
190205
.netbsd => return .{
191206
.semver = .{
192207
.min = .{ .major = 8, .minor = 0 },

lib/std/zig/cross_target.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ pub const CrossTarget = struct {
8888
.cloudabi,
8989
.dragonfly,
9090
.fuchsia,
91-
.ios,
9291
.kfreebsd,
9392
.lv2,
9493
.solaris,
@@ -103,8 +102,6 @@ pub const CrossTarget = struct {
103102
.amdhsa,
104103
.ps4,
105104
.elfiamcu,
106-
.tvos,
107-
.watchos,
108105
.mesa3d,
109106
.contiki,
110107
.amdpal,
@@ -121,8 +118,11 @@ pub const CrossTarget = struct {
121118

122119
.freebsd,
123120
.macosx,
121+
.ios,
124122
.netbsd,
125123
.openbsd,
124+
.tvos,
125+
.watchos,
126126
=> {
127127
self.os_version_min = .{ .semver = os.version_range.semver.min };
128128
self.os_version_max = .{ .semver = os.version_range.semver.max };

src-self-hosted/stage2.zig

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ const Stage2Target = extern struct {
892892

893893
is_native: bool,
894894

895-
glibc_version: ?*Stage2GLibCVersion, // null means default
895+
glibc_or_darwin_version: ?*Stage2SemVer,
896896

897897
llvm_cpu_name: ?[*:0]const u8,
898898
llvm_cpu_features: ?[*:0]const u8,
@@ -1103,16 +1103,29 @@ const Stage2Target = extern struct {
11031103
os_builtin_str_buffer.toSlice()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()],
11041104
);
11051105

1106-
const glibc_version = if (target.isGnuLibC()) blk: {
1107-
const stage1_glibc = try std.heap.c_allocator.create(Stage2GLibCVersion);
1108-
const stage2_glibc = target.os.version_range.linux.glibc;
1109-
stage1_glibc.* = .{
1110-
.major = stage2_glibc.major,
1111-
.minor = stage2_glibc.minor,
1112-
.patch = stage2_glibc.patch,
1113-
};
1114-
break :blk stage1_glibc;
1115-
} else null;
1106+
const glibc_or_darwin_version = blk: {
1107+
if (target.isGnuLibC()) {
1108+
const stage1_glibc = try std.heap.c_allocator.create(Stage2SemVer);
1109+
const stage2_glibc = target.os.version_range.linux.glibc;
1110+
stage1_glibc.* = .{
1111+
.major = stage2_glibc.major,
1112+
.minor = stage2_glibc.minor,
1113+
.patch = stage2_glibc.patch,
1114+
};
1115+
break :blk stage1_glibc;
1116+
} else if (target.isDarwin()) {
1117+
const stage1_semver = try std.heap.c_allocator.create(Stage2SemVer);
1118+
const stage2_semver = target.os.version_range.semver.min;
1119+
stage1_semver.* = .{
1120+
.major = stage2_semver.major,
1121+
.minor = stage2_semver.minor,
1122+
.patch = stage2_semver.patch,
1123+
};
1124+
break :blk stage1_semver;
1125+
} else {
1126+
break :blk null;
1127+
}
1128+
};
11161129

11171130
self.* = .{
11181131
.arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch
@@ -1125,7 +1138,7 @@ const Stage2Target = extern struct {
11251138
.os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr,
11261139
.cache_hash = cache_hash.toOwnedSlice().ptr,
11271140
.is_native = cross_target.isNative(),
1128-
.glibc_version = glibc_version,
1141+
.glibc_or_darwin_version = glibc_or_darwin_version,
11291142
.dynamic_linker = dynamic_linker,
11301143
};
11311144
}
@@ -1179,7 +1192,7 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8)
11791192
}
11801193

11811194
// ABI warning
1182-
const Stage2GLibCVersion = extern struct {
1195+
const Stage2SemVer = extern struct {
11831196
major: u32,
11841197
minor: u32,
11851198
patch: u32,

src/all_types.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,8 +2250,6 @@ struct CodeGen {
22502250
bool test_is_evented;
22512251
CodeModel code_model;
22522252

2253-
Buf *mmacosx_version_min;
2254-
Buf *mios_version_min;
22552253
Buf *root_out_name;
22562254
Buf *test_filter;
22572255
Buf *test_name_prefix;

src/codegen.cpp

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,6 @@ enum ResumeId {
3232
ResumeIdCall,
3333
};
3434

35-
static void init_darwin_native(CodeGen *g) {
36-
char *osx_target = getenv("MACOSX_DEPLOYMENT_TARGET");
37-
char *ios_target = getenv("IPHONEOS_DEPLOYMENT_TARGET");
38-
39-
// Allow conflicts among OSX and iOS, but choose the default platform.
40-
if (osx_target && ios_target) {
41-
if (g->zig_target->arch == ZigLLVM_arm ||
42-
g->zig_target->arch == ZigLLVM_aarch64 ||
43-
g->zig_target->arch == ZigLLVM_thumb)
44-
{
45-
osx_target = nullptr;
46-
} else {
47-
ios_target = nullptr;
48-
}
49-
}
50-
51-
if (osx_target) {
52-
g->mmacosx_version_min = buf_create_from_str(osx_target);
53-
} else if (ios_target) {
54-
g->mios_version_min = buf_create_from_str(ios_target);
55-
} else if (g->zig_target->os != OsIOS) {
56-
g->mmacosx_version_min = buf_create_from_str("10.14");
57-
}
58-
}
59-
6035
static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path, const char *pkg_path) {
6136
ZigPackage *entry = heap::c_allocator.create<ZigPackage>();
6237
entry->package_table.init(4);
@@ -160,14 +135,6 @@ void codegen_add_framework(CodeGen *g, const char *framework) {
160135
g->darwin_frameworks.append(buf_create_from_str(framework));
161136
}
162137

163-
void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) {
164-
g->mmacosx_version_min = mmacosx_version_min;
165-
}
166-
167-
void codegen_set_mios_version_min(CodeGen *g, Buf *mios_version_min) {
168-
g->mios_version_min = mios_version_min;
169-
}
170-
171138
void codegen_set_rdynamic(CodeGen *g, bool rdynamic) {
172139
g->linker_rdynamic = rdynamic;
173140
}
@@ -8655,10 +8622,10 @@ static Error define_builtin_compile_vars(CodeGen *g) {
86558622
if (g->zig_target->cache_hash != nullptr) {
86568623
cache_str(&cache_hash, g->zig_target->cache_hash);
86578624
}
8658-
if (g->zig_target->glibc_version != nullptr) {
8659-
cache_int(&cache_hash, g->zig_target->glibc_version->major);
8660-
cache_int(&cache_hash, g->zig_target->glibc_version->minor);
8661-
cache_int(&cache_hash, g->zig_target->glibc_version->patch);
8625+
if (g->zig_target->glibc_or_darwin_version != nullptr) {
8626+
cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->major);
8627+
cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->minor);
8628+
cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->patch);
86628629
}
86638630
cache_bool(&cache_hash, g->have_err_ret_tracing);
86648631
cache_bool(&cache_hash, g->libc_link_lib != nullptr);
@@ -10313,10 +10280,10 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1031310280
if (g->zig_target->cache_hash != nullptr) {
1031410281
cache_str(ch, g->zig_target->cache_hash);
1031510282
}
10316-
if (g->zig_target->glibc_version != nullptr) {
10317-
cache_int(ch, g->zig_target->glibc_version->major);
10318-
cache_int(ch, g->zig_target->glibc_version->minor);
10319-
cache_int(ch, g->zig_target->glibc_version->patch);
10283+
if (g->zig_target->glibc_or_darwin_version != nullptr) {
10284+
cache_int(ch, g->zig_target->glibc_or_darwin_version->major);
10285+
cache_int(ch, g->zig_target->glibc_or_darwin_version->minor);
10286+
cache_int(ch, g->zig_target->glibc_or_darwin_version->patch);
1032010287
}
1032110288
cache_int(ch, detect_subsystem(g));
1032210289
cache_bool(ch, g->strip_debug_symbols);
@@ -10344,8 +10311,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1034410311
cache_bool(ch, g->emit_bin);
1034510312
cache_bool(ch, g->emit_llvm_ir);
1034610313
cache_bool(ch, g->emit_asm);
10347-
cache_buf_opt(ch, g->mmacosx_version_min);
10348-
cache_buf_opt(ch, g->mios_version_min);
1034910314
cache_usize(ch, g->version_major);
1035010315
cache_usize(ch, g->version_minor);
1035110316
cache_usize(ch, g->version_patch);
@@ -10662,9 +10627,6 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o
1066210627

1066310628
codegen_set_errmsg_color(child_gen, parent_gen->err_color);
1066410629

10665-
codegen_set_mmacosx_version_min(child_gen, parent_gen->mmacosx_version_min);
10666-
codegen_set_mios_version_min(child_gen, parent_gen->mios_version_min);
10667-
1066810630
child_gen->enable_cache = true;
1066910631

1067010632
return child_gen;
@@ -10772,11 +10734,6 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
1077210734
g->each_lib_rpath = false;
1077310735
} else {
1077410736
g->each_lib_rpath = true;
10775-
10776-
if (target_os_is_darwin(g->zig_target->os)) {
10777-
init_darwin_native(g);
10778-
}
10779-
1078010737
}
1078110738

1078210739
if (target_os_requires_libc(g->zig_target->os)) {

src/codegen.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);
3535
void codegen_add_framework(CodeGen *codegen, const char *name);
3636
void codegen_add_rpath(CodeGen *codegen, const char *name);
3737
void codegen_set_rdynamic(CodeGen *g, bool rdynamic);
38-
void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min);
39-
void codegen_set_mios_version_min(CodeGen *g, Buf *mios_version_min);
4038
void codegen_set_linker_script(CodeGen *g, const char *linker_script);
4139
void codegen_set_test_filter(CodeGen *g, Buf *filter);
4240
void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);

src/glibc.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
5555
Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
5656
if (!opt_component.is_some) break;
5757
Buf *ver_buf = buf_create_from_slice(opt_component.value);
58-
ZigGLibCVersion *this_ver = glibc_abi->all_versions.add_one();
58+
Stage2SemVer *this_ver = glibc_abi->all_versions.add_one();
5959
if ((err = target_parse_glibc_version(this_ver, buf_ptr(ver_buf)))) {
6060
if (verbose) {
6161
fprintf(stderr, "Unable to parse glibc version '%s': %s\n", buf_ptr(ver_buf), err_str(err));
@@ -186,9 +186,9 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
186186
cache_buf(cache_hash, compiler_id);
187187
cache_int(cache_hash, target->arch);
188188
cache_int(cache_hash, target->abi);
189-
cache_int(cache_hash, target->glibc_version->major);
190-
cache_int(cache_hash, target->glibc_version->minor);
191-
cache_int(cache_hash, target->glibc_version->patch);
189+
cache_int(cache_hash, target->glibc_or_darwin_version->major);
190+
cache_int(cache_hash, target->glibc_or_darwin_version->minor);
191+
cache_int(cache_hash, target->glibc_or_darwin_version->patch);
192192

193193
Buf digest = BUF_INIT;
194194
buf_resize(&digest, 0);
@@ -224,20 +224,20 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
224224

225225
uint8_t target_ver_index = 0;
226226
for (;target_ver_index < glibc_abi->all_versions.length; target_ver_index += 1) {
227-
const ZigGLibCVersion *this_ver = &glibc_abi->all_versions.at(target_ver_index);
228-
if (this_ver->major == target->glibc_version->major &&
229-
this_ver->minor == target->glibc_version->minor &&
230-
this_ver->patch == target->glibc_version->patch)
227+
const Stage2SemVer *this_ver = &glibc_abi->all_versions.at(target_ver_index);
228+
if (this_ver->major == target->glibc_or_darwin_version->major &&
229+
this_ver->minor == target->glibc_or_darwin_version->minor &&
230+
this_ver->patch == target->glibc_or_darwin_version->patch)
231231
{
232232
break;
233233
}
234234
}
235235
if (target_ver_index == glibc_abi->all_versions.length) {
236236
if (verbose) {
237237
fprintf(stderr, "Unrecognized glibc version: %d.%d.%d\n",
238-
target->glibc_version->major,
239-
target->glibc_version->minor,
240-
target->glibc_version->patch);
238+
target->glibc_or_darwin_version->major,
239+
target->glibc_or_darwin_version->minor,
240+
target->glibc_or_darwin_version->patch);
241241
}
242242
return ErrorUnknownABI;
243243
}
@@ -246,7 +246,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
246246
Buf *map_contents = buf_alloc();
247247

248248
for (uint8_t ver_i = 0; ver_i < glibc_abi->all_versions.length; ver_i += 1) {
249-
const ZigGLibCVersion *ver = &glibc_abi->all_versions.at(ver_i);
249+
const Stage2SemVer *ver = &glibc_abi->all_versions.at(ver_i);
250250
if (ver->patch == 0) {
251251
buf_appendf(map_contents, "GLIBC_%d.%d { };\n", ver->major, ver->minor);
252252
} else {
@@ -294,7 +294,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
294294
uint8_t ver_index = ver_list->versions[ver_i];
295295

296296
Buf *stub_name;
297-
const ZigGLibCVersion *ver = &glibc_abi->all_versions.at(ver_index);
297+
const Stage2SemVer *ver = &glibc_abi->all_versions.at(ver_index);
298298
const char *sym_name = buf_ptr(libc_fn->name);
299299
if (ver->patch == 0) {
300300
stub_name = buf_sprintf("%s_%d_%d", sym_name, ver->major, ver->minor);

src/glibc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct ZigGLibCAbi {
3232
Buf *abi_txt_path;
3333
Buf *vers_txt_path;
3434
Buf *fns_txt_path;
35-
ZigList<ZigGLibCVersion> all_versions;
35+
ZigList<Stage2SemVer> all_versions;
3636
ZigList<ZigGLibCFn> all_functions;
3737
// The value is a pointer to all_functions.length items and each item is an index
3838
// into all_functions.

0 commit comments

Comments
 (0)