Custom build file - chung-leong/zigar GitHub Wiki

Zigar uses its built-in build.zig when compiling your Zig files. There are occasions when you might need to customize the build settings. For instance, when you're employing third-party packages.

To obtain a copy of Zigar's build.zig, go to the directory where your Zig file is stored and run one of the following commands:

npx node-zigar custom
npx rollup-plugin-zigar custom
npx zigar-loader custom

You can then make the necessary changes.

Adding a package

Place dependent packages in the imports tuple. Example:

    const ziglua = b.dependency("ziglua", .{
        .target = target,
        .optimize = optimize,
    }).module("ziglua");
    const imports = [_]std.Build.Module.Import{
        .{ .name = "zigar", .module = zigar },
        .{ .name = "ziglua", .module = ziglua },
    };

Adding a C source file

Call addIncludePath to add directories holding expected header files. Call addCSourceFile to add the source file itself.

    lib.addIncludePath(.{ .path = "./libx/include" });
    lib.addCSourceFile(.{ .file = .{ .path = "./libx/src/main.c" }, .flags = &.{} });

Fields in build-cfg.zig

'omitFunctions', 'omitVariables',
  • eval_branch_quota
    Value provided to @setEvalBranchQuota() during export. Corresponds to the evalBranchQuota configuration option.
  • is_wasm
    Whether the target archecture is WebAssembly.
  • max_memory
    The maximum amount of memory that the WebAssembly VM can use. Corresponds to the maxMemory configuration option.
  • module_dir
    The full path to the parent directory of module_path.
  • module_name
    The name of the module, i.e. the name of the Zig file without the extension.
  • module_path
    The full path to the Zig file specified in the import statement (directly or indirectly through sourceFiles).
  • multithreaded
    Whether multithreading is enabled. Corresponds to the multithreaded configuration option.
  • omit_functions
    Whether functions are being exported. Corresponds to the omitFunctions configuration option.
  • omit_variables
    Whether variables are being exported. Corresponds to the omitVariables configuration option.
  • output_path
    The full path to the .so, .dylib, or .dll. file being generated.
  • stack_size
    The size of the call stack in bytes. Corresponds to the stackSize configuration option.
  • use_libc
    Whether the C standard library should be linked in. Corresponds to the useLibc configuration option. Relevant only for compilation to WASM.
  • zigar_src_path
    The full path to the directory holding Zigar's zig files.