Skip to content

Commit 835f558

Browse files
Import emscripten cache nuget package, build for x86 platforms
1 parent a7ca459 commit 835f558

File tree

3 files changed

+36
-50
lines changed

3 files changed

+36
-50
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
os: [ubuntu-latest, macos-13, windows-latest]
39+
os: [ubuntu-latest, macos-latest, windows-latest]
4040

4141
steps:
4242
- uses: actions/checkout@v4
@@ -57,7 +57,7 @@ jobs:
5757
fi
5858
5959
- name: Setup IOS SDK
60-
if: matrix.os == 'macos-13'
60+
if: matrix.os == 'macos-latest'
6161
shell: bash
6262
run: |
6363
IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
@@ -66,21 +66,15 @@ jobs:
6666
echo "IOS_SDK=$IOS_SDK" >> $GITHUB_ENV
6767
echo "IOS_SIMULATOR_SDK=$IOS_SIMULATOR_SDK" >> $GITHUB_ENV
6868
69-
- name: Setup Emscripten SDK
70-
if: matrix.os == 'macos-13'
71-
uses: mymindstorm/setup-emsdk@v14
72-
with:
73-
actions-cache-folder: 'emsdk-cache'
74-
7569
- name: Setup Android NDK
76-
if: matrix.os == 'macos-13'
70+
if: matrix.os == 'macos-latest'
7771
uses: nttld/setup-ndk@v1
7872
with:
7973
ndk-version: r25c
8074
link-to-sdk: true
8175

8276
- name: Set Android NDK variables
83-
if: matrix.os == 'macos-13'
77+
if: matrix.os == 'macos-latest'
8478
shell: bash
8579
run: |
8680
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
@@ -101,29 +95,31 @@ jobs:
10195
10296
- name: Build Natives
10397
shell: bash
104-
if: matrix.os == 'macos-13'
98+
if: matrix.os == 'macos-latest'
10599
working-directory: Box2D.NET.Native
106100
run: |
107101
dotnet build -c Debug -r linux-x64
102+
dotnet build -c Debug -r linux-x86
108103
dotnet build -c Debug -r linux-arm64
109104
dotnet build -c Debug -r osx-x64
110105
dotnet build -c Debug -r osx-arm64
111106
dotnet build -c Debug -r win-x64
107+
dotnet build -c Debug -r win-x86
112108
dotnet build -c Debug -r win-arm64
113-
dotnet build -c Debug -r browser-wasm
114109
dotnet build -c Debug -r iossimulator-x64
115110
dotnet build -c Debug -r iossimulator-arm64
116111
dotnet build -c Debug -r ios-arm64
117112
dotnet build -c Debug -r android-arm64
118113
dotnet build -c Debug -r android-x64
119114
120115
dotnet build -c Release -r linux-x64
116+
dotnet build -c Release -r linux-x86
121117
dotnet build -c Release -r linux-arm64
122118
dotnet build -c Release -r osx-x64
123119
dotnet build -c Release -r osx-arm64
124120
dotnet build -c Release -r win-x64
121+
dotnet build -c Release -r win-x86
125122
dotnet build -c Release -r win-arm64
126-
dotnet build -c Release -r browser-wasm
127123
dotnet build -c Release -r iossimulator-x64
128124
dotnet build -c Release -r iossimulator-arm64
129125
dotnet build -c Release -r ios-arm64
@@ -148,7 +144,7 @@ jobs:
148144
fi
149145
150146
- name: Upload Artifacts
151-
if: matrix.os == 'macos-13'
147+
if: matrix.os == 'macos-latest'
152148
uses: actions/upload-artifact@v4
153149
with:
154150
name: Nuget Packages
@@ -158,7 +154,7 @@ jobs:
158154
159155
- name: Push NuGet Packages
160156
if: >
161-
matrix.os == 'macos-13' &&
157+
matrix.os == 'macos-latest' &&
162158
github.repository_owner == 'BeanCheeseBurrito' &&
163159
(
164160
(github.event_name == 'workflow_dispatch' && github.event.inputs.push-packages == 'true') ||

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@
4141
</Content>
4242
</ItemGroup>
4343

44+
<!-- Here we need host not target toolset to compile/cross-compile -->
45+
<ItemGroup>
46+
<PackageReference Include="Microsoft.NET.Runtime.Emscripten.3.1.56.Cache.$(HostRuntime)" Version="9.0.5" PrivateAssets="all"/>
47+
<PackageReference Include="Vezel.Zig.Toolsets.$(HostRuntime)" Version="0.14.0.1" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" PrivateAssets="all"/>
48+
</ItemGroup>
49+
50+
<!-- Import needed for the $(WasmCachePath) property -->
51+
<Import Project="$(NuGetPackageRoot)/microsoft.net.runtime.emscripten.3.1.56.cache.$(HostRuntime)/9.0.5/Sdk/Sdk.props"/>
52+
53+
<PropertyGroup>
54+
<EMSCRIPTEN_CACHE Condition="$(EMSCRIPTEN_CACHE) == ''" >$(WasmCachePath)</EMSCRIPTEN_CACHE>
55+
</PropertyGroup>
56+
4457
<!-- Determine mapping between dotnet RID and zig targets -->
4558
<Choose>
4659
<When Condition="$(RuntimeIdentifier) == 'win-x64'">
@@ -96,37 +109,37 @@
96109
<When Condition="$(RuntimeIdentifier) == 'iossimulator-x64'">
97110
<PropertyGroup>
98111
<ZigIdentifier>x86_64-ios-simulator</ZigIdentifier>
99-
<ZigArgs>--sysroot $(IOS_SIMULATOR_SDK)</ZigArgs>
112+
<ZigArgs>--sysroot "$(IOS_SIMULATOR_SDK)"</ZigArgs>
100113
</PropertyGroup>
101114
</When>
102115
<When Condition="$(RuntimeIdentifier) == 'iossimulator-arm64'">
103116
<PropertyGroup>
104117
<ZigIdentifier>aarch64-ios-simulator</ZigIdentifier>
105-
<ZigArgs>--sysroot $(IOS_SIMULATOR_SDK)</ZigArgs>
118+
<ZigArgs>--sysroot "$(IOS_SIMULATOR_SDK)"</ZigArgs>
106119
</PropertyGroup>
107120
</When>
108121
<When Condition="$(RuntimeIdentifier) == 'ios-arm64'">
109122
<PropertyGroup>
110123
<ZigIdentifier>aarch64-ios</ZigIdentifier>
111-
<ZigArgs>--sysroot $(IOS_SDK)</ZigArgs>
124+
<ZigArgs>--sysroot "$(IOS_SDK)"</ZigArgs>
112125
</PropertyGroup>
113126
</When>
114127
<When Condition="$(RuntimeIdentifier) == 'browser-wasm'">
115128
<PropertyGroup>
116129
<ZigIdentifier>wasm32-emscripten</ZigIdentifier>
117-
<ZigArgs>--sysroot "$(EMSDK)/upstream/emscripten"</ZigArgs>
130+
<ZigArgs>--sysroot "$(EMSCRIPTEN_CACHE)"</ZigArgs>
118131
</PropertyGroup>
119132
</When>
120133
<When Condition="$(RuntimeIdentifier) == 'android-arm64'">
121134
<PropertyGroup>
122135
<ZigIdentifier>aarch64-linux-android</ZigIdentifier>
123-
<ZigArgs>--sysroot $(ANDROID_NDK_HOME)</ZigArgs>
136+
<ZigArgs>--sysroot "$(ANDROID_NDK_HOME)"</ZigArgs>
124137
</PropertyGroup>
125138
</When>
126139
<When Condition="$(RuntimeIdentifier) == 'android-x64'">
127140
<PropertyGroup>
128141
<ZigIdentifier>x86_64-linux-android</ZigIdentifier>
129-
<ZigArgs>--sysroot $(ANDROID_NDK_HOME)</ZigArgs>
142+
<ZigArgs>--sysroot "$(ANDROID_NDK_HOME)"</ZigArgs>
130143
</PropertyGroup>
131144
</When>
132145
<Otherwise>
@@ -136,23 +149,10 @@
136149
</Otherwise>
137150
</Choose>
138151

139-
<!-- Path to compiler_rt.zig -->
140-
<PropertyGroup>
141-
<ZigArgs>$(ZigArgs) -Dcompiler-rt-path="$(ZigLibPath)/compiler_rt.zig"</ZigArgs>
142-
</PropertyGroup>
143-
144-
<!-- Here we need host not target toolset to compile/cross-compile -->
145-
<ItemGroup>
146-
<PackageReference Include="Vezel.Zig.Toolsets.$(HostRuntime)" Version="0.14.0.1">
147-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
148-
<PrivateAssets>all</PrivateAssets>
149-
</PackageReference>
150-
</ItemGroup>
151-
152152
<!-- All the native code compile magic lives here -->
153153
<Target Name="CompileNatives" AfterTargets="Build" Condition="'$(SkipNatives)' != 'true'">
154154
<PropertyGroup>
155-
<BuildCommand>$(ZigExePath) build -Doptimize=$(ZigConfiguration) --prefix $(OutputPath)runtimes --prefix-lib-dir $(RuntimeIdentifier)/native --prefix-exe-dir $(RuntimeIdentifier)/native -Dtarget=$(ZigIdentifier) $(ZigArgs)</BuildCommand>
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>
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: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ const src_flags = [_][]const u8{
1515
"-fno-sanitize=undefined",
1616
};
1717

18-
const include_paths = [_][]const u8{
19-
"../native/box2d/src",
20-
"../native/box2d/include",
21-
};
22-
2318
// Collect all C source files in the given directory and its subdirectories.
2419
fn getSourceFiles(b: *std.Build, dir_path: []const u8) !std.ArrayList([]const u8) {
2520
var list = std.ArrayList([]const u8).init(b.allocator);
@@ -62,17 +57,15 @@ pub fn compile(b: *Build, options: BuildOptions) !void {
6257
lib.root_module.addCMacro("NDEBUG", "");
6358
}
6459

60+
lib.addIncludePath(b.path("../native/box2d/include"));
61+
lib.addIncludePath(b.path("../native/box2d/src"));
62+
6563
const source_files = try getSourceFiles(b, "../native/box2d/src");
6664
defer source_files.deinit();
67-
6865
for (source_files.items) |file| {
6966
lib.addCSourceFile(.{ .file = b.path(file), .flags = &src_flags });
7067
}
7168

72-
for (include_paths) |path| {
73-
lib.addIncludePath(b.path(path));
74-
}
75-
7669
switch (options.target.result.os.tag) {
7770
.windows => {
7871
// Temporary fix to get rid of undefined symbol errors when statically linking in Native AOT.
@@ -91,13 +84,10 @@ pub fn compile(b: *Build, options: BuildOptions) !void {
9184
},
9285
.emscripten => {
9386
if (b.sysroot == null) {
94-
@panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'");
87+
@panic("A --sysroot path to an emscripten cache needs to be provided when compiling for wasm.");
9588
}
9689

97-
const cache_include = b.pathJoin(&.{ b.sysroot.?, "cache", "sysroot", "include" });
98-
var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
99-
dir.close();
100-
lib.addIncludePath(.{ .cwd_relative = cache_include });
90+
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/sysroot/include" }) });
10191
},
10292
.linux => {
10393
if (options.target.result.abi == .android) {

0 commit comments

Comments
 (0)