diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-17 17:08:56 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-17 17:11:18 -0400 |
| commit | 4c6f1e614a204293732004ef844e8bb057bdc212 (patch) | |
| tree | 5b9ce7cf5888d2122406b79001325ed770d5d872 /std | |
| parent | 9c9eefc841b577f646a54e74c8970e074162b594 (diff) | |
| download | zig-4c6f1e614a204293732004ef844e8bb057bdc212.tar.gz zig-4c6f1e614a204293732004ef844e8bb057bdc212.zip | |
remove `zig build --init`. add `zig init-lib` and `zig init-exe`
init-lib creates a working static library with tests, and
init-exe creates a working hello world with a `run` target.
both now have test coverage with the new "cli tests" file.
closes #1035
Diffstat (limited to 'std')
| -rw-r--r-- | std/special/build_file_template.zig | 10 | ||||
| -rw-r--r-- | std/special/init-exe/build.zig | 15 | ||||
| -rw-r--r-- | std/special/init-exe/src/main.zig | 5 | ||||
| -rw-r--r-- | std/special/init-lib/build.zig | 16 | ||||
| -rw-r--r-- | std/special/init-lib/src/main.zig | 10 |
5 files changed, 46 insertions, 10 deletions
diff --git a/std/special/build_file_template.zig b/std/special/build_file_template.zig deleted file mode 100644 index 11e9647698..0000000000 --- a/std/special/build_file_template.zig +++ /dev/null @@ -1,10 +0,0 @@ -const Builder = @import("std").build.Builder; - -pub fn build(b: *Builder) void { - const mode = b.standardReleaseOptions(); - const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig"); - exe.setBuildMode(mode); - - b.default_step.dependOn(&exe.step); - b.installArtifact(exe); -} diff --git a/std/special/init-exe/build.zig b/std/special/init-exe/build.zig new file mode 100644 index 0000000000..21a2600562 --- /dev/null +++ b/std/special/init-exe/build.zig @@ -0,0 +1,15 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + const exe = b.addExecutable("$", "src/main.zig"); + exe.setBuildMode(mode); + + const run_step = b.step("run", "Run the app"); + const run_cmd = b.addCommand(".", b.env_map, [][]const u8{exe.getOutputPath()}); + run_step.dependOn(&run_cmd.step); + run_cmd.step.dependOn(&exe.step); + + b.default_step.dependOn(&exe.step); + b.installArtifact(exe); +} diff --git a/std/special/init-exe/src/main.zig b/std/special/init-exe/src/main.zig new file mode 100644 index 0000000000..71034d1bfa --- /dev/null +++ b/std/special/init-exe/src/main.zig @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn main() error!void { + std.debug.warn("All your base are belong to us.\n"); +} diff --git a/std/special/init-lib/build.zig b/std/special/init-lib/build.zig new file mode 100644 index 0000000000..9557ccf10d --- /dev/null +++ b/std/special/init-lib/build.zig @@ -0,0 +1,16 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + const lib = b.addStaticLibrary("$", "src/main.zig"); + lib.setBuildMode(mode); + + var main_tests = b.addTest("src/main.zig"); + main_tests.setBuildMode(mode); + + const test_step = b.step("test", "Run library tests"); + test_step.dependOn(&main_tests.step); + + b.default_step.dependOn(&lib.step); + b.installArtifact(lib); +} diff --git a/std/special/init-lib/src/main.zig b/std/special/init-lib/src/main.zig new file mode 100644 index 0000000000..27fdeb2030 --- /dev/null +++ b/std/special/init-lib/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const assertOrPanic = std.debug.assertOrPanic; + +export fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + assertOrPanic(add(3, 7) == 10); +} |
