mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 03:57:29 +00:00
Automatically include Emscripten headers (#173)
* add emscripten headers * update func to return error
This commit is contained in:
parent
606d9bb9ba
commit
de8c2d4585
@ -318,7 +318,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
for (examples) |ex| {
|
for (examples) |ex| {
|
||||||
if (target.query.os_tag == .emscripten) {
|
if (target.query.os_tag == .emscripten) {
|
||||||
const exe_lib = emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize);
|
const exe_lib = try emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize);
|
||||||
exe_lib.root_module.addImport("raylib", raylib);
|
exe_lib.root_module.addImport("raylib", raylib);
|
||||||
exe_lib.root_module.addImport("raygui", raygui);
|
exe_lib.root_module.addImport("raygui", raygui);
|
||||||
const raylib_lib = getRaylib(b, target, optimize, options);
|
const raylib_lib = getRaylib(b, target, optimize, options);
|
||||||
|
9
emcc.zig
9
emcc.zig
@ -39,19 +39,24 @@ pub fn compileForEmscripten(
|
|||||||
root_source_file: []const u8,
|
root_source_file: []const u8,
|
||||||
target: std.Build.ResolvedTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.Mode,
|
optimize: std.builtin.Mode,
|
||||||
) *std.Build.Step.Compile {
|
) !*std.Build.Step.Compile {
|
||||||
// TODO: It might be a good idea to create a custom compile step, that does
|
// TODO: It might be a good idea to create a custom compile step, that does
|
||||||
// both the compile to static library and the link with emcc by overidding
|
// both the compile to static library and the link with emcc by overidding
|
||||||
// the make function of the step. However it might also be a bad idea since
|
// the make function of the step. However it might also be a bad idea since
|
||||||
// it messes with the build system itself.
|
// it messes with the build system itself.
|
||||||
|
|
||||||
// The project is built as a library and linked later.
|
// The project is built as a library and linked later.
|
||||||
return b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
.name = name,
|
.name = name,
|
||||||
.root_source_file = b.path(root_source_file),
|
.root_source_file = b.path(root_source_file),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const emscripten_headers = try std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" });
|
||||||
|
defer b.allocator.free(emscripten_headers);
|
||||||
|
lib.addIncludePath(.{ .cwd_relative = emscripten_headers });
|
||||||
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Links a set of items together using emscripten.
|
// Links a set of items together using emscripten.
|
||||||
|
@ -27,7 +27,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
//web exports are completely separate
|
//web exports are completely separate
|
||||||
if (target.query.os_tag == .emscripten) {
|
if (target.query.os_tag == .emscripten) {
|
||||||
const exe_lib = rlz.emcc.compileForEmscripten(b, "$PROJECT_NAME", "src/main.zig", target, optimize);
|
const exe_lib = try rlz.emcc.compileForEmscripten(b, "$PROJECT_NAME", "src/main.zig", target, optimize);
|
||||||
|
|
||||||
exe_lib.linkLibrary(raylib_artifact);
|
exe_lib.linkLibrary(raylib_artifact);
|
||||||
exe_lib.root_module.addImport("raylib", raylib);
|
exe_lib.root_module.addImport("raylib", raylib);
|
||||||
|
@ -26,7 +26,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
//web exports are completely separate
|
//web exports are completely separate
|
||||||
if (target.query.os_tag == .emscripten) {
|
if (target.query.os_tag == .emscripten) {
|
||||||
const exe_lib = rlz.emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize);
|
const exe_lib = try rlz.emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize);
|
||||||
|
|
||||||
exe_lib.linkLibrary(raylib_artifact);
|
exe_lib.linkLibrary(raylib_artifact);
|
||||||
exe_lib.root_module.addImport("raylib", raylib);
|
exe_lib.root_module.addImport("raylib", raylib);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user