Skip to content

Commit ebc7d6f

Browse files
Update sysroot variables
1 parent fe960bb commit ebc7d6f

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,29 @@ jobs:
4949
with:
5050
dotnet-version: 8.0.x
5151

52+
- name: Setup Android SDK
53+
uses: android-actions/setup-android@v3
54+
5255
- name: Set Version Suffix
5356
shell: bash
5457
run: |
5558
if [ '${{ github.event.inputs.use-auto-generated-version }}' != 'false' ]; then
5659
echo "BuildVersionSuffix=build.$(git rev-list --count HEAD)" >> $GITHUB_ENV
5760
fi
5861
59-
- name: Setup IOS SDK
62+
- name: Set IOS SDK Variables
6063
if: matrix.os == 'macos-latest'
6164
shell: bash
6265
run: |
63-
echo "IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)" >> $GITHUB_ENV
64-
echo "IOS_SIMULATOR_SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)" >> $GITHUB_ENV
65-
66-
- name: Setup Android NDK
67-
if: matrix.os == 'macos-latest'
68-
uses: nttld/setup-ndk@v1
69-
with:
70-
ndk-version: r25c
71-
link-to-sdk: true
66+
echo "IOS_SDK_SYSROOT=$(xcrun --sdk iphoneos --show-sdk-path)" >> $GITHUB_ENV
67+
echo "IOS_SIMULATOR_SDK_SYSROOT=$(xcrun --sdk iphonesimulator --show-sdk-path)" >> $GITHUB_ENV
7268
73-
- name: Set Android NDK variables
69+
- name: Set Android NDK Variables
7470
if: matrix.os == 'macos-latest'
7571
shell: bash
7672
run: |
77-
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
73+
echo "ANDROID_NDK=$(find "$ANDROID_SDK_ROOT/ndk/" -mindepth 1 -maxdepth 1 -type d | sort | head -n 1)" >> $GITHUB_ENV
74+
echo "ANDROID_NDK_SYSROOT=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64/sysroot" >> $GITHUB_ENV
7875
7976
- name: Restore Dependencies
8077
shell: bash

Box2D.NET.Native/Box2D.NET.Native.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<Import Project="$(NuGetPackageRoot)/microsoft.net.runtime.emscripten.3.1.56.cache.$(HostRuntime)/9.0.5/Sdk/Sdk.props"/>
5252

5353
<PropertyGroup>
54-
<EMSCRIPTEN_CACHE Condition="$(EMSCRIPTEN_CACHE) == ''" >$(WasmCachePath)</EMSCRIPTEN_CACHE>
54+
<EMSCRIPTEN_CACHE_SYSROOT Condition="$(EMSCRIPTEN_CACHE_SYSROOT) == ''" >$(WasmCachePath)sysroot</EMSCRIPTEN_CACHE_SYSROOT>
5555
</PropertyGroup>
5656

