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-9864816f
in/tmp/zigar-build
. - Create
build-cfg.zig
in/tmp/zigar-build/project_x-9864816f
. - Copy
/home/eric/project_x/zig/build.zig
to/tmp/zigar-build/project_x-9864816f
if it exists. If not, copy/home/eric/project_x/node_modules/zigar-compiler/zig/build.zig
. - Copy
/home/eric/project_x/zig/build.zig.zon
to/tmp/zigar-build/project_x-9864816f
if 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-9864816f
ifclean
istrue
The build directory would look like this afterward:
📄 build-cfg.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 is_wasm = false;
pub const multithreaded = true;
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.