View Source mix compile.build_dot_zig (build_dot_zig v0.2.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,
install_zig: "0.10.1",
compilers: [:build_dot_zig] ++ Mix.compilers,
deps: deps()
]
end
The following options are available:
:install_zig
- (binary or boolean) determines if a Zig installation should be automatically downloaded and installed locally in the build directory. Iffalse
, no Zig installation is downloaded. Iftrue
(default), the latest Zig stable version is downloaded. Otherwise, it's possible to pass a specific Zig version, e.g.install_zig: "0.9.1"
.:zig_executable
- (binary or:default
) it's the executable to use as thezig
program. If not provided or if:default
, it defaults to the downloadedzig
binary if theinstall_zig
was configured to download Zig, otherwise it defaults tozig
(it assumes to find it in thePATH
). Note that it's possible to both install a downloaded Zig installation and pass a local:zig_executable
. This is useful for use cases where the downloaded Zig installation must be called through some wrapper script.:zig_build_mode
- (atom) allows choosing the build mode. The supported build modes are:debug
(default),:release_safe
,:release_fast
and:release_small
.
default-environment-variables
Default environment variables
This compiler also sets deveral default environment variables which are accessible
from build.zig
:
MIX_TARGET
MIX_ENV
MIX_BUILD_PATH
- same asMix.Project.build_path/0
MIX_APP_PATH
- same asMix.Project.app_path/0
MIX_COMPILE_PATH
- same asMix.Project.compile_path/0
MIX_CONSOLIDATION_PATH
- same asMix.Project.consolidation_path/0
MIX_DEPS_PATH
- same asMix.Project.deps_path/0
MIX_MANIFEST_PATH
- same asMix.Project.manifest_path/0
ERL_EI_LIBDIR
ERL_EI_INCLUDE_DIR
ERTS_INCLUDE_DIR
ERL_INTERFACE_LIB_DIR
ERL_INTERFACE_INCLUDE_DIR
ZIG_INSTALL_DIR
- the directory where the Zig toolchain was downloaded, if it was.
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
.