Skip to content

Commit ebbc50d

Browse files
committed
std.Target: Introduce Abi.androideabi to distinguish the soft float case.
Abi.android on its own is not enough to know whether soft float or hard float should be used. In the C world, androideabi is typically used for the soft float case, so let's go with that. Note that Android doesn't have a hard float ABI, so no androideabihf. Closes #21488.
1 parent d3ba5f3 commit ebbc50d

File tree

10 files changed

+34
-22
lines changed

10 files changed

+34
-22
lines changed

lib/compiler/aro/aro/Compilation.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
308308
),
309309
else => {},
310310
}
311-
if (comp.target.abi == .android) {
311+
if (comp.target.isAndroid()) {
312312
try w.writeAll("#define __ANDROID__ 1\n");
313313
}
314314

lib/compiler/aro/aro/target.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
690690
.eabi => "eabi",
691691
.eabihf => "eabihf",
692692
.android => "android",
693+
.androideabi => "androideabi",
693694
.musl => "musl",
694695
.musleabi => "musleabi",
695696
.musleabihf => "musleabihf",

lib/compiler_rt/common.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub const want_aeabi = switch (builtin.abi) {
2222
.gnueabi,
2323
.gnueabihf,
2424
.android,
25+
.androideabi,
2526
=> switch (builtin.cpu.arch) {
2627
.arm, .armeb, .thumb, .thumbeb => true,
2728
else => false,

lib/compiler_rt/emutls.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const gcc_word = usize;
1818
pub const panic = common.panic;
1919

2020
comptime {
21-
if (builtin.link_libc and (builtin.abi == .android or builtin.os.tag == .openbsd)) {
21+
if (builtin.link_libc and (builtin.abi.isAndroid() or builtin.os.tag == .openbsd)) {
2222
@export(&__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage, .visibility = common.visibility });
2323
}
2424
}

lib/std/Target.zig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ pub const Abi = enum {
664664
eabihf,
665665
ilp32,
666666
android,
667+
androideabi,
667668
musl,
668669
musleabi,
669670
musleabihf,
@@ -770,8 +771,16 @@ pub const Abi = enum {
770771
};
771772
}
772773

774+
pub inline fn isAndroid(abi: Abi) bool {
775+
return switch (abi) {
776+
.android, .androideabi => true,
777+
else => false,
778+
};
779+
}
780+
773781
pub inline fn floatAbi(abi: Abi) FloatAbi {
774782
return switch (abi) {
783+
.androideabi,
775784
.eabi,
776785
.gnueabi,
777786
.musleabi,
@@ -1617,7 +1626,7 @@ pub inline fn isMusl(target: Target) bool {
16171626
}
16181627

16191628
pub inline fn isAndroid(target: Target) bool {
1620-
return target.abi == .android;
1629+
return target.abi.isAndroid();
16211630
}
16221631

16231632
pub inline fn isWasm(target: Target) bool {
@@ -1724,7 +1733,7 @@ pub const DynamicLinker = struct {
17241733
}
17251734

17261735
pub fn standard(cpu: Cpu, os_tag: Os.Tag, abi: Abi) DynamicLinker {
1727-
return if (abi == .android) initFmt("/system/bin/linker{s}", .{
1736+
return if (abi.isAndroid()) initFmt("/system/bin/linker{s}", .{
17281737
if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else "",
17291738
}) catch unreachable else if (abi.isMusl()) return initFmt("/lib/ld-musl-{s}{s}.so.1", .{
17301739
@tagName(switch (cpu.arch) {
@@ -2391,6 +2400,7 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
23912400
.eabi,
23922401
.eabihf,
23932402
.android,
2403+
.androideabi,
23942404
.musleabi,
23952405
.musleabihf,
23962406
=> 8,
@@ -2463,6 +2473,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
24632473
.eabi,
24642474
.eabihf,
24652475
.android,
2476+
.androideabi,
24662477
.musleabi,
24672478
.musleabihf,
24682479
=> {},

lib/std/Target/Query.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ pub fn canDetectLibC(self: Query) bool {
374374
if (self.isNativeOs()) return true;
375375
if (self.os_tag) |os| {
376376
if (builtin.os.tag == .macos and os.isDarwin()) return true;
377-
if (os == .linux and self.abi == .android) return true;
377+
if (os == .linux and self.abi.isAndroid()) return true;
378378
}
379379
return false;
380380
}

lib/std/c.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5946,7 +5946,7 @@ pub const PR = switch (native_os) {
59465946
};
59475947
pub const _errno = switch (native_os) {
59485948
.linux => switch (native_abi) {
5949-
.android => private.__errno,
5949+
.android, .androideabi => private.__errno,
59505950
else => private.__errno_location,
59515951
},
59525952
.emscripten => private.__errno_location,
@@ -6754,7 +6754,7 @@ pub const pthread_mutex_t = switch (native_os) {
67546754
.mips64, .powerpc64, .powerpc64le, .sparc64 => 40,
67556755
else => if (@sizeOf(usize) == 8) 40 else 24,
67566756
},
6757-
.android => if (@sizeOf(usize) == 8) 40 else 4,
6757+
.android, .androideabi => if (@sizeOf(usize) == 8) 40 else 4,
67586758
else => @compileError("unsupported ABI"),
67596759
};
67606760
},
@@ -6848,7 +6848,7 @@ pub const pthread_cond_t = switch (native_os) {
68486848

68496849
pub const pthread_rwlock_t = switch (native_os) {
68506850
.linux => switch (native_abi) {
6851-
.android => switch (@sizeOf(usize)) {
6851+
.android, .androideabi => switch (@sizeOf(usize)) {
68526852
4 => extern struct {
68536853
data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40,
68546854
},

lib/std/zig/LibCDirs.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 {
248248
.eabihf,
249249
.ilp32,
250250
.android,
251+
.androideabi,
251252
.msvc,
252253
.itanium,
253254
.cygnus,

src/codegen/llvm.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
172172
.eabi => "eabi",
173173
.eabihf => "eabihf",
174174
.android => "android",
175+
.androideabi => "androideabi",
175176
.musl => "musl",
176177
.musleabi => "musleabi",
177178
.musleabihf => "musleabihf",

src/target.zig

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,17 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
304304
"-lc",
305305
"-lnetwork",
306306
},
307-
else => switch (target.abi) {
308-
.android => &[_][]const u8{
309-
"-lm",
310-
"-lc",
311-
"-ldl",
312-
},
313-
else => &[_][]const u8{
314-
"-lm",
315-
"-lpthread",
316-
"-lc",
317-
"-ldl",
318-
"-lrt",
319-
"-lutil",
320-
},
307+
else => if (target.isAndroid()) &[_][]const u8{
308+
"-lm",
309+
"-lc",
310+
"-ldl",
311+
} else &[_][]const u8{
312+
"-lm",
313+
"-lpthread",
314+
"-lc",
315+
"-ldl",
316+
"-lrt",
317+
"-lutil",
321318
},
322319
};
323320
}

0 commit comments

Comments
 (0)