authorgravatar for jagt@live.comjagt <jagt@live.com> 2023-03-12 18:45:53+08:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-30 22:56:33+03:00
logc964e10821c417ceb7d0efcf1625d67484e734f7
treed6efa170a27c050922f6b3d71acf276115eb7353
parent64214b1ca6a295af8521ed6fb3be5a3244a42564

docgen: add `additional_option` token; fix wasm-freestanding example

- Fix usage string `--skip-code-test` to `--skip-code-tests`. - Added a token `{#additonal_option|-rdynamic#}` which introduce arbitrary flag to `build-exe/obj/lib` example. - Fix wasm freestanding example, it now needs explicit export symbols to work.

2 files changed, 23 insertions(+), 2 deletions(-)

doc/docgen.zig+22-2
......@@ -18,13 +18,13 @@ const tmp_dir_name = "docgen_tmp";
1818const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
1919
2020const usage =
21 \\Usage: docgen [--zig] [--skip-code-test] input output"
21 \\Usage: docgen [--zig] [--skip-code-tests] input output"
2222 \\
2323 \\ Generates an HTML document from a docgen template.
2424 \\
2525 \\Options:
2626 \\ -h, --help Print this help and exit
27 \\ --skip-code-test Skip the doctests
27 \\ --skip-code-tests Skip the doctests
2828 \\
2929;
3030
......@@ -329,6 +329,7 @@ const Code = struct {
329329 link_mode: ?std.builtin.LinkMode,
330330 disable_cache: bool,
331331 verbose_cimport: bool,
332 additional_options: []const []const u8,
332333
333334 const Id = union(enum) {
334335 Test,
......@@ -596,6 +597,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
596597 var disable_cache = false;
597598 var verbose_cimport = false;
598599 var backend_stage1 = false;
600 var additional_options = std.ArrayList([]const u8).init(allocator);
601 defer additional_options.deinit();
599602
600603 const source_token = while (true) {
601604 const content_tok = try eatToken(tokenizer, Token.Id.Content);
......@@ -630,6 +633,10 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
630633 link_mode = .Dynamic;
631634 } else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
632635 backend_stage1 = true;
636 } else if (mem.eql(u8, end_tag_name, "additonal_option")) {
637 _ = try eatToken(tokenizer, Token.Id.Separator);
638 const option = try eatToken(tokenizer, Token.Id.TagContent);
639 try additional_options.append(tokenizer.buffer[option.start..option.end]);
633640 } else if (mem.eql(u8, end_tag_name, "code_end")) {
634641 _ = try eatToken(tokenizer, Token.Id.BracketClose);
635642 break content_tok;
......@@ -657,6 +664,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
657664 .link_mode = link_mode,
658665 .disable_cache = disable_cache,
659666 .verbose_cimport = verbose_cimport,
667 .additional_options = try additional_options.toOwnedSlice(),
660668 },
661669 });
662670 tokenizer.code_node_count += 1;
......@@ -1418,6 +1426,10 @@ fn genHtml(
14181426 try build_args.append("--verbose-cimport");
14191427 try shell_out.print("--verbose-cimport ", .{});
14201428 }
1429 for (code.additional_options) |option| {
1430 try build_args.append(option);
1431 try shell_out.print("{s} ", .{option});
1432 }
14211433
14221434 try shell_out.print("\n", .{});
14231435
......@@ -1729,6 +1741,10 @@ fn genHtml(
17291741 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
17301742 try shell_out.print("-target {s} ", .{triple});
17311743 }
1744 for (code.additional_options) |option| {
1745 try build_args.append(option);
1746 try shell_out.print("{s} ", .{option});
1747 }
17321748
17331749 if (maybe_error_match) |error_match| {
17341750 const result = try ChildProcess.exec(.{
......@@ -1811,6 +1827,10 @@ fn genHtml(
18111827 },
18121828 }
18131829 }
1830 for (code.additional_options) |option| {
1831 try test_args.append(option);
1832 try shell_out.print("{s} ", .{option});
1833 }
18141834 const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
18151835 const escaped_stderr = try escapeHtml(allocator, result.stderr);
18161836 const escaped_stdout = try escapeHtml(allocator, result.stdout);
doc/langref.html.in+1
......@@ -11149,6 +11149,7 @@ all your base are belong to us{#end_shell_samp#}
1114911149 {#code_begin|lib|math#}
1115011150 {#target_wasm#}
1115111151 {#link_mode_dynamic#}
11152 {#additonal_option|-rdynamic#}
1115211153extern fn print(i32) void;
1115311154
1115411155export fn add(a: i32, b: i32) void {