Add WASM support for Zig build (#2901)
* Add WASM support for Zig build * Improve Web example building * Remove emscript example building with Zig again * Readd windows emscripten variables
This commit is contained in:
parent
c94c666d04
commit
89171a2608
4 changed files with 55 additions and 21 deletions
|
@ -67,8 +67,8 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Determine PLATFORM_OS in case PLATFORM_DESKTOP selected
|
# Determine PLATFORM_OS in case PLATFORM_DESKTOP or PLATFORM_WEB selected
|
||||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP PLATFORM_WEB))
|
||||||
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
|
# No uname.exe on MinGW!, but OS=Windows_NT on Windows!
|
||||||
# ifeq ($(UNAME),Msys) -> Windows
|
# ifeq ($(UNAME),Msys) -> Windows
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
|
@ -126,16 +126,18 @@ ifeq ($(PLATFORM),PLATFORM_DRM)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Define raylib release directory for compiled library
|
# Define raylib release directory for compiled library
|
||||||
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
|
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
# Emscripten required variables
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
EMSDK_PATH ?= C:/emsdk
|
# Emscripten required variables
|
||||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
|
EMSDK_PATH ?= C:/emsdk
|
||||||
CLANG_PATH = $(EMSDK_PATH)/upstream/bin
|
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
|
||||||
PYTHON_PATH = $(EMSDK_PATH)/python/3.9.2-1_64bit
|
CLANG_PATH = $(EMSDK_PATH)/upstream/bin
|
||||||
NODE_PATH = $(EMSDK_PATH)/node/14.15.5_64bit/bin
|
PYTHON_PATH = $(EMSDK_PATH)/python/3.9.2-1_64bit
|
||||||
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH):$$(PATH)
|
NODE_PATH = $(EMSDK_PATH)/node/14.15.5_64bit/bin
|
||||||
|
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH):$$(PATH)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Define default C compiler: CC
|
# Define default C compiler: CC
|
||||||
|
@ -579,7 +581,10 @@ ifeq ($(PLATFORM),PLATFORM_DRM)
|
||||||
rm -fv *.o
|
rm -fv *.o
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
del *.o *.html *.js
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
|
del *.wasm *.html *.js *.data
|
||||||
|
else
|
||||||
|
rm -f */*.wasm */*.html */*.js */*.data
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
@echo Cleaning done
|
@echo Cleaning done
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@ const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step {
|
fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step {
|
||||||
|
if (target.getOsTag() == .emscripten) {
|
||||||
|
@panic("Emscripten building via Zig unsupported");
|
||||||
|
}
|
||||||
|
|
||||||
// Standard release options allow the person running `zig build` to select
|
// Standard release options allow the person running `zig build` to select
|
||||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
|
@ -19,12 +23,7 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
|
||||||
if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
|
if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
|
||||||
|
|
||||||
const exe = b.addExecutable(name, null);
|
const exe = b.addExecutable(name, null);
|
||||||
exe.addCSourceFile(path, switch (target.getOsTag()) {
|
exe.addCSourceFile(path, &[_][]const u8{});
|
||||||
.windows => &[_][]const u8{},
|
|
||||||
.linux => &[_][]const u8{},
|
|
||||||
.macos => &[_][]const u8{"-DPLATFORM_DESKTOP"},
|
|
||||||
else => @panic("Unsupported OS"),
|
|
||||||
});
|
|
||||||
exe.setTarget(target);
|
exe.setTarget(target);
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
|
@ -32,6 +31,7 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
|
||||||
.windows => "../src/raylib.lib",
|
.windows => "../src/raylib.lib",
|
||||||
.linux => "../src/libraylib.a",
|
.linux => "../src/libraylib.a",
|
||||||
.macos => "../src/libraylib.a",
|
.macos => "../src/libraylib.a",
|
||||||
|
.emscripten => "../src/libraylib.a",
|
||||||
else => @panic("Unsupported OS"),
|
else => @panic("Unsupported OS"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,12 +39,14 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
|
||||||
exe.addIncludePath("../src/external");
|
exe.addIncludePath("../src/external");
|
||||||
exe.addIncludePath("../src/external/glfw/include");
|
exe.addIncludePath("../src/external/glfw/include");
|
||||||
|
|
||||||
switch (exe.target.toTarget().os.tag) {
|
switch (target.getOsTag()) {
|
||||||
.windows => {
|
.windows => {
|
||||||
exe.linkSystemLibrary("winmm");
|
exe.linkSystemLibrary("winmm");
|
||||||
exe.linkSystemLibrary("gdi32");
|
exe.linkSystemLibrary("gdi32");
|
||||||
exe.linkSystemLibrary("opengl32");
|
exe.linkSystemLibrary("opengl32");
|
||||||
exe.addIncludePath("external/glfw/deps/mingw");
|
exe.addIncludePath("external/glfw/deps/mingw");
|
||||||
|
|
||||||
|
exe.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
},
|
},
|
||||||
.linux => {
|
.linux => {
|
||||||
exe.linkSystemLibrary("GL");
|
exe.linkSystemLibrary("GL");
|
||||||
|
@ -52,6 +54,8 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
|
||||||
exe.linkSystemLibrary("dl");
|
exe.linkSystemLibrary("dl");
|
||||||
exe.linkSystemLibrary("m");
|
exe.linkSystemLibrary("m");
|
||||||
exe.linkSystemLibrary("X11");
|
exe.linkSystemLibrary("X11");
|
||||||
|
|
||||||
|
exe.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
},
|
},
|
||||||
.macos => {
|
.macos => {
|
||||||
exe.linkFramework("Foundation");
|
exe.linkFramework("Foundation");
|
||||||
|
@ -60,6 +64,8 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
|
||||||
exe.linkFramework("CoreAudio");
|
exe.linkFramework("CoreAudio");
|
||||||
exe.linkFramework("CoreVideo");
|
exe.linkFramework("CoreVideo");
|
||||||
exe.linkFramework("IOKit");
|
exe.linkFramework("IOKit");
|
||||||
|
|
||||||
|
exe.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
@panic("Unsupported OS");
|
@panic("Unsupported OS");
|
||||||
|
|
0
examples/shapes/resources/.gitkeep
Normal file
0
examples/shapes/resources/.gitkeep
Normal file
|
@ -3,7 +3,6 @@ const std = @import("std");
|
||||||
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
||||||
const raylib_flags = &[_][]const u8{
|
const raylib_flags = &[_][]const u8{
|
||||||
"-std=gnu99",
|
"-std=gnu99",
|
||||||
"-DPLATFORM_DESKTOP",
|
|
||||||
"-D_GNU_SOURCE",
|
"-D_GNU_SOURCE",
|
||||||
"-DGL_SILENCE_DEPRECATION=199309L",
|
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||||
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
|
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
|
||||||
|
@ -25,13 +24,15 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
|
||||||
srcdir ++ "/utils.c",
|
srcdir ++ "/utils.c",
|
||||||
}, raylib_flags);
|
}, raylib_flags);
|
||||||
|
|
||||||
switch (raylib.target.toTarget().os.tag) {
|
switch (target.getOsTag()) {
|
||||||
.windows => {
|
.windows => {
|
||||||
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||||
raylib.linkSystemLibrary("winmm");
|
raylib.linkSystemLibrary("winmm");
|
||||||
raylib.linkSystemLibrary("gdi32");
|
raylib.linkSystemLibrary("gdi32");
|
||||||
raylib.linkSystemLibrary("opengl32");
|
raylib.linkSystemLibrary("opengl32");
|
||||||
raylib.addIncludePath("external/glfw/deps/mingw");
|
raylib.addIncludePath("external/glfw/deps/mingw");
|
||||||
|
|
||||||
|
raylib.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
},
|
},
|
||||||
.linux => {
|
.linux => {
|
||||||
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||||
|
@ -40,6 +41,8 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
|
||||||
raylib.linkSystemLibrary("dl");
|
raylib.linkSystemLibrary("dl");
|
||||||
raylib.linkSystemLibrary("m");
|
raylib.linkSystemLibrary("m");
|
||||||
raylib.linkSystemLibrary("X11");
|
raylib.linkSystemLibrary("X11");
|
||||||
|
|
||||||
|
raylib.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
},
|
},
|
||||||
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
||||||
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||||
|
@ -53,6 +56,8 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
|
||||||
raylib.linkSystemLibrary("Xi");
|
raylib.linkSystemLibrary("Xi");
|
||||||
raylib.linkSystemLibrary("Xxf86vm");
|
raylib.linkSystemLibrary("Xxf86vm");
|
||||||
raylib.linkSystemLibrary("Xcursor");
|
raylib.linkSystemLibrary("Xcursor");
|
||||||
|
|
||||||
|
raylib.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
},
|
},
|
||||||
.macos => {
|
.macos => {
|
||||||
// On macos rglfw.c include Objective-C files.
|
// On macos rglfw.c include Objective-C files.
|
||||||
|
@ -68,6 +73,24 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
|
||||||
raylib.linkFramework("CoreGraphics");
|
raylib.linkFramework("CoreGraphics");
|
||||||
raylib.linkFramework("AppKit");
|
raylib.linkFramework("AppKit");
|
||||||
raylib.linkFramework("IOKit");
|
raylib.linkFramework("IOKit");
|
||||||
|
|
||||||
|
raylib.defineCMacro("PLATFORM_DESKTOP", null);
|
||||||
|
},
|
||||||
|
.emscripten => {
|
||||||
|
raylib.defineCMacro("PLATFORM_WEB", null);
|
||||||
|
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
|
||||||
|
|
||||||
|
if (b.sysroot == null) {
|
||||||
|
@panic("Pass '--sysroot \"$EMSDK/upstream/emscripten\"'");
|
||||||
|
}
|
||||||
|
|
||||||
|
const cache_include = std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }) catch @panic("Out of memory");
|
||||||
|
defer b.allocator.free(cache_include);
|
||||||
|
|
||||||
|
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!");
|
||||||
|
dir.close();
|
||||||
|
|
||||||
|
raylib.addIncludePath(cache_include);
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
@panic("Unsupported OS");
|
@panic("Unsupported OS");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue