| ... | ... | @@ -325,7 +325,6 @@ const Code = struct { |
| 325 | 325 | link_objects: []const []const u8, |
| 326 | 326 | target_str: ?[]const u8, |
| 327 | 327 | link_libc: bool, |
| 328 | | backend_stage1: bool, |
| 329 | 328 | link_mode: ?std.builtin.LinkMode, |
| 330 | 329 | disable_cache: bool, |
| 331 | 330 | verbose_cimport: bool, |
| ... | ... | @@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 596 | 595 | var link_mode: ?std.builtin.LinkMode = null; |
| 597 | 596 | var disable_cache = false; |
| 598 | 597 | var verbose_cimport = false; |
| 599 | | var backend_stage1 = false; |
| 600 | 598 | var additional_options = std.ArrayList([]const u8).init(allocator); |
| 601 | 599 | defer additional_options.deinit(); |
| 602 | 600 | |
| ... | ... | @@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 631 | 629 | link_libc = true; |
| 632 | 630 | } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { |
| 633 | 631 | link_mode = .Dynamic; |
| 634 | | } else if (mem.eql(u8, end_tag_name, "backend_stage1")) { |
| 635 | | backend_stage1 = true; |
| 636 | 632 | } else if (mem.eql(u8, end_tag_name, "additonal_option")) { |
| 637 | 633 | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 638 | 634 | const option = try eatToken(tokenizer, Token.Id.TagContent); |
| ... | ... | @@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 660 | 656 | .link_objects = try link_objects.toOwnedSlice(), |
| 661 | 657 | .target_str = target_str, |
| 662 | 658 | .link_libc = link_libc, |
| 663 | | .backend_stage1 = backend_stage1, |
| 664 | 659 | .link_mode = link_mode, |
| 665 | 660 | .disable_cache = disable_cache, |
| 666 | 661 | .verbose_cimport = verbose_cimport, |
| ... | ... | @@ -1380,10 +1375,10 @@ fn genHtml( |
| 1380 | 1375 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1381 | 1376 | defer build_args.deinit(); |
| 1382 | 1377 | try build_args.appendSlice(&[_][]const u8{ |
| 1383 | | zig_exe, "build-exe", |
| 1384 | | "--name", code.name, |
| 1385 | | "--color", "on", |
| 1386 | | "--enable-cache", tmp_source_file_name, |
| 1378 | zig_exe, "build-exe", |
| 1379 | "--name", code.name, |
| 1380 | "--color", "on", |
| 1381 | name_plus_ext, |
| 1387 | 1382 | }); |
| 1388 | 1383 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1389 | 1384 | try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| ... | ... | @@ -1400,21 +1395,13 @@ fn genHtml( |
| 1400 | 1395 | } |
| 1401 | 1396 | for (code.link_objects) |link_object| { |
| 1402 | 1397 | const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext }); |
| 1403 | | const full_path_object = try fs.path.join( |
| 1404 | | allocator, |
| 1405 | | &[_][]const u8{ tmp_dir_name, name_with_ext }, |
| 1406 | | ); |
| 1407 | | try build_args.append(full_path_object); |
| 1398 | try build_args.append(name_with_ext); |
| 1408 | 1399 | try shell_out.print("{s} ", .{name_with_ext}); |
| 1409 | 1400 | } |
| 1410 | 1401 | if (code.link_libc) { |
| 1411 | 1402 | try build_args.append("-lc"); |
| 1412 | 1403 | try shell_out.print("-lc ", .{}); |
| 1413 | 1404 | } |
| 1414 | | if (code.backend_stage1) { |
| 1415 | | try build_args.append("-fstage1"); |
| 1416 | | try shell_out.print("-fstage1", .{}); |
| 1417 | | } |
| 1418 | 1405 | const target = try std.zig.CrossTarget.parse(.{ |
| 1419 | 1406 | .arch_os_abi = code.target_str orelse "native", |
| 1420 | 1407 | }); |
| ... | ... | @@ -1461,7 +1448,7 @@ fn genHtml( |
| 1461 | 1448 | try shell_out.writeAll(colored_stderr); |
| 1462 | 1449 | break :code_block; |
| 1463 | 1450 | } |
| 1464 | | const exec_result = exec(allocator, &env_map, build_args.items) catch |
| 1451 | const exec_result = exec(allocator, &env_map, tmp_dir_name, build_args.items) catch |
| 1465 | 1452 | return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1466 | 1453 | |
| 1467 | 1454 | if (code.verbose_cimport) { |
| ... | ... | @@ -1480,15 +1467,10 @@ fn genHtml( |
| 1480 | 1467 | } |
| 1481 | 1468 | } |
| 1482 | 1469 | |
| 1483 | | const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n"); |
| 1484 | | const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{ |
| 1470 | const path_to_exe = try std.fmt.allocPrint(allocator, "./{s}{s}", .{ |
| 1485 | 1471 | code.name, |
| 1486 | 1472 | target.exeFileExt(), |
| 1487 | 1473 | }); |
| 1488 | | const path_to_exe = try fs.path.join(allocator, &[_][]const u8{ |
| 1489 | | path_to_exe_dir, |
| 1490 | | path_to_exe_basename, |
| 1491 | | }); |
| 1492 | 1474 | const run_args = &[_][]const u8{path_to_exe}; |
| 1493 | 1475 | |
| 1494 | 1476 | var exited_with_signal = false; |
| ... | ... | @@ -1498,6 +1480,7 @@ fn genHtml( |
| 1498 | 1480 | .allocator = allocator, |
| 1499 | 1481 | .argv = run_args, |
| 1500 | 1482 | .env_map = &env_map, |
| 1483 | .cwd = tmp_dir_name, |
| 1501 | 1484 | .max_output_bytes = max_doc_file_size, |
| 1502 | 1485 | }); |
| 1503 | 1486 | switch (result.term) { |
| ... | ... | @@ -1514,7 +1497,7 @@ fn genHtml( |
| 1514 | 1497 | } |
| 1515 | 1498 | break :blk result; |
| 1516 | 1499 | } else blk: { |
| 1517 | | break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{}); |
| 1500 | break :blk exec(allocator, &env_map, tmp_dir_name, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{}); |
| 1518 | 1501 | }; |
| 1519 | 1502 | |
| 1520 | 1503 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| ... | ... | @@ -1555,10 +1538,6 @@ fn genHtml( |
| 1555 | 1538 | try test_args.append("-lc"); |
| 1556 | 1539 | try shell_out.print("-lc ", .{}); |
| 1557 | 1540 | } |
| 1558 | | if (code.backend_stage1) { |
| 1559 | | try test_args.append("-fstage1"); |
| 1560 | | try shell_out.print("-fstage1", .{}); |
| 1561 | | } |
| 1562 | 1541 | if (code.target_str) |triple| { |
| 1563 | 1542 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1564 | 1543 | try shell_out.print("-target {s} ", .{triple}); |
| ... | ... | @@ -1579,7 +1558,7 @@ fn genHtml( |
| 1579 | 1558 | }, |
| 1580 | 1559 | } |
| 1581 | 1560 | } |
| 1582 | | const result = exec(allocator, &env_map, test_args.items) catch |
| 1561 | const result = exec(allocator, &env_map, null, test_args.items) catch |
| 1583 | 1562 | return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1584 | 1563 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1585 | 1564 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| ... | ... | @@ -1610,10 +1589,6 @@ fn genHtml( |
| 1610 | 1589 | try test_args.append("-lc"); |
| 1611 | 1590 | try shell_out.print("-lc ", .{}); |
| 1612 | 1591 | } |
| 1613 | | if (code.backend_stage1) { |
| 1614 | | try test_args.append("-fstage1"); |
| 1615 | | try shell_out.print("-fstage1", .{}); |
| 1616 | | } |
| 1617 | 1592 | const result = try ChildProcess.exec(.{ |
| 1618 | 1593 | .allocator = allocator, |
| 1619 | 1594 | .argv = test_args.items, |
| ... | ... | @@ -1778,7 +1753,7 @@ fn genHtml( |
| 1778 | 1753 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1779 | 1754 | try shell_out.print("\n{s} ", .{colored_stderr}); |
| 1780 | 1755 | } else { |
| 1781 | | _ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1756 | _ = exec(allocator, &env_map, null, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1782 | 1757 | } |
| 1783 | 1758 | try shell_out.writeAll("\n"); |
| 1784 | 1759 | }, |
| ... | ... | @@ -1831,7 +1806,7 @@ fn genHtml( |
| 1831 | 1806 | try test_args.append(option); |
| 1832 | 1807 | try shell_out.print("{s} ", .{option}); |
| 1833 | 1808 | } |
| 1834 | | const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1809 | const result = exec(allocator, &env_map, null, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1835 | 1810 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1836 | 1811 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1837 | 1812 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); |
| ... | ... | @@ -1846,11 +1821,17 @@ fn genHtml( |
| 1846 | 1821 | } |
| 1847 | 1822 | } |
| 1848 | 1823 | |
| 1849 | | fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult { |
| 1824 | fn exec( |
| 1825 | allocator: Allocator, |
| 1826 | env_map: *process.EnvMap, |
| 1827 | cwd: ?[]const u8, |
| 1828 | args: []const []const u8, |
| 1829 | ) !ChildProcess.ExecResult { |
| 1850 | 1830 | const result = try ChildProcess.exec(.{ |
| 1851 | 1831 | .allocator = allocator, |
| 1852 | 1832 | .argv = args, |
| 1853 | 1833 | .env_map = env_map, |
| 1834 | .cwd = cwd, |
| 1854 | 1835 | .max_output_bytes = max_doc_file_size, |
| 1855 | 1836 | }); |
| 1856 | 1837 | switch (result.term) { |
| ... | ... | @@ -1877,12 +1858,12 @@ fn getBuiltinCode( |
| 1877 | 1858 | opt_zig_lib_dir: ?[]const u8, |
| 1878 | 1859 | ) ![]const u8 { |
| 1879 | 1860 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1880 | | const result = try exec(allocator, env_map, &.{ |
| 1861 | const result = try exec(allocator, env_map, null, &.{ |
| 1881 | 1862 | zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir, |
| 1882 | 1863 | }); |
| 1883 | 1864 | return result.stdout; |
| 1884 | 1865 | } else { |
| 1885 | | const result = try exec(allocator, env_map, &.{ |
| 1866 | const result = try exec(allocator, env_map, null, &.{ |
| 1886 | 1867 | zig_exe, "build-obj", "--show-builtin", |
| 1887 | 1868 | }); |
| 1888 | 1869 | return result.stdout; |