Skip to content

Commit ef70f51

Browse files
Update sysroot variables
1 parent fe960bb commit ef70f51

File tree

3 files changed

+44
-54
lines changed

3 files changed

+44
-54
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 18 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
@@ -104,9 +101,9 @@ jobs:
104101
dotnet build -c Debug -r win-x86
105102
dotnet build -c Debug -r win-arm64
106103
# dotnet build -c Debug -r browser-wasm
107-
# dotnet build -c Debug -r iossimulator-x64
108-
# dotnet build -c Debug -r iossimulator-arm64
109-
# dotnet build -c Debug -r ios-arm64
104+
dotnet build -c Debug -r iossimulator-x64
105+
dotnet build -c Debug -r iossimulator-arm64
106+
dotnet build -c Debug -r ios-arm64
110107
dotnet build -c Debug -r android-arm64
111108
dotnet build -c Debug -r android-x64
112109
@@ -119,9 +116,9 @@ jobs:
119116
dotnet build -c Release -r win-x86
120117
dotnet build -c Release -r win-arm64
121118
# dotnet build -c Release -r browser-wasm
122-
# dotnet build -c Release -r iossimulator-x64
123-
# dotnet build -c Release -r iossimulator-arm64
124-
# dotnet build -c Release -r ios-arm64
119+
dotnet build -c Release -r iossimulator-x64
120+
dotnet build -c Release -r iossimulator-arm64
121+
dotnet build -c Release -r ios-arm64
125122
dotnet build -c Release -r android-arm64
126123
dotnet build -c Release -r android-x64
127124

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@
3434
<None Pack="true" Include="buildTransitive/Box2D.NET.Native.props" PackagePath="buildTransitive/$(PackageId).props"/>
3535
<None Pack="true" Include="buildTransitive/Box2D.NET.Native.targets" PackagePath="buildTransitive/$(PackageId).targets"/>
3636
<None Pack="true" Include="$(OutputPath)runtimes/**/*.a;$(OutputPath)runtimes/**/*.lib" PackagePath="static/"/>
37-
38-
<Content Include="$(OutputPath)runtimes/**/**" Exclude="$(OutputPath)runtimes/**/*.a;$(OutputPath)runtimes/**/*.lib" Link="%(Filename)%(Extension)">
39-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40-
<PackagePath>runtimes/</PackagePath>
41-
</Content>
37+
<None Pack="true" Include="$(OutputPath)runtimes/**/**" Exclude="$(OutputPath)runtimes/**/*.a;$(OutputPath)runtimes/**/*.lib" PackagePath="runtimes/"/>
38+
<None Include="$(OutputPath)runtimes/$(HostRuntime)/**" Exclude="$(OutputPath)runtimes/**/*.a;$(OutputPath)runtimes/**/*.lib" Link="%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest"/>
4239
</ItemGroup>
4340

4441
<!-- Here we need host not target toolset to compile/cross-compile -->
@@ -51,7 +48,7 @@
5148
<Import Project="$(NuGetPackageRoot)/microsoft.net.runtime.emscripten.3.1.56.cache.$(HostRuntime)/9.0.5/Sdk/Sdk.props"/>
5249

5350
<PropertyGroup>
54-
<EMSCRIPTEN_CACHE Condition="$(EMSCRIPTEN_CACHE) == ''" >$(WasmCachePath)</EMSCRIPTEN_CACHE>
51+
<EMSCRIPTEN_CACHE_SYSROOT Condition="$(EMSCRIPTEN_CACHE_SYSROOT) == ''" >$(WasmCachePath)sysroot</EMSCRIPTEN_CACHE_SYSROOT>
5552
</PropertyGroup>
5653

5754
<!-- Determine mapping between dotnet RID and zig targets -->
@@ -109,37 +106,37 @@
109106
<When Condition="$(RuntimeIdentifier) == 'iossimulator-x64'">
110107
<PropertyGroup>
111108
<ZigIdentifier>x86_64-ios-simulator</ZigIdentifier>
112-
<ZigArgs>--sysroot "$(IOS_SIMULATOR_SDK)"</ZigArgs>
109+
<ZigArgs>-Dsysroot="$(IOS_SIMULATOR_SDK_SYSROOT)"</ZigArgs>
113110
</PropertyGroup>
114111
</When>
115112
<When Condition="$(RuntimeIdentifier) == 'iossimulator-arm64'">
116113
<PropertyGroup>
117114
<ZigIdentifier>aarch64-ios-simulator</ZigIdentifier>
118-
<ZigArgs>--sysroot "$(IOS_SIMULATOR_SDK)"</ZigArgs>
115+
<ZigArgs>-Dsysroot="$(IOS_SIMULATOR_SDK_SYSROOT)"</ZigArgs>
119116
</PropertyGroup>
120117
</When>
121118
<When Condition="$(RuntimeIdentifier) == 'ios-arm64'">
122119
<PropertyGroup>
123120
<ZigIdentifier>aarch64-ios</ZigIdentifier>
124-
<ZigArgs>--sysroot "$(IOS_SDK)"</ZigArgs>
121+
<ZigArgs>-Dsysroot="$(IOS_SDK_SYSROOT)"</ZigArgs>
125122
</PropertyGroup>
126123
</When>
127124
<When Condition="$(RuntimeIdentifier) == 'browser-wasm'">
128125
<PropertyGroup>
129126
<ZigIdentifier>wasm32-emscripten</ZigIdentifier>
130-
<ZigArgs>--sysroot "$(EMSCRIPTEN_CACHE)"</ZigArgs>
127+
<ZigArgs>-Dsysroot="$(EMSCRIPTEN_CACHE_SYSROOT)"</ZigArgs>
131128
</PropertyGroup>
132129
</When>
133130
<When Condition="$(RuntimeIdentifier) == 'android-arm64'">
134131
<PropertyGroup>
135-
<ZigIdentifier>aarch64-linux-android</ZigIdentifier>
136-
<ZigArgs>--sysroot "$(ANDROID_NDK_HOME)"</ZigArgs>
132+
<ZigIdentifier>aarch64-linux-android.21</ZigIdentifier>
133+
<ZigArgs>-Dsysroot="$(ANDROID_NDK_SYSROOT)"</ZigArgs>
137134
</PropertyGroup>
138135
</When>
139136
<When Condition="$(RuntimeIdentifier) == 'android-x64'">
140137
<PropertyGroup>
141-
<ZigIdentifier>x86_64-linux-android</ZigIdentifier>
142-
<ZigArgs>--sysroot "$(ANDROID_NDK_HOME)"</ZigArgs>
138+
<ZigIdentifier>x86_64-linux-android.21</ZigIdentifier>
139+
<ZigArgs>-Dsysroot="$(ANDROID_NDK_SYSROOT)"</ZigArgs>
143140
</PropertyGroup>
144141
</When>
145142
<Otherwise>
@@ -152,7 +149,7 @@
152149
<!-- All the native code compile magic lives here -->
153150
<Target Name="CompileNatives" AfterTargets="Build" Condition="'$(SkipNatives)' != 'true'">
154151
<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>
152+
<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>
156153
</PropertyGroup>
157154
<Message Importance="High" Text="Build Target: $(RuntimeIdentifier) $(Configuration)"/>
158155
<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.?, "/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)