| author | |
| committer | |
| log | 67904e925d2b33c48dda3d4ddaf158328964dc2e |
| tree | 35c505758915b7a2473dec2b7165a4fc4c2d5b38 |
| parent | ea516f0e81d055e0d7504eff36dfde694831bec1 |
4 files changed, 29 insertions(+), 26 deletions(-)
lib/init/build.zig+3-3| ... | ... | @@ -42,14 +42,14 @@ pub fn build(b: *std.Build) void { |
| 42 | 42 | // Modules can depend on one another using the `std.Build.Module.addImport` function. |
| 43 | 43 | // This is what allows Zig source code to use `@import("foo")` where 'foo' is not a |
| 44 | 44 | // file path. In this case, we set up `exe_mod` to import `lib_mod`. |
| 45 | exe_mod.addImport("$n_lib", lib_mod); | |
| 45 | exe_mod.addImport(".NAME_lib", lib_mod); | |
| 46 | 46 | |
| 47 | 47 | // Now, we will create a static library based on the module we created above. |
| 48 | 48 | // This creates a `std.Build.Step.Compile`, which is the build step responsible |
| 49 | 49 | // for actually invoking the compiler. |
| 50 | 50 | const lib = b.addLibrary(.{ |
| 51 | 51 | .linkage = .static, |
| 52 | .name = "$n", | |
| 52 | .name = ".NAME", | |
| 53 | 53 | .root_module = lib_mod, |
| 54 | 54 | }); |
| 55 | 55 | |
| ... | ... | @@ -61,7 +61,7 @@ pub fn build(b: *std.Build) void { |
| 61 | 61 | // This creates another `std.Build.Step.Compile`, but this one builds an executable |
| 62 | 62 | // rather than a static library. |
| 63 | 63 | const exe = b.addExecutable(.{ |
| 64 | .name = "$n", | |
| 64 | .name = ".NAME", | |
| 65 | 65 | .root_module = exe_mod, |
| 66 | 66 | }); |
| 67 | 67 |
lib/init/build.zig.zon+3-3| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | // |
| 7 | 7 | // It is redundant to include "zig" in this name because it is already |
| 8 | 8 | // within the Zig package namespace. |
| 9 | .name = .$n, | |
| 9 | .name = .LITNAME, | |
| 10 | 10 | |
| 11 | 11 | // This is a [Semantic Version](https://semver.org/). |
| 12 | 12 | // In a future version of Zig it will be used for package deduplication. |
| ... | ... | @@ -24,11 +24,11 @@ |
| 24 | 24 | // original project's identity. Thus it is recommended to leave the comment |
| 25 | 25 | // on the following line intact, so that it shows up in code reviews that |
| 26 | 26 | // modify the field. |
| 27 | .nonce = $i, // Changing this has security and trust implications. | |
| 27 | .nonce = .NONCE, // Changing this has security and trust implications. | |
| 28 | 28 | |
| 29 | 29 | // Tracks the earliest Zig version that the package considers to be a |
| 30 | 30 | // supported use case. |
| 31 | .minimum_zig_version = "$v", | |
| 31 | .minimum_zig_version = ".ZIGVER", | |
| 32 | 32 | |
| 33 | 33 | // This field is optional. |
| 34 | 34 | // This is currently advisory only; Zig does not yet do anything |
lib/init/src/main.zig+1-1| ... | ... | @@ -43,4 +43,4 @@ test "fuzz example" { |
| 43 | 43 | const std = @import("std"); |
| 44 | 44 | |
| 45 | 45 | /// This imports the separate module containing `root.zig`. Take a look in `build.zig` for details. |
| 46 | const lib = @import("$n_lib"); | |
| 46 | const lib = @import(".NAME_lib"); |
src/main.zig+22-19| ... | ... | @@ -7543,28 +7543,31 @@ const Templates = struct { |
| 7543 | 7543 | }; |
| 7544 | 7544 | templates.buffer.clearRetainingCapacity(); |
| 7545 | 7545 | try templates.buffer.ensureUnusedCapacity(contents.len); |
| 7546 | var state: enum { start, dollar } = .start; | |
| 7547 | for (contents) |c| switch (state) { | |
| 7548 | .start => switch (c) { | |
| 7549 | '$' => state = .dollar, | |
| 7550 | else => try templates.buffer.append(c), | |
| 7551 | }, | |
| 7552 | .dollar => switch (c) { | |
| 7553 | 'n' => { | |
| 7546 | var i: usize = 0; | |
| 7547 | while (i < contents.len) { | |
| 7548 | if (contents[i] == '.') { | |
| 7549 | if (std.mem.startsWith(u8, contents[i..], ".LITNAME")) { | |
| 7550 | try templates.buffer.append('.'); | |
| 7554 | 7551 | try templates.buffer.appendSlice(root_name); |
| 7555 | state = .start; | |
| 7556 | }, | |
| 7557 | 'i' => { | |
| 7552 | i += ".LITNAME".len; | |
| 7553 | continue; | |
| 7554 | } else if (std.mem.startsWith(u8, contents[i..], ".NAME")) { | |
| 7555 | try templates.buffer.appendSlice(root_name); | |
| 7556 | i += ".NAME".len; | |
| 7557 | continue; | |
| 7558 | } else if (std.mem.startsWith(u8, contents[i..], ".NONCE")) { | |
| 7558 | 7559 | try templates.buffer.writer().print("0x{x}", .{nonce.int()}); |
| 7559 | state = .start; | |
| 7560 | }, | |
| 7561 | 'v' => { | |
| 7560 | i += ".NONCE".len; | |
| 7561 | continue; | |
| 7562 | } else if (std.mem.startsWith(u8, contents[i..], ".ZIGVER")) { | |
| 7562 | 7563 | try templates.buffer.appendSlice(build_options.version); |
| 7563 | state = .start; | |
| 7564 | }, | |
| 7565 | else => fatal("unknown substitution: ${c}", .{c}), | |
| 7566 | }, | |
| 7567 | }; | |
| 7564 | i += ".ZIGVER".len; | |
| 7565 | continue; | |
| 7566 | } | |
| 7567 | } | |
| 7568 | try templates.buffer.append(contents[i]); | |
| 7569 | i += 1; | |
| 7570 | } | |
| 7568 | 7571 | |
| 7569 | 7572 | return out_dir.writeFile(.{ |
| 7570 | 7573 | .sub_path = template_path, |