5757
<!-- Determine mapping between dotnet RID and zig targets -->
@@ -109,37 +109,37 @@
109109
<When Condition="$(RuntimeIdentifier) == 'iossimulator-x64'">
110110
<PropertyGroup>
111111
<ZigIdentifier>x86_64-ios-simulator</ZigIdentifier>
112-
<ZigArgs>--sysroot "$(IOS_SIMULATOR_SDK)"</ZigArgs>
112+
<ZigArgs>-Dsysroot="$(IOS_SIMULATOR_SDK_SYSROOT)"</ZigArgs>
113113
</PropertyGroup>
114114
</When>
115115
<When Condition="$(RuntimeIdentifier) == 'iossimulator-arm64'">
116116
<PropertyGroup>
117117
<ZigIdentifier>aarch64-ios-simulator</ZigIdentifier>
118-
<ZigArgs>--sysroot "$(IOS_SIMULATOR_SDK)"</ZigArgs>
118+
<ZigArgs>-Dsysroot="$(IOS_SIMULATOR_SDK_SYSROOT)"</ZigArgs>
119119
</PropertyGroup>
120120
</When>
121121
<When Condition="$(RuntimeIdentifier) == 'ios-arm64'">
122122
<PropertyGroup>
123123
<ZigIdentifier>aarch64-ios</ZigIdentifier>
124-
<ZigArgs>--sysroot "$(IOS_SDK)"</ZigArgs>
124+
<ZigArgs>-Dsysroot="$(IOS_SDK_SYSROOT)"</ZigArgs>
125125
</PropertyGroup>
126126
</When>
127127
<When Condition="$(RuntimeIdentifier) == 'browser-wasm'">
128128
<PropertyGroup>
129129
<ZigIdentifier>wasm32-emscripten</ZigIdentifier>
130-
<ZigArgs>--sysroot "$(EMSCRIPTEN_CACHE)"</ZigArgs>
130+
<ZigArgs>-Dsysroot="$(EMSCRIPTEN_CACHE_SYSROOT)"</ZigArgs>
131131
</PropertyGroup>
132132
</When>
133133
<When Condition="$(RuntimeIdentifier) == 'android-arm64'">
134134
<PropertyGroup>
135-
<ZigIdentifier>aarch64-linux-android</ZigIdentifier>
136-
<ZigArgs>--sysroot "$(ANDROID_NDK_HOME)"</ZigArgs>
135+
<ZigIdentifier>aarch64-linux-android.21</ZigIdentifier>
136+
<ZigArgs>-Dsysroot="$(ANDROID_NDK_SYSROOT)"</ZigArgs>
137137
</PropertyGroup>
138138
</When>
139139
<When Condition="$(RuntimeIdentifier) == 'android-x64'">
140140
<PropertyGroup>
141-
<ZigIdentifier>x86_64-linux-android</ZigIdentifier>
142-
<ZigArgs>--sysroot "$(ANDROID_NDK_HOME)"</ZigArgs>
141+
<ZigIdentifier>x86_64-linux-android.21</ZigIdentifier>
142+
<ZigArgs>-Dsysroot="$(ANDROID_NDK_SYSROOT)"</ZigArgs>
143143
</PropertyGroup>
144144
</When>
145145
<Otherwise>
@@ -152,7 +152,7 @@
152152
<!-- All the native code compile magic lives here -->
153153
<Target Name="CompileNatives" AfterTargets="Build" Condition="'$(SkipNatives)' != 'true'">
154154
<PropertyGroup>
155-
<BuildCommand>$(ZigExePath) build -Dcompiler-rt-path="$(ZigLibPath)compiler_rt.zig" -Doptimize=$(ZigConfiguration) --prefix $(OutputPath)runtimes --prefix-lib-dir $(RuntimeIdentifier)/native --prefix-exe-dir $(RuntimeIdentifier)/native -Dtarget=$(ZigIdentifier) $(ZigArgs)</BuildCommand>
155+
<BuildCommand>$(ZigExePath) build -Doptimize=$(ZigConfiguration) --prefix $(OutputPath)runtimes --prefix-lib-dir $(RuntimeIdentifier)/native --prefix-exe-dir $(RuntimeIdentifier)/native -Dtarget=$(ZigIdentifier) -Dcompiler-rt-path="$(ZigLibPath)compiler_rt.zig" $(ZigArgs)</BuildCommand>
156156
</PropertyGroup>
157157
<Message Importance="High" Text="Build Target: $(RuntimeIdentifier) $(Configuration)"/>
158158
<Message Importance="High" Text="Build Zig Target: $(ZigIdentifier) $(ZigConfiguration)"/>

Box2D.NET.Native/build.zig

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const BuildOptions = struct {
88
optimize: std.builtin.OptimizeMode,
99
target: Build.ResolvedTarget,
1010
library_type: LibraryType,
11+
// There are some issues with path lookups when using --sysroot. Pass as a build option instead.
12+
sysroot: ?[]const u8,
13+
// When building static libraries for Windows, zig's compiler-rt needs to be bundled.
14+
// For some reason, setting "bundle_compiler_rt" to true doesn't produce a static library that works with NativeAOT.
15+
// As a work-around, we manually build the compiler_rt.zig file.
1116
compiler_rt_path: ?[]const u8,
1217
};
1318

@@ -75,45 +80,38 @@ pub fn compile(b: *Build, options: BuildOptions) !void {
7580
}
7681
},
7782
.ios => {
78-
if (b.sysroot == null or b.sysroot.?.len == 0) {
83+
if (options.sysroot == null or options.sysroot.?.len == 0) {
7984
@panic("A --sysroot path to an IOS SDK needs to be provided when compiling for IOS.");
8085
}
8186

82-
lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/System/Library/Frameworks" }) });
83-
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/usr/include" }) });
84-
lib.addLibraryPath(.{ .cwd_relative = "/usr/lib" });
87+
lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ options.sysroot.?, "/System/Library/Frameworks" }) });
88+
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ options.sysroot.?, "/usr/include" }) });
89+
lib.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ options.sysroot.?, "/usr/lib" }) });
8590
},
8691
.emscripten => {
87-
if (b.sysroot == null or b.sysroot.?.len == 0) {
92+
if (options.sysroot == null or options.sysroot.?.len == 0) {
8893
@panic("A --sysroot path to an emscripten cache needs to be provided when compiling for wasm.");
8994
}
9095

91-
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/sysroot/include" }) });
96+
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ options.sysroot.?, "/sysroot/include" }) });
9297
},
9398
.linux => {
9499
if (options.target.result.abi == .android) {
95-
if (b.sysroot == null or b.sysroot.?.len == 0) {
100+
if (options.sysroot == null or options.sysroot.?.len == 0) {
96101
@panic("A --sysroot path to an Android NDK needs to be provided when compiling for Android.");
97102
}
98103

99-
const host_tuple = switch (builtin.target.os.tag) {
100-
.linux => "linux-x86_64",
101-
.windows => "windows-x86_64",
102-
.macos => "darwin-x86_64",
103-
else => @panic("unsupported host OS"),
104-
};
105-
106104
const triple = switch (options.target.result.cpu.arch) {
107105
.aarch64 => "aarch64-linux-android",
108106
.x86_64 => "x86_64-linux-android",
109107
else => @panic("Unsupported Android architecture"),
110108
};
109+
111110
const android_api_level: []const u8 = "21";
112111

113-
const android_sysroot = b.pathJoin(&.{ b.sysroot.?, "/toolchains/llvm/prebuilt/", host_tuple, "/sysroot" });
114-
const android_lib_path = b.pathJoin(&.{ "/usr/lib/", triple, android_api_level });
115-
const android_include_path = b.pathJoin(&.{ android_sysroot, "/usr/include" });
116-
const android_system_include_path = b.pathJoin(&.{ android_sysroot, "/usr/include/", triple });
112+
const android_lib_path = b.pathJoin(&.{ options.sysroot.?, "/usr/lib/", triple, android_api_level });
113+
const android_include_path = b.pathJoin(&.{ options.sysroot.?, "/usr/include" });
114+
const android_system_include_path = b.pathJoin(&.{ options.sysroot.?, "/usr/include/", triple });
117115

118116
lib.addLibraryPath(.{ .cwd_relative = android_lib_path });
119117

@@ -145,9 +143,7 @@ pub fn build(b: *Build) !void {
145143
.optimize = b.standardOptimizeOption(.{}),
146144
.target = b.standardTargetOptions(.{}),
147145
.library_type = b.option(LibraryType, "library-type", "Compile as a static or shared library.") orelse LibraryType.Shared,
148-
// When building static libraries for Windows, zig's compiler-rt needs to be bundled.
149-
// For some reason, setting "bundle_compiler_rt" to true doesn't produce a static library that works with NativeAOT.
150-
// As a work-around, we manually build the compiler_rt.zig file.
146+
.sysroot = b.option([]const u8, "sysroot", "Path to sysroot.") orelse null,
151147
.compiler_rt_path = b.option([]const u8, "compiler-rt-path", "Path to the compiler_rt file.") orelse null,
152148
});
153149
}

0 commit comments

Comments
 (0)