-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ZigPlanner] Add support for shell and build (#141)
## Summary Adds basic support for shell and build. Build Size optimization: - If I include the `zig` nix package in the runtimePackages, then the image size is really large (700MB) - But I believe the zig executable is standalone ziglang/zig#3660 (comment) - So, I get the zig-executable's name by: - parsing the `build.zig` file (so unfortunate) to find the `addExecutable` line - fallback: if I fail to find exactly one `addExecutable`, then I fallback to installing the `zig` nix package and invoking `zig build run` - the image size is 22MB ## How was it tested? shell: in the testcase folder: ``` > devbox shell (devbox)> zig build run # see output info: All your codebase are belong to us. ``` Don't be alarmed! Just a printout. build: ``` > devbox build > docker run devbox info: All your codebase are belong to us. ```
- Loading branch information
Showing
8 changed files
with
154 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
To create a project, I followed the instructions at: | ||
https://ziglang.org/learn/getting-started/#installing-zig | ||
|
||
``` | ||
mkdir <folder> | ||
cd <folder> | ||
zig init-exe # executable gets the folder name | ||
# build the project | ||
zig build install | ||
# run the project | ||
zig build run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
zig-cache/ | ||
zig-out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.build.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(); | ||
|
||
const exe = b.addExecutable("zig-hello-world", "src/main.zig"); | ||
exe.setTarget(target); | ||
exe.setBuildMode(mode); | ||
exe.install(); | ||
|
||
const run_cmd = exe.run(); | ||
run_cmd.step.dependOn(b.getInstallStep()); | ||
if (b.args) |args| { | ||
run_cmd.addArgs(args); | ||
} | ||
|
||
const run_step = b.step("run", "Run the app"); | ||
run_step.dependOn(&run_cmd.step); | ||
|
||
const exe_tests = b.addTest("src/main.zig"); | ||
exe_tests.setTarget(target); | ||
exe_tests.setBuildMode(mode); | ||
|
||
const test_step = b.step("test", "Run unit tests"); | ||
test_step.dependOn(&exe_tests.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"packages": [], | ||
"shell": { | ||
"init_hook": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"dev_packages": [ | ||
"zig" | ||
], | ||
"runtime_packages": [], | ||
"install_stage": { | ||
"command": "" | ||
}, | ||
"build_stage": { | ||
"command": "zig build install", | ||
"input_files": [ | ||
"." | ||
] | ||
}, | ||
"start_stage": { | ||
"command": "./zig-hello-world", | ||
"input_files": [ | ||
"./zig-out/bin/" | ||
] | ||
}, | ||
"definitions": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const std = @import("std"); | ||
|
||
pub fn main() anyerror!void { | ||
std.log.info("Hello World! You are running zig.", .{}); | ||
} | ||
|
||
test "basic test" { | ||
try std.testing.expectEqual(10, 3 + 7); | ||
} |