Skip to content

Commit

Permalink
use opend-xpack-emscripten druntime
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Dec 29, 2024
1 parent c45cbac commit 03bcd63
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 136 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,52 @@ jobs:
- name: (Zig) Build Shaders
run: zig build shaders
- name: (Zig) Running Test
if: runner.os != 'Windows'
run: zig build test -DzigCC
- name: (Zig) Build Native
run: zig build -Dimgui --summary all
# - name: (Zig + emsdk) Build Wasm
# run: zig build -Dimgui -DzigCC --summary all -Dtarget=wasm32-emscripten-none -Doptimize=ReleaseSmall

opend:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v1
with:
version: master
- name: Install opend
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
if [ "$RUNNER_ARCH" == "X64" ]; then
curl -sLO https://github.com/opendlang/opend/releases/download/CI/opend-latest-linux-x86_64.tar.xz
tar -xf opend-latest-linux-x86_64.tar.xz
echo "$PWD/opend-latest-linux-x86_64/bin" >> $GITHUB_PATH
$PWD/opend-latest-linux-x86_64/bin/opend install xpack-emscripten
fi
elif [ "$RUNNER_OS" == "macOS" ]; then
if [ "$RUNNER_ARCH" == "ARM64" ]; then
curl -sLO https://github.com/opendlang/opend/releases/download/CI/opend-latest-osx-arm64.tar.xz
tar -xf opend-latest-osx-arm64.tar.xz
echo "$PWD/opend-latest-osx-arm64/bin" >> $GITHUB_PATH
$PWD/opend-latest-osx-arm64/bin/opend install xpack-emscripten
fi
fi
- name: prepare-linux
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install libglu1-mesa-dev mesa-common-dev xorg-dev libasound-dev
- name: (Zig) Build Shaders
run: zig build shaders

- name: (Zig) Running Test
if: runner.os != 'Windows'
run: zig build test -DzigCC
Expand Down
13 changes: 11 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ pub fn build(b: *Build) !void {
.betterC = if (std.mem.eql(u8, example, "user-data")) false else enable_betterC,
.dflags = &.{
"-w",
"-preview=all",
"-preview=rvaluerefparam",
"-preview=dip1000",
},
// fixme: https://github.com/kassane/sokol-d/issues/1 - betterC works on darwin
.zig_cc = if (target.result.isDarwin() and !enable_betterC) false else enable_zigcc,
Expand Down Expand Up @@ -456,6 +457,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
\\
\\ extern (C):
\\
\\ version(D_BetterC):
\\ version (Emscripten)
\\ {
\\ union fpos_t
Expand Down Expand Up @@ -653,8 +655,9 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
.emsdk = options.emsdk.?,
.use_webgpu = backend == .wgpu,
.use_webgl2 = backend != .wgpu,
.use_emmalloc = true,
.use_emmalloc = options.betterC,
.use_filesystem = false,
.use_drt = !options.betterC and options.target.result.isWasm(),
.use_ubsan = options.artifact.?.root_module.sanitize_c orelse false,
.release_use_lto = options.artifact.?.want_lto orelse false,
.shell_file_path = b.path("src/sokol/web/shell.html"),
Expand Down Expand Up @@ -816,6 +819,7 @@ pub const EmLinkOptions = struct {
use_emmalloc: bool = false,
use_filesystem: bool = true,
use_ubsan: bool = false,
use_drt: bool = false,
shell_file_path: ?Build.LazyPath,
extra_args: []const []const u8 = &.{},
};
Expand Down Expand Up @@ -866,6 +870,11 @@ pub fn emLinkStep(b: *Build, options: EmLinkOptions) !*Build.Step.InstallDir {
emcc.addArg(arg);
}

if (options.use_drt) {
const xpack = b.dependency("xpack", .{}).path("lib").getPath(b);
emcc.addFileArg(path(b, b.fmt("{s}/libdruntime-ldc.a", .{xpack})));
emcc.addFileArg(path(b, b.fmt("{s}/libphobos2-ldc.a", .{xpack})));
}
// add the main lib, and then scan for library dependencies and add those too
emcc.addArtifactArg(options.lib_main);
for (options.lib_main.getCompileDependencies(false)) |item| {
Expand Down
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
.url = "git+https://github.com/floooh/sokol-tools-bin#d80b1d8f20fef813092ba37f26723d3880839651",
.hash = "1220f2ae16952843dd25b6bc86b888a3fd8c3f25d34adddfd8d1d2b9f801429e80e4",
},
.xpack = .{
.url = "https://github.com/opendlang/opend/releases/download/CI/opend-latest-xpack-emscripten.tar.xz",
.hash = "1220132c994d2f9754174c5fe934413f3fc79603d1a180429bb231aaed6110429cc6",
},
},
}
Loading

0 comments on commit 03bcd63

Please sign in to comment.