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