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 theevalBranchQuota
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 themaxMemory
configuration option.module_dir
The full path to the parent directory ofmodule_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 throughsourceFiles
).multithreaded
Whether multithreading is enabled. Corresponds to themultithreaded
configuration option.omit_functions
Whether functions are being exported. Corresponds to theomitFunctions
configuration option.omit_variables
Whether variables are being exported. Corresponds to theomitVariables
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 thestackSize
configuration option.use_libc
Whether the C standard library should be linked in. Corresponds to theuseLibc
configuration option. Relevant only for compilation to WASM.zigar_src_path
The full path to the directory holding Zigar's zig files.