Skip to content

Commit

Permalink
Merge branch 'ziglang:master' into optimize_std.fs.Dir.makeOpenPath_1…
Browse files Browse the repository at this point in the history
…2474
  • Loading branch information
QusaiHroub authored Aug 3, 2023
2 parents a0885d6 + e85a46c commit 23fff77
Show file tree
Hide file tree
Showing 179 changed files with 3,507 additions and 3,744 deletions.
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/math/frexp.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isinf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isnan.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/ln.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log10.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log2.zig"
Expand Down Expand Up @@ -700,6 +699,7 @@ elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7l")
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7b")
set(ZIG_HOST_TARGET_ARCH "armeb")
endif()

if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(eb)?$")
include(CheckSymbolExists)
check_symbol_exists(__thumb__ "" ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
Expand All @@ -711,7 +711,16 @@ string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS)
if(ZIG_HOST_TARGET_OS STREQUAL "darwin")
set(ZIG_HOST_TARGET_OS "macos")
endif()
set(ZIG_HOST_TARGET_TRIPLE "${ZIG_HOST_TARGET_ARCH}-${ZIG_HOST_TARGET_OS}" CACHE STRING "Host zig target triple.")

if(MSVC)
set(ZIG_HOST_TARGET_ABI "-msvc")
elif(MINGW)
set(ZIG_HOST_TARGET_ABI "-gnu")
else()
set(ZIG_HOST_TARGET_ABI "")
endif()

set(ZIG_HOST_TARGET_TRIPLE "${ZIG_HOST_TARGET_ARCH}-${ZIG_HOST_TARGET_OS}${ZIG_HOST_TARGET_ABI}" CACHE STRING "Host zig target triple.")

if(MSVC)
set(ZIG_WASM2C_COMPILE_FLAGS "")
Expand All @@ -724,6 +733,8 @@ else()
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-stack-protector")
if(APPLE)
set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000")
elseif(MINGW)
set(ZIG2_LINK_FLAGS "-Wl,--stack,0x10000000")
else()
set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
endif()
Expand Down Expand Up @@ -752,6 +763,9 @@ if(MSVC)
target_link_options(zig1 PRIVATE /STACK:0x10000000)
else()
target_link_libraries(zig1 LINK_PUBLIC m)
if(MINGW)
target_link_options(zig1 PRIVATE -Wl,--stack,0x10000000)
endif()
endif()

set(BUILD_ZIG2_ARGS
Expand Down
53 changes: 27 additions & 26 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn build(b: *std.Build) !void {

const docgen_exe = b.addExecutable(.{
.name = "docgen",
.root_source_file = .{ .path = "doc/docgen.zig" },
.root_source_file = .{ .path = "tools/docgen.zig" },
.target = .{},
.optimize = .Debug,
});
Expand All @@ -45,9 +45,10 @@ pub fn build(b: *std.Build) !void {
const docgen_cmd = b.addRunArtifact(docgen_exe);
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
if (b.zig_lib_dir) |p| {
docgen_cmd.addArgs(&.{ "--zig-lib-dir", p });
docgen_cmd.addArg("--zig-lib-dir");
docgen_cmd.addDirectoryArg(p);
}
docgen_cmd.addFileSourceArg(.{ .path = "doc/langref.html.in" });
docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" });
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
const install_langref = b.addInstallFileWithDir(langref_file, .prefix, "doc/langref.html");
if (!skip_install_langref) {
Expand All @@ -57,9 +58,8 @@ pub fn build(b: *std.Build) !void {
const autodoc_test = b.addTest(.{
.root_source_file = .{ .path = "lib/std/std.zig" },
.target = target,
.zig_lib_dir = .{ .path = "lib" },
});
autodoc_test.overrideZigLibDir("lib");
autodoc_test.emit_bin = .no_emit; // https://github.com/ziglang/zig/issues/16351
const install_std_docs = b.addInstallDirectory(.{
.source_dir = autodoc_test.getEmittedDocs(),
.install_dir = .prefix,
Expand Down Expand Up @@ -88,8 +88,8 @@ pub fn build(b: *std.Build) !void {
.name = "check-case",
.root_source_file = .{ .path = "test/src/Cases.zig" },
.optimize = optimize,
.main_pkg_path = .{ .path = "." },
});
check_case_exe.main_pkg_path = ".";
check_case_exe.stack_size = stack_size;
check_case_exe.single_threaded = single_threaded;

Expand Down Expand Up @@ -196,10 +196,6 @@ pub fn build(b: *std.Build) !void {
exe.pie = pie;
exe.sanitize_thread = sanitize_thread;
exe.entitlements = entitlements;
// TODO -femit-bin/-fno-emit-bin should be inferred by the build system
// based on whether or not the exe is run or installed.
// https://github.com/ziglang/zig/issues/16351
if (no_bin) exe.emit_bin = .no_emit;

exe.build_id = b.option(
std.Build.Step.Compile.BuildId,
Expand All @@ -208,7 +204,7 @@ pub fn build(b: *std.Build) !void {
);

if (!no_bin) {
const install_exe = b.addInstallArtifact(exe);
const install_exe = b.addInstallArtifact(exe, .{});
if (flat) {
install_exe.dest_dir = .prefix;
}
Expand Down Expand Up @@ -352,19 +348,18 @@ pub fn build(b: *std.Build) !void {
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "value_tracing", value_tracing);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
const client_cpp = b.pathJoin(
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
) catch unreachable;
);

// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };

exe.addIncludePath(tracy_path);
exe.addCSourceFile(client_cpp, tracy_c_flags);
exe.addIncludePath(.{ .cwd_relative = tracy_path });
exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
if (!enable_llvm) {
exe.linkSystemLibraryName("c++");
}
Expand Down Expand Up @@ -440,7 +435,13 @@ pub fn build(b: *std.Build) !void {
}).step);

const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
try tests.addCases(b, test_cases_step, test_filter, check_case_exe);
try tests.addCases(b, test_cases_step, test_filter, check_case_exe, .{
.enable_llvm = enable_llvm,
.llvm_has_m68k = llvm_has_m68k,
.llvm_has_csky = llvm_has_csky,
.llvm_has_arc = llvm_has_arc,
.llvm_has_xtensa = llvm_has_xtensa,
});
test_step.dependOn(test_cases_step);

test_step.dependOn(tests.addModuleTests(b, .{
Expand Down Expand Up @@ -554,7 +555,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
});
run_opt.addArtifactArg(exe);
run_opt.addArg("-o");
run_opt.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
run_opt.addFileArg(.{ .path = "stage1/zig1.wasm" });

const copy_zig_h = b.addWriteFiles();
copy_zig_h.addCopyFileToSource(.{ .path = "lib/zig.h" }, "stage1/zig.h");
Expand Down Expand Up @@ -603,19 +604,19 @@ fn addCmakeCfgOptionsToExe(
// useful for package maintainers
exe.headerpad_max_install_names = true;
}
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{
cfg.cmake_binary_dir,
"zigcpp",
b.fmt("{s}{s}{s}", .{
cfg.cmake_static_library_prefix,
"zigcpp",
cfg.cmake_static_library_suffix,
}),
}) catch unreachable);
}) });
assert(cfg.lld_include_dir.len != 0);
exe.addIncludePath(cfg.lld_include_dir);
exe.addIncludePath(cfg.llvm_include_dir);
exe.addLibraryPath(cfg.llvm_lib_dir);
exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir });
exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir });
exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir });
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
Expand Down Expand Up @@ -671,7 +672,7 @@ fn addCmakeCfgOptionsToExe(
}

if (cfg.dia_guids_lib.len != 0) {
exe.addObjectFile(cfg.dia_guids_lib);
exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib });
}
}

Expand Down Expand Up @@ -732,7 +733,7 @@ fn addCxxKnownPath(
}
return error.RequiredLibraryNotFound;
}
exe.addObjectFile(path_unpadded);
exe.addObjectFile(.{ .cwd_relative = path_unpadded });

// TODO a way to integrate with system c++ include files here
// c++ -E -Wp,-v -xc++ /dev/null
Expand All @@ -752,7 +753,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
} else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) {
exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]);
} else {
exe.addObjectFile(lib);
exe.addObjectFile(.{ .cwd_relative = lib });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -3018,7 +3018,7 @@ test "basic slices" {
slice[10] += 1;

// Note that `slice.ptr` does not invoke safety checking, while `&slice[0]`
// asserts that the slice has len >= 1.
// asserts that the slice has len > 0.
}
{#code_end#}
<p>This is one reason we prefer slices to pointers.</p>
Expand Down
4 changes: 2 additions & 2 deletions lib/build_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ pub fn main() !void {
usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
builder.zig_lib_dir = nextArg(args, &arg_idx) orelse {
builder.zig_lib_dir = .{ .cwd_relative = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
usageAndErr(builder, false, stderr_stream);
};
} };
} else if (mem.eql(u8, arg, "--debug-log")) {
const next_arg = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
Expand Down
Loading

0 comments on commit 23fff77

Please sign in to comment.