#Compile build.zig with c library for emscripten

1 messages · Page 1 of 1 (latest)

edgy crown
#

I have the following build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const mod = b.addModule("zlisp", .{
        .root_source_file = b.path("src/root.zig"),
        .target = target,
        .optimize = optimize,
    });

    const pcre2_dep = b.dependency("pcre2", .{
        .target = target,
        .optimize = optimize,
    });
    mod.linkLibrary(pcre2_dep.artifact("pcre2-8"));

    const lib_unit_tests = b.addTest(.{
        .root_module = mod,
    });

    const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_lib_unit_tests.step);
}

How could I compile it for -Dtarget=wasm32-emscripten? If I try to build it I get the error
.cache/zig/p/N-V-__8AAPaj4AA7tqCGizncMhl8gm8AX1wmXFaB7jH2tJoq/src/pcre2_internal.h:83:10: error: 'ctype.h' file not found
#include <ctype.h>
So I'm missing some compile step to link c header files to pcre2, but I'm not sure how to proceed. Searches online did not yield any result.

dark rock
#

do you have the emsdk? zigs support for emscripten is barebones it doesnt ship anything for it

dark rock
#

you need to add the emscripten include paths

edgy crown
#

So, I should check if I'm targeting emscripten and addIncludePath the path of emsdk headers, right?

dark rock
#

yea

edgy crown
# dark rock yea

So, I added

    const pcre2_artifact = pcre2_dep.artifact("pcre2-8");
    mod.linkLibrary(pcre2_artifact);

    if (target.query.os_tag == .emscripten) {
        pcre2_artifact.addIncludePath(b.path("../emsdk/upstream/include/c++/v1/"));
    }

But it still didn't find some files, such as
/snap/zig/14937/lib/include/inttypes.h:24:15: error: 'inttypes.h' file not found
#include_next <inttypes.h>
I've checked and the file exists on "../emsdk/upstream/include/c++/v1/

dark rock
#

sorry im not really familiar with how emscripten is setup. you might be able to find other threads in here, i know others have done it before

edgy crown
#

I'll look into it, worst case scenario I'll parse what I need in zig and remove pcre2