Skip to content

Commit 961d51d

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

File tree

3 files changed

+42
-59
lines changed

3 files changed

+42
-59
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 20 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,30 +57,21 @@ 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: |
63-
IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
64-
IOS_SIMULATOR_SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
65-
66-
echo "IOS_SDK=$IOS_SDK" >> $GITHUB_ENV
67-
echo "IOS_SIMULATOR_SDK=$IOS_SIMULATOR_SDK" >> $GITHUB_ENV
68-
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'
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
7465
7566
- name: Setup Android NDK
76-
if: matrix.os == 'macos-13'
67+
if: matrix.os == 'macos-latest'
7768
uses: nttld/setup-ndk@v1
7869
with:
7970
ndk-version: r25c
8071
link-to-sdk: true
8172

8273
- name: Set Android NDK variables
83-
if: matrix.os == 'macos-13'
74+
if: matrix.os == 'macos-latest'
8475
shell: bash
8576
run: |
8677
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
@@ -101,29 +92,31 @@ jobs:
10192
10293
- name: Build Natives
10394
shell: bash
104-
if: matrix.os == 'macos-13'
95+
if: matrix.os == 'macos-latest'
10596
working-directory: Box2D.NET.Native
10697
run: |
10798
dotnet build -c Debug -r linux-x64
99+
dotnet build -c Debug -r linux-x86
108100
dotnet build -c Debug -r linux-arm64
109101
dotnet build -c Debug -r osx-x64
110102
dotnet build -c Debug -r osx-arm64
111103
dotnet build -c Debug -r win-x64
104+
dotnet build -c Debug -r win-x86
112105
dotnet build -c Debug -r win-arm64
113-
dotnet build -c Debug -r browser-wasm
114106
dotnet build -c Debug -r iossimulator-x64
115107
dotnet build -c Debug -r iossimulator-arm64
116108
dotnet build -c Debug -r ios-arm64
117109
dotnet build -c Debug -r android-arm64
118110
dotnet build -c Debug -r android-x64
119111
120112
dotnet build -c Release -r linux-x64
113+
dotnet build -c Release -r linux-x86
121114
dotnet build -c Release -r linux-arm64
122115
dotnet build -c Release -r osx-x64
123116
dotnet build -c Release -r osx-arm64
124117
dotnet build -c Release -r win-x64
118+
dotnet build -c Release -r win-x86
125119
dotnet build -c Release -r win-arm64
126-
dotnet build -c Release -r browser-wasm
127120
dotnet build -c Release -r iossimulator-x64
128121
dotnet build -c Release -r iossimulator-arm64
129122
dotnet build -c Release -r ios-arm64
@@ -148,7 +141,7 @@ jobs:
148141
fi
149142
150143
- name: Upload Artifacts
151-
if: matrix.os == 'macos-13'
144+
if: matrix.os == 'macos-latest'
152145
uses: actions/upload-artifact@v4
153146
with:
154147
name: Nuget Packages
@@ -158,7 +151,7 @@ jobs:
158151
159152
- name: Push NuGet Packages
160153
if: >
161-
matrix.os == 'macos-13' &&
154+
matrix.os == 'macos-latest' &&
162155
github.repository_owner == 'BeanCheeseBurrito' &&
163156
(
164157
(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: 9 additions & 19 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.
@@ -81,27 +74,24 @@ pub fn compile(b: *Build, options: BuildOptions) !void {
8174
}
8275
},
8376
.ios => {
84-
if (b.sysroot == null) {
77+
if (b.sysroot == null or b.sysroot.?.len == 0) {
8578
@panic("A --sysroot path to an IOS SDK needs to be provided when compiling for IOS.");
8679
}
8780

8881
lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/System/Library/Frameworks" }) });
8982
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/usr/include" }) });
90-
lib.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "/usr/lib" }) });
83+
lib.addLibraryPath(.{ .cwd_relative = "/usr/lib" });
9184
},
9285
.emscripten => {
93-
if (b.sysroot == null) {
94-
@panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'");
86+
if (b.sysroot == null or b.sysroot.?.len == 0) {
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) {
104-
if (b.sysroot == null) {
94+
if (b.sysroot == null or b.sysroot.?.len == 0) {
10595
@panic("A --sysroot path to an Android NDK needs to be provided when compiling for Android.");
10696
}
10797

0 commit comments

Comments
 (0)