Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/aduros/wasm4 into chore/con…
Browse files Browse the repository at this point in the history
…vert-to-monorepo
  • Loading branch information
FaberVitale committed Jan 13, 2022
2 parents b88aa1a + 9db63e0 commit 1a191d5
Show file tree
Hide file tree
Showing 31 changed files with 1,026 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- os: windows-latest
artifact: "windows"
wasm4: bin/wasm4.exe
libretro: bin/wasm4_libretro.dll
libretro: lib/wasm4_libretro.dll

- os: macos-latest
artifact: "mac"
Expand Down
129 changes: 129 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# DESCRIPTION: GitLab CI/CD for libRetro (NOT FOR GitLab-proper)

##############################################################################
################################# BOILERPLATE ################################
##############################################################################

# Core definitions
.core-defs:
variables:
GIT_SUBMODULE_STRATEGY: recursive
CORENAME: wasm4
CORE_ARGS: -DCMAKE_BUILD_TYPE=Release -DLIBRETRO=ON
CMAKE_SOURCE_ROOT: runtimes/native

.core-defs-linux:
extends: .core-defs
variables:
CORE_ARGS: -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release

.core-defs-osx-x64:
extends: .core-defs
variables:
CORE_ARGS: -G Xcode -DCMAKE_BUILD_TYPE=Release
EXTRA_PATH: Release

.core-defs-android:
extends: .core-defs

.core-defs-emscripten:
extends: .core-defs

# Inclusion templates, required for the build to work
include:
################################## DESKTOPS ################################
# Windows
- project: 'libretro-infrastructure/ci-templates'
file: '/windows-cmake-mingw.yml'

# MacOS
- project: 'libretro-infrastructure/ci-templates'
file: 'osx-cmake-x86.yml'

# Linux
- project: 'libretro-infrastructure/ci-templates'
file: '/linux-cmake.yml'

################################## CELLULAR ################################
# Android
- project: 'libretro-infrastructure/ci-templates'
file: '/android-cmake.yml'

################################## MISC ####################################
# Emscripten
- project: 'libretro-infrastructure/ci-templates'
file: '/emscripten-static-cmake.yml'

# Stages for building
stages:
- build-prepare
- build-shared
- build-static

##############################################################################
#################################### STAGES ##################################
##############################################################################
#
################################### DESKTOPS #################################
# Windows 64-bit
libretro-build-windows-x64:
extends:
- .libretro-windows-cmake-x86_64
- .core-defs

# Windows 32-bit
libretro-build-windows-i686:
extends:
- .libretro-windows-cmake-x86
- .core-defs

# Linux 64-bit
libretro-build-linux-x64:
extends:
- .libretro-linux-cmake-x86_64
- .core-defs-linux

# Linux 32-bit
libretro-build-linux-i686:
extends:
- .libretro-linux-cmake-x86
- .core-defs-linux

# MacOS 64-bit
libretro-build-osx-x64:
extends:
- .libretro-osx-cmake-x86
- .core-defs-osx-x64

################################### CELLULAR #################################
# Android ARMv7a
android-armeabi-v7a:
extends:
- .libretro-android-cmake-armeabi-v7a
- .core-defs-android

# Android ARMv8a
android-arm64-v8a:
extends:
- .libretro-android-cmake-arm64-v8a
- .core-defs-android

# Android 64-bit x86
android-x86_64:
extends:
- .libretro-android-cmake-x86_64
- .core-defs-android

# Android 32-bit x86
android-x86:
extends:
- .libretro-android-cmake-x86
- .core-defs-android

################################### MISC #####################################

# Emscripten
libretro-build-emscripten:
extends:
- .libretro-emscripten-static-cmake-retroarch-master
- .core-defs-emscripten
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[submodule "runtimes/native/vendor/wasm3"]
path = runtimes/native/vendor/wasm3
url = git://github.com/wasm3/wasm3
url = https://github.com/wasm3/wasm3
[submodule "runtimes/native/vendor/glfw"]
path = runtimes/native/vendor/glfw
url = git://github.com/glfw/glfw
url = https://github.com/glfw/glfw
[submodule "runtimes/native/vendor/minifb"]
path = runtimes/native/vendor/minifb
url = git://github.com/emoon/minifb
url = https://github.com/emoon/minifb
[submodule "runtimes/native/vendor/cubeb"]
path = runtimes/native/vendor/cubeb
url = git://github.com/mozilla/cubeb
url = https://github.com/mozilla/cubeb
12 changes: 6 additions & 6 deletions cli/assets/templates/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ else
endif

# Linker flags
LDFLAGS = -Wl,-zstack-size=8192,--no-entry,--import-memory -mexec-model=reactor \
-Wl,--initial-memory=65536,--max-memory=65536,--global-base=6560
LDFLAGS = -Wl,-zstack-size=14752,--no-entry,--import-memory -mexec-model=reactor \
-Wl,--initial-memory=65536,--max-memory=65536,--stack-first
ifeq ($(DEBUG), 1)
LDFLAGS += -Wl,--export-all,--no-gc-sections
else
Expand All @@ -34,10 +34,10 @@ OBJECTS += $(patsubst src/%.cpp, build/%.o, $(wildcard src/*.cpp))
DEPS = $(OBJECTS:.o=.d)

ifeq ($(OS), Windows_NT)
MKDIR = md
MKDIR_BUILD = if not exist build md build
RMDIR = rd /s /q
else
MKDIR = mkdir -p
MKDIR_BUILD = mkdir -p build
RMDIR = rm -rf
endif

Expand All @@ -56,12 +56,12 @@ endif

# Compile C sources
build/%.o: src/%.c
@$(MKDIR) build
@$(MKDIR_BUILD)
$(CC) -c $< -o $@ $(CFLAGS)

# Compile C++ sources
build/%.o: src/%.cpp
@$(MKDIR) build
@$(MKDIR_BUILD)
$(CXX) -c $< -o $@ $(CFLAGS)

.PHONY: clean
Expand Down
8 changes: 4 additions & 4 deletions cli/assets/templates/d/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"lflags": [
"--strip-all",
"--allow-undefined",
"--global-base=6560",
"--stack-first",
"--import-memory",
"--initial-memory=65536",
"--max-memory=65536",
"--no-entry",
"-zstack-size=8192"
"-zstack-size=14752"
]
},
{
Expand All @@ -28,12 +28,12 @@
"lflags": [
"--strip-all",
"--allow-undefined",
"--global-base=6560",
"--stack-first",
"--import-memory",
"--initial-memory=65536",
"--max-memory=65536",
"--no-entry",
"-zstack-size=8192",
"-zstack-size=14752",
"$WASI_SDK_PATH/share/wasi-sysroot/lib/wasm32-wasi/libc.a"
]
}
Expand Down
4 changes: 2 additions & 2 deletions cli/assets/templates/go/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"--import-memory",
"--initial-memory=65536",
"--max-memory=65536",
"--global-base=6560",
"-zstack-size=8192",
"--stack-first",
"-zstack-size=14752",
"--strip-all"
],
"emulator": [ "w4", "run" ],
Expand Down
4 changes: 2 additions & 2 deletions cli/assets/templates/nelua/src/wasm4.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
-- Configure compiler.
-- NOTE: This must come first because it changes some compiler settings!
##[[
ldflags "-Wl,-zstack-size=8192,--no-entry,--import-memory -mexec-model=reactor"
ldflags "-Wl,--initial-memory=65536,--max-memory=65536,--global-base=6560,--export-dynamic"
ldflags "-Wl,-zstack-size=14752,--no-entry,--import-memory -mexec-model=reactor"
ldflags "-Wl,--initial-memory=65536,--max-memory=65536,--stack-first,--export-dynamic"
if DEBUG then
-- We should use at least 01 optimization, otherwise the application may use too much stack space.
Expand Down
2 changes: 1 addition & 1 deletion cli/assets/templates/nim/src/config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ switch("clang.linkerexe", wasi / "bin" / "clang")

switch("passC", "--sysroot=" & (wasi / "share" / "wasi-sysroot"))

switch("passL", "-Wl,-zstack-size=8192,--no-entry,--import-memory -mexec-model=reactor -Wl,--initial-memory=65536,--max-memory=65536,--global-base=6560")
switch("passL", "-Wl,-zstack-size=14752,--no-entry,--import-memory -mexec-model=reactor -Wl,--initial-memory=65536,--max-memory=65536,--stack-first")

when not defined(release):
switch("assertions", "off")
Expand Down
2 changes: 1 addition & 1 deletion cli/assets/templates/odin/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build/cart.wasm: src/*.odin
@-mkdir -p build
odin build src -out:build/cart.wasm -target:freestanding_wasm32 -no-entry-point -extra-linker-flags:"--import-memory -zstack-size=8192 --initial-memory=65536 --max-memory=65536 --global-base=6560 --lto-O3 --gc-sections --strip-all"
odin build src -out:build/cart.wasm -target:freestanding_wasm32 -no-entry-point -extra-linker-flags:"--import-memory -zstack-size=14752 --initial-memory=65536 --max-memory=65536 --stack-first --lto-O3 --gc-sections --strip-all"
58 changes: 54 additions & 4 deletions cli/assets/templates/zig/build.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions();
// Returns true if the version includes https://github.com/ziglang/zig/pull/10572/commits.
// When this is false, trying to place the stack first will result in data corruption.
fn version_supports_stack_first(zig_version: std.SemanticVersion) !bool {
if (zig_version.order(try std.SemanticVersion.parse("0.10.0")).compare(.gte)) {
// Merged here: https://github.com/ziglang/zig/pull/10572
return true;
}
if (zig_version.major == 0 and zig_version.minor == 10) {
// Check for 0.10.0-dev.258+. Conservatively check the prefix of the tag
// in case zig uses other prefixes that don't respect semver ordering.
if (zig_version.pre) |pre| {
// Merged here: https://github.com/ziglang/zig/pull/10572
return std.mem.startsWith(u8, pre, "dev.") and zig_version.order(try std.SemanticVersion.parse("0.10.0-dev.258")).compare(.gte);
}
}
// Backported here: https://github.com/ziglang/zig/commit/6f49233ac6a6569b909b689f22fc260dc8c19234
return zig_version.order(try std.SemanticVersion.parse("0.9.1")).compare(.gte);
}

test "stack version check" {
const expect = std.testing.expect;
const parse = std.SemanticVersion.parse;
try expect(!try version_supports_stack_first(try parse("0.8.0")));

try expect(!try version_supports_stack_first(try parse("0.9.0")));
try expect(!try version_supports_stack_first(try parse("0.9.1-dev.259")));
try expect(try version_supports_stack_first(try parse("0.9.1")));

// Conservatively don't recognize tags other than 'dev'.
try expect(!try version_supports_stack_first(try parse("0.10.0-aev.259")));
try expect(!try version_supports_stack_first(try parse("0.10.0-zev.259")));

try expect(!try version_supports_stack_first(try parse("0.10.0-dev.257")));
try expect(try version_supports_stack_first(try parse("0.10.0-dev.258")));
try expect(try version_supports_stack_first(try parse("0.10.0-dev.259")));
try expect(try version_supports_stack_first(try parse("0.10.0")));

try expect(try version_supports_stack_first(try parse("0.10.1-dev.100")));
try expect(try version_supports_stack_first(try parse("0.10.1-dev.300")));
try expect(try version_supports_stack_first(try parse("0.10.1")));

try expect(try version_supports_stack_first(try parse("1.0.0")));
}

pub fn build(b: *std.build.Builder) !void {
const zig_version = @import("builtin").zig_version;
const mode = b.standardReleaseOptions();
const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned);
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.import_memory = true;
lib.initial_memory = 65536;
lib.max_memory = 65536;
lib.global_base = 6560;
lib.stack_size = 8192;
if (try version_supports_stack_first(zig_version)) {
lib.stack_size = 14752;
} else {
// `--stack-first` option have been reenabled on wasm targets with https://github.com/ziglang/zig/pull/10572
std.log.warn("Update to Zig >=0.9.1 (or >=0.10.0-dev.258 for nightly) to detect stack overflows at runtime.", .{});
lib.global_base = 6560;
lib.stack_size = 8192;
}
// Workaround https://github.com/ziglang/zig/issues/2910, preventing
// functions from compiler_rt getting incorrectly marked as exported, which
// prevents them from being removed even if unused.
Expand Down
Loading

0 comments on commit 1a191d5

Please sign in to comment.