| ... | @@ -325,7 +325,6 @@ const Code = struct { | ... | @@ -325,7 +325,6 @@ const Code = struct { |
| 325 | link_objects: []const []const u8, | 325 | link_objects: []const []const u8, |
| 326 | target_str: ?[]const u8, | 326 | target_str: ?[]const u8, |
| 327 | link_libc: bool, | 327 | link_libc: bool, |
| 328 | backend_stage1: bool, | | |
| 329 | link_mode: ?std.builtin.LinkMode, | 328 | link_mode: ?std.builtin.LinkMode, |
| 330 | disable_cache: bool, | 329 | disable_cache: bool, |
| 331 | verbose_cimport: bool, | 330 | verbose_cimport: bool, |
| ... | @@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 596 | var link_mode: ?std.builtin.LinkMode = null; | 595 | var link_mode: ?std.builtin.LinkMode = null; |
| 597 | var disable_cache = false; | 596 | var disable_cache = false; |
| 598 | var verbose_cimport = false; | 597 | var verbose_cimport = false; |
| 599 | var backend_stage1 = false; | | |
| 600 | var additional_options = std.ArrayList([]const u8).init(allocator); | 598 | var additional_options = std.ArrayList([]const u8).init(allocator); |
| 601 | defer additional_options.deinit(); | 599 | defer additional_options.deinit(); |
| 602 | | 600 | |
| ... | @@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 631 | link_libc = true; | 629 | link_libc = true; |
| 632 | } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { | 630 | } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { |
| 633 | link_mode = .Dynamic; | 631 | link_mode = .Dynamic; |
| 634 | } else if (mem.eql(u8, end_tag_name, "backend_stage1")) { | | |
| 635 | backend_stage1 = true; | | |
| 636 | } else if (mem.eql(u8, end_tag_name, "additonal_option")) { | 632 | } else if (mem.eql(u8, end_tag_name, "additonal_option")) { |
| 637 | _ = try eatToken(tokenizer, Token.Id.Separator); | 633 | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 638 | const option = try eatToken(tokenizer, Token.Id.TagContent); | 634 | const option = try eatToken(tokenizer, Token.Id.TagContent); |
| ... | @@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 660 | .link_objects = try link_objects.toOwnedSlice(), | 656 | .link_objects = try link_objects.toOwnedSlice(), |
| 661 | .target_str = target_str, | 657 | .target_str = target_str, |
| 662 | .link_libc = link_libc, | 658 | .link_libc = link_libc, |
| 663 | .backend_stage1 = backend_stage1, | | |
| 664 | .link_mode = link_mode, | 659 | .link_mode = link_mode, |
| 665 | .disable_cache = disable_cache, | 660 | .disable_cache = disable_cache, |
| 666 | .verbose_cimport = verbose_cimport, | 661 | .verbose_cimport = verbose_cimport, |
| ... | @@ -1380,10 +1375,10 @@ fn genHtml( | ... | @@ -1380,10 +1375,10 @@ fn genHtml( |
| 1380 | var build_args = std.ArrayList([]const u8).init(allocator); | 1375 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1381 | defer build_args.deinit(); | 1376 | defer build_args.deinit(); |
| 1382 | try build_args.appendSlice(&[_][]const u8{ | 1377 | try build_args.appendSlice(&[_][]const u8{ |
| 1383 | zig_exe, "build-exe", | 1378 | zig_exe, "build-exe", |
| 1384 | "--name", code.name, | 1379 | "--name", code.name, |
| 1385 | "--color", "on", | 1380 | "--color", "on", |
| 1386 | "--enable-cache", tmp_source_file_name, | 1381 | name_plus_ext, |
| 1387 | }); | 1382 | }); |
| 1388 | if (opt_zig_lib_dir) |zig_lib_dir| { | 1383 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1389 | try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); | 1384 | try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| ... | @@ -1400,21 +1395,13 @@ fn genHtml( | ... | @@ -1400,21 +1395,13 @@ fn genHtml( |
| 1400 | } | 1395 | } |
| 1401 | for (code.link_objects) |link_object| { | 1396 | for (code.link_objects) |link_object| { |
| 1402 | const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext }); | 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( | 1398 | try build_args.append(name_with_ext); |
| 1404 | allocator, | | |
| 1405 | &[_][]const u8{ tmp_dir_name, name_with_ext }, | | |
| 1406 | ); | | |
| 1407 | try build_args.append(full_path_object); | | |
| 1408 | try shell_out.print("{s} ", .{name_with_ext}); | 1399 | try shell_out.print("{s} ", .{name_with_ext}); |
| 1409 | } | 1400 | } |
| 1410 | if (code.link_libc) { | 1401 | if (code.link_libc) { |
| 1411 | try build_args.append("-lc"); | 1402 | try build_args.append("-lc"); |
| 1412 | try shell_out.print("-lc ", .{}); | 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 | const target = try std.zig.CrossTarget.parse(.{ | 1405 | const target = try std.zig.CrossTarget.parse(.{ |
| 1419 | .arch_os_abi = code.target_str orelse "native", | 1406 | .arch_os_abi = code.target_str orelse "native", |
| 1420 | }); | 1407 | }); |
| ... | @@ -1461,7 +1448,7 @@ fn genHtml( | ... | @@ -1461,7 +1448,7 @@ fn genHtml( |
| 1461 | try shell_out.writeAll(colored_stderr); | 1448 | try shell_out.writeAll(colored_stderr); |
| 1462 | break :code_block; | 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 | return parseError(tokenizer, code.source_token, "example failed to compile", .{}); | 1452 | return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1466 | | 1453 | |
| 1467 | if (code.verbose_cimport) { | 1454 | if (code.verbose_cimport) { |
| ... | @@ -1480,15 +1467,10 @@ fn genHtml( | ... | @@ -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"); | 1470 | const path_to_exe = try std.fmt.allocPrint(allocator, "./{s}{s}", .{ |
| 1484 | const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{ | | |
| 1485 | code.name, | 1471 | code.name, |
| 1486 | target.exeFileExt(), | 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 | const run_args = &[_][]const u8{path_to_exe}; | 1474 | const run_args = &[_][]const u8{path_to_exe}; |
| 1493 | | 1475 | |
| 1494 | var exited_with_signal = false; | 1476 | var exited_with_signal = false; |
| ... | @@ -1498,6 +1480,7 @@ fn genHtml( | ... | @@ -1498,6 +1480,7 @@ fn genHtml( |
| 1498 | .allocator = allocator, | 1480 | .allocator = allocator, |
| 1499 | .argv = run_args, | 1481 | .argv = run_args, |
| 1500 | .env_map = &env_map, | 1482 | .env_map = &env_map, |
| | 1483 | .cwd = tmp_dir_name, |
| 1501 | .max_output_bytes = max_doc_file_size, | 1484 | .max_output_bytes = max_doc_file_size, |
| 1502 | }); | 1485 | }); |
| 1503 | switch (result.term) { | 1486 | switch (result.term) { |
| ... | @@ -1514,7 +1497,7 @@ fn genHtml( | ... | @@ -1514,7 +1497,7 @@ fn genHtml( |
| 1514 | } | 1497 | } |
| 1515 | break :blk result; | 1498 | break :blk result; |
| 1516 | } else blk: { | 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 | const escaped_stderr = try escapeHtml(allocator, result.stderr); | 1503 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| ... | @@ -1555,10 +1538,6 @@ fn genHtml( | ... | @@ -1555,10 +1538,6 @@ fn genHtml( |
| 1555 | try test_args.append("-lc"); | 1538 | try test_args.append("-lc"); |
| 1556 | try shell_out.print("-lc ", .{}); | 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 | if (code.target_str) |triple| { | 1541 | if (code.target_str) |triple| { |
| 1563 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); | 1542 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1564 | try shell_out.print("-target {s} ", .{triple}); | 1543 | try shell_out.print("-target {s} ", .{triple}); |
| ... | @@ -1579,7 +1558,7 @@ fn genHtml( | ... | @@ -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 | return parseError(tokenizer, code.source_token, "test failed", .{}); | 1562 | return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1584 | const escaped_stderr = try escapeHtml(allocator, result.stderr); | 1563 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1585 | const escaped_stdout = try escapeHtml(allocator, result.stdout); | 1564 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| ... | @@ -1610,10 +1589,6 @@ fn genHtml( | ... | @@ -1610,10 +1589,6 @@ fn genHtml( |
| 1610 | try test_args.append("-lc"); | 1589 | try test_args.append("-lc"); |
| 1611 | try shell_out.print("-lc ", .{}); | 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 | const result = try ChildProcess.exec(.{ | 1592 | const result = try ChildProcess.exec(.{ |
| 1618 | .allocator = allocator, | 1593 | .allocator = allocator, |
| 1619 | .argv = test_args.items, | 1594 | .argv = test_args.items, |
| ... | @@ -1778,7 +1753,7 @@ fn genHtml( | ... | @@ -1778,7 +1753,7 @@ fn genHtml( |
| 1778 | const colored_stderr = try termColor(allocator, escaped_stderr); | 1753 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1779 | try shell_out.print("\n{s} ", .{colored_stderr}); | 1754 | try shell_out.print("\n{s} ", .{colored_stderr}); |
| 1780 | } else { | 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 | try shell_out.writeAll("\n"); | 1758 | try shell_out.writeAll("\n"); |
| 1784 | }, | 1759 | }, |
| ... | @@ -1831,7 +1806,7 @@ fn genHtml( | ... | @@ -1831,7 +1806,7 @@ fn genHtml( |
| 1831 | try test_args.append(option); | 1806 | try test_args.append(option); |
| 1832 | try shell_out.print("{s} ", .{option}); | 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 | const escaped_stderr = try escapeHtml(allocator, result.stderr); | 1810 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1836 | const escaped_stdout = try escapeHtml(allocator, result.stdout); | 1811 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1837 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); | 1812 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); |
| ... | @@ -1846,11 +1821,17 @@ fn genHtml( | ... | @@ -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 | const result = try ChildProcess.exec(.{ | 1830 | const result = try ChildProcess.exec(.{ |
| 1851 | .allocator = allocator, | 1831 | .allocator = allocator, |
| 1852 | .argv = args, | 1832 | .argv = args, |
| 1853 | .env_map = env_map, | 1833 | .env_map = env_map, |
| | 1834 | .cwd = cwd, |
| 1854 | .max_output_bytes = max_doc_file_size, | 1835 | .max_output_bytes = max_doc_file_size, |
| 1855 | }); | 1836 | }); |
| 1856 | switch (result.term) { | 1837 | switch (result.term) { |
| ... | @@ -1877,12 +1858,12 @@ fn getBuiltinCode( | ... | @@ -1877,12 +1858,12 @@ fn getBuiltinCode( |
| 1877 | opt_zig_lib_dir: ?[]const u8, | 1858 | opt_zig_lib_dir: ?[]const u8, |
| 1878 | ) ![]const u8 { | 1859 | ) ![]const u8 { |
| 1879 | if (opt_zig_lib_dir) |zig_lib_dir| { | 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 | zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir, | 1862 | zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir, |
| 1882 | }); | 1863 | }); |
| 1883 | return result.stdout; | 1864 | return result.stdout; |
| 1884 | } else { | 1865 | } else { |
| 1885 | const result = try exec(allocator, env_map, &.{ | 1866 | const result = try exec(allocator, env_map, null, &.{ |
| 1886 | zig_exe, "build-obj", "--show-builtin", | 1867 | zig_exe, "build-obj", "--show-builtin", |
| 1887 | }); | 1868 | }); |
| 1888 | return result.stdout; | 1869 | return result.stdout; |