View Source mix compile.build_dot_zig (build_dot_zig v0.1.0)

Runs zig build using the build.zig file in the current project.

This task runs zig build in the current project; any output coming from zig build is printed in real-time on stdout.

configuration

Configuration

This compiler can be configured through the return value of the project/0 function in mix.exs; for example:

def project() do
  [app: :myapp,
   build_dot_zig_executable: "zig",
   compilers: [:build_dot_zig] ++ Mix.compilers,
   deps: deps()]
end

The following options are available:

  • :build_dot_zig_executable - (binary or :default) it's the executable to use as the zig program. If not provided or if :default, it defaults to "zig".

default-environment-variables

Default environment variables

This compiler also sets deveral default environment variables which are accessible from build.zig:

compilation-artifacts-and-working-with-priv-directories

Compilation artifacts and working with priv directories

Generally speaking, compilation artifacts are written to the priv directory, as that the only directory, besides ebin, which are available to Erlang/OTP applications.

However, note that Mix projects supports the :build_embedded configuration, which controls if assets in the _build directory are symlinked (when false, the default) or copied (true). In order to support both options for :build_embedded, it is important to follow the given guidelines:

  • The "priv" directory must not exist in the source code
  • If there are static assets, build.zig should copy them over from a directory at the project root (not named "priv")

This compiler passes $MIX_APP_PATH/priv/$MIX_TARGET as install prefix to zig build, so the resulting artifacts can be found in $PREFIX/lib for libraries and $PREFIX/bin for binaries. Note that the default $MIX_TARGET is :host.