Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
zig source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
zig 0.10.0
zig 0.11.0
zig 0.12.0
zig 0.12.1
zig 0.13.0
zig 0.2.0
zig 0.3.0
zig 0.4.0
zig 0.5.0
zig 0.6.0
zig 0.7.0
zig 0.7.1
zig 0.8.0
zig 0.9.0
zig trunk
Options
Source code
const Builder = @import("std").build.Builder; pub fn build(b: *Builder) void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options // for restricting supported target set are available. const target = b.standardTargetOptions(.{}); // Standard release options allow the person running `zig build` to select // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. const mode = b.standardReleaseOptions(); // We have the following project structure // // app.zig // ^ // | // main.c // // First, we compile the zig layer to an object file const zig_layer = b.addObject("zig_layer", "src/engine/app/app.zig"); zig_layer.linkSystemLibrary("c"); zig_layer.addIncludeDir("src/engine/app/"); zig_layer.setTarget(target); zig_layer.setBuildMode(mode); //zig_layer.install(); // It is the first build step b.default_step.dependOn(&zig_layer.step); // still not quite sure what run does //const zig_layer_run = zig_layer.run(); // Then we compile the c layer, with the sokol-defined main(), calling the // zig_layer.o const c_main = b.addExecutable("untitled_game", null); c_main.addCSourceFile("src/engine/app/main.c", &[_][]const u8{"-std=c99"}); c_main.linkSystemLibrary("c"); c_main.addIncludeDir("src/engine/app/"); c_main.addObject(zig_layer); c_main.setTarget(target); c_main.setBuildMode(mode); //c_main.install(); // It is the second build step, relying on the zig_layer to be .o'ified // first //c_main.step.dependOn(&zig_layer_run.step); // still not quite sure what run does const c_main_run = c_main.run(); //c_main_run.step.dependOn(b.getInstallStep()); // Defines the "zig run" command? const run_app_step = b.step("run", "Run the app"); run_app_step.dependOn(&c_main_run.step); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
About the author
Statistics
Changelog
Version tree