Build process - chung-leong/zigar GitHub Wiki
Suppose we have the following Zig file:
/home/eric/project_x/zig/hello.zig
And we want to compile it at ReleaseSmall to:
/home/eric/project_x/lib/hello.zigar/linux.x64.so
Zigar would go through the following steps:
- Write the process id to '/tmp/zigar-build/project_x-9864816f.pid'. If the file exists already, read the process id and check if the process is still alive. Keep waiting until the other process has gone away.
- Create the sub-directory
project_x-9864816fin/tmp/zigar-build. - Create
build.cfg.zigin/tmp/zigar-build/project_x-9864816f. - Copy
/home/eric/project_x/zig/build.zigto/tmp/zigar-build/project_x-9864816fif it exists. If not, copy/home/eric/project_x/node_modules/zigar-compiler/zig/build.zig. - Copy
/home/eric/project_x/zig/build.extra.zigto/tmp/zigar-build/project_x-9864816fif it exists. - Copy
/home/eric/project_x/zig/build.zig.zonto/tmp/zigar-build/project_x-9864816fif it exists. - Run the command
zig build -Doptimize=ReleaseSmall -Dtarget=linux-x86_64-gnu. - If an error occurs, write the compiler output to
/tmp/zigar-build/project_x-9864816f/log - Remove
/tmp/zigar-build/project_x-9864816fif clean istrue
The build directory would look like this afterward:
📄 build.cfg.zig
📄 build.extra.zig
📄 build.zig
📄 build.zig.zon
📁 .zig-cache
build.cfg.zig would contain the following:
pub const module_name = "hello";
pub const module_path = "/home/eric/project_x/zig/type-example-4.zig";
pub const module_dir = "/home/eric/project_x/zig/";
pub const zigar_src_path = "/home/eric/project_x/node_modules/zigar-compiler/zig/";
pub const output_path = "/home/eric/project_x/lib/hello.zigar/linux.x64.so";
pub const use_libc = true;
pub const use_llvm = null;
pub const use_redirection = true;
pub const use_pthread_emulation = false;
pub const is_wasm = false;
pub const multithreaded = false;
pub const stack_size = 262144;
pub const max_memory = null;
pub const eval_branch_quota = 2000000;
pub const omit_functions = false;
pub const omit_variables = false;
Notes
The random string attached to the name of the build directory is the first 8 letters of sha1("/home/eric/project_x/zig/").
The content of build.cfg.zig is described here.
If build.zig.zon contains references to local modules, their paths will be updated to be
relative to the build directory.