diff --git a/CMakeLists.txt b/CMakeLists.txt index af34214bae..5055ea4d36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE) endif() if(NOT CMAKE_INSTALL_PREFIX) - set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage1" CACHE STRING + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage3" CACHE STRING "Directory to install zig to" FORCE) endif() @@ -65,6 +65,9 @@ if("${ZIG_VERSION}" STREQUAL "") endif() message(STATUS "Configuring zig version ${ZIG_VERSION}") +set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL + "Disable copying lib/ files to install prefix during the build phase") + set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)") set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries") set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries") @@ -333,7 +336,7 @@ set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h") set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig") # This is our shim which will be replaced by stage1.zig. -set(ZIG0_SOURCES +set(ZIG1_SOURCES "${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp" ) @@ -373,9 +376,9 @@ set(ZIG_CPP_SOURCES # https://github.com/ziglang/zig/issues/6363 "${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp" ) -# Needed because we use cmake, not the zig build system, to build zig1.o. +# Needed because we use cmake, not the zig build system, to build zig2.o. # This list is generated by building zig and then clearing the zig-cache directory, -# then manually running the build-obj command (see BUILD_ZIG1_ARGS), and then looking +# then manually running the build-obj command (see BUILD_ZIG2_ARGS), and then looking # in the zig-cache directory for the compiler-generated list of zig file dependencies. set(ZIG_STAGE2_SOURCES "${ZIG_CONFIG_ZIG_OUT}" @@ -942,40 +945,51 @@ if(MSVC OR MINGW) endif() if("${ZIG_EXECUTABLE}" STREQUAL "") - add_executable(zig0 ${ZIG0_SOURCES}) - set_target_properties(zig0 PROPERTIES + add_executable(zig1 ${ZIG1_SOURCES}) + set_target_properties(zig1 PROPERTIES COMPILE_FLAGS ${EXE_CFLAGS} LINK_FLAGS ${EXE_LDFLAGS} ) - target_link_libraries(zig0 zigstage1) + target_link_libraries(zig1 zigstage1) endif() if(MSVC) - set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj") + set(ZIG2_OBJECT "${CMAKE_BINARY_DIR}/zig2.obj") else() - set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.o") + set(ZIG2_OBJECT "${CMAKE_BINARY_DIR}/zig2.o") endif() if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set(ZIG1_RELEASE_ARG "") + set(ZIG_RELEASE_ARG "") +elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + set(ZIG_RELEASE_ARG -Drelease) else() - set(ZIG1_RELEASE_ARG -OReleaseFast --strip) + set(ZIG_RELEASE_ARG -Drelease -Dstrip) +endif() +if(ZIG_SKIP_INSTALL_LIB_FILES) + set(ZIG_SKIP_INSTALL_LIB_FILES_ARG "-Dskip-install-lib-files") +else() + set(ZIG_SKIP_INSTALL_LIB_FILES_ARG "-Dskip-install-lib-files=false") endif() if(ZIG_SINGLE_THREADED) - set(ZIG1_SINGLE_THREADED_ARG "-fsingle-threaded") + set(ZIG_SINGLE_THREADED_ARG "-fsingle-threaded") else() - set(ZIG1_SINGLE_THREADED_ARG "") + set(ZIG_SINGLE_THREADED_ARG "") +endif() +if(ZIG_STATIC) + set(ZIG_STATIC_ARG "-Duse-zig-libcxx") +else() + set(ZIG_STATIC_ARG "") endif() -set(BUILD_ZIG1_ARGS +set(BUILD_ZIG2_ARGS "src/stage1.zig" - -target "${ZIG_TARGET_TRIPLE}" - "-mcpu=${ZIG_TARGET_MCPU}" - --name zig1 + --name zig2 --zig-lib-dir "${CMAKE_SOURCE_DIR}/lib" - "-femit-bin=${ZIG1_OBJECT}" + "-femit-bin=${ZIG2_OBJECT}" -fcompiler-rt - "${ZIG1_RELEASE_ARG}" - "${ZIG1_SINGLE_THREADED_ARG}" + ${ZIG_SINGLE_THREADED_ARG} + -target "${ZIG_TARGET_TRIPLE}" + -mcpu "${ZIG_TARGET_MCPU}" -lc --pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}" --pkg-end @@ -985,68 +999,64 @@ set(BUILD_ZIG1_ARGS if("${ZIG_EXECUTABLE}" STREQUAL "") add_custom_command( - OUTPUT "${ZIG1_OBJECT}" - COMMAND zig0 ${BUILD_ZIG1_ARGS} - DEPENDS zig0 "${ZIG_STAGE2_SOURCES}" - COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}" - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT "${ZIG2_OBJECT}" + COMMAND zig1 ${BUILD_ZIG2_ARGS} + DEPENDS zig1 "${ZIG_STAGE2_SOURCES}" + COMMENT STATUS "Building stage2 object ${ZIG2_OBJECT}" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) - set(ZIG_EXECUTABLE "${zig_BINARY_DIR}/zig") if (WIN32) - set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe") + set(ZIG_EXECUTABLE "${zig2_BINARY_DIR}/zig2.exe") + else() + set(ZIG_EXECUTABLE "${zig2_BINARY_DIR}/zig2") endif() else() add_custom_command( - OUTPUT "${ZIG1_OBJECT}" - COMMAND "${ZIG_EXECUTABLE}" "build-obj" ${BUILD_ZIG1_ARGS} - DEPENDS ${ZIG_STAGE2_SOURCES} - COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}" - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT "${ZIG2_OBJECT}" + COMMAND "${ZIG_EXECUTABLE}" "build-obj" ${BUILD_ZIG2_ARGS} + DEPENDS ${ZIG_STAGE2_SOURCES} + COMMENT STATUS "Building stage2 component ${ZIG2_OBJECT}" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) endif() # cmake won't let us configure an executable without C sources. -add_executable(zig "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp" "${ZIG1_OBJECT}") +add_executable(zig2 "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp" "${ZIG2_OBJECT}") -set_target_properties(zig PROPERTIES +set_target_properties(zig2 PROPERTIES COMPILE_FLAGS ${EXE_CFLAGS} LINK_FLAGS ${EXE_LDFLAGS} ) -target_link_libraries(zig zigstage1) +target_link_libraries(zig2 zigstage1) if(MSVC) - target_link_libraries(zig ntdll.lib) + target_link_libraries(zig2 ntdll.lib) elseif(MINGW) - target_link_libraries(zig ntdll) + target_link_libraries(zig2 ntdll) endif() -install(TARGETS zig DESTINATION bin) - -set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL - "Disable copying lib/ files to install prefix during the build phase") - +# Dummy install command so that the "install" target is not missing. +# This is redundant from the "stage3" custom target below. if(NOT ZIG_SKIP_INSTALL_LIB_FILES) - set(ZIG_INSTALL_ARGS "build" - --zig-lib-dir "${CMAKE_SOURCE_DIR}/lib" - "-Dlib-files-only" - --prefix "${CMAKE_INSTALL_PREFIX}" - "-Dconfig_h=${ZIG_CONFIG_H_OUT}" - install - ) - - # CODE has no effect with Visual Studio build system generator, therefore - # when using Visual Studio build system generator we resort to running - # `zig build install` during the build phase. - if(MSVC) - add_custom_target(zig_install_lib_files ALL - COMMAND zig ${ZIG_INSTALL_ARGS} - DEPENDS zig - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - ) - else() - get_target_property(zig_BINARY_DIR zig BINARY_DIR) - install(CODE "set(zig_EXE \"${ZIG_EXECUTABLE}\")") - install(CODE "set(ZIG_INSTALL_ARGS \"${ZIG_INSTALL_ARGS}\")") - install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")") - install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake) - endif() + install(FILES "lib/compiler_rt.zig" DESTINATION "lib/zig") endif() + +set(ZIG_INSTALL_ARGS "build" + --zig-lib-dir "${CMAKE_SOURCE_DIR}/lib" + --prefix "${CMAKE_INSTALL_PREFIX}" + "-Dconfig_h=${ZIG_CONFIG_H_OUT}" + "-Denable-llvm" + "-Denable-stage1" + ${ZIG_RELEASE_ARG} + ${ZIG_STATIC_ARG} + ${ZIG_SKIP_INSTALL_LIB_FILES_ARG} + ${ZIG_SINGLE_THREADED_ARG} + "-Dtarget=${ZIG_TARGET_TRIPLE}" + "-Dcpu=${ZIG_TARGET_MCPU}" +) + +add_custom_target(stage3 ALL + COMMAND zig2 ${ZIG_INSTALL_ARGS} + DEPENDS zig2 + COMMENT STATUS "Building stage3" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" +) diff --git a/build.zig b/build.zig index 4ecb7f9a4f..fc89b54023 100644 --- a/build.zig +++ b/build.zig @@ -15,6 +15,7 @@ const stack_size = 32 * 1024 * 1024; pub fn build(b: *Builder) !void { b.setPreferredReleaseMode(.ReleaseFast); + const test_step = b.step("test", "Run all the tests"); const mode = b.standardReleaseOptions(); const target = b.standardTargetOptions(.{}); const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode"); @@ -39,8 +40,6 @@ pub fn build(b: *Builder) !void { const docs_step = b.step("docs", "Build documentation"); docs_step.dependOn(&docgen_cmd.step); - const toolchain_step = b.step("test-toolchain", "Run the tests for the toolchain"); - var test_cases = b.addTest("src/test.zig"); test_cases.stack_size = stack_size; test_cases.setBuildMode(mode); @@ -64,10 +63,9 @@ pub fn build(b: *Builder) !void { const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false; - const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false; - const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false; + const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false; const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false; - const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm); + const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm); const llvm_has_m68k = b.option( bool, "llvm-has-m68k", @@ -137,7 +135,7 @@ pub fn build(b: *Builder) !void { }; const main_file: ?[]const u8 = mf: { - if (!is_stage1) break :mf "src/main.zig"; + if (!have_stage1) break :mf "src/main.zig"; if (use_zig0) break :mf null; break :mf "src/stage1.zig"; }; @@ -150,7 +148,7 @@ pub fn build(b: *Builder) !void { exe.setBuildMode(mode); exe.setTarget(target); if (!skip_stage2_tests) { - toolchain_step.dependOn(&exe.step); + test_step.dependOn(&exe.step); } b.default_step.dependOn(&exe.step); @@ -248,7 +246,7 @@ pub fn build(b: *Builder) !void { } }; - if (is_stage1) { + if (have_stage1) { const softfloat = b.addStaticLibrary("softfloat", null); softfloat.setBuildMode(.ReleaseFast); softfloat.setTarget(target); @@ -360,8 +358,7 @@ pub fn build(b: *Builder) !void { exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack); exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation); exe_options.addOption(bool, "value_tracing", value_tracing); - exe_options.addOption(bool, "is_stage1", is_stage1); - exe_options.addOption(bool, "omit_stage2", omit_stage2); + exe_options.addOption(bool, "have_stage1", have_stage1); if (tracy) |tracy_path| { const client_cpp = fs.path.join( b.allocator, @@ -396,8 +393,7 @@ pub fn build(b: *Builder) !void { test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots); test_cases_options.addOption(bool, "skip_non_native", skip_non_native); test_cases_options.addOption(bool, "skip_stage1", skip_stage1); - test_cases_options.addOption(bool, "is_stage1", is_stage1); - test_cases_options.addOption(bool, "omit_stage2", omit_stage2); + test_cases_options.addOption(bool, "have_stage1", have_stage1); test_cases_options.addOption(bool, "have_llvm", enable_llvm); test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k); test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky); @@ -418,7 +414,7 @@ pub fn build(b: *Builder) !void { const test_cases_step = b.step("test-cases", "Run the main compiler test cases"); test_cases_step.dependOn(&test_cases.step); if (!skip_stage2_tests) { - toolchain_step.dependOn(test_cases_step); + test_step.dependOn(test_cases_step); } var chosen_modes: [4]builtin.Mode = undefined; @@ -442,11 +438,11 @@ pub fn build(b: *Builder) !void { const modes = chosen_modes[0..chosen_mode_index]; // run stage1 `zig fmt` on this build.zig file just to make sure it works - toolchain_step.dependOn(&fmt_build_zig.step); + test_step.dependOn(&fmt_build_zig.step); const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works"); fmt_step.dependOn(&fmt_build_zig.step); - toolchain_step.dependOn(tests.addPkgTests( + test_step.dependOn(tests.addPkgTests( b, test_filter, "test/behavior.zig", @@ -457,11 +453,10 @@ pub fn build(b: *Builder) !void { skip_non_native, skip_libc, skip_stage1, - omit_stage2, - is_stage1, + skip_stage2_tests, )); - toolchain_step.dependOn(tests.addPkgTests( + test_step.dependOn(tests.addPkgTests( b, test_filter, "lib/compiler_rt.zig", @@ -472,11 +467,10 @@ pub fn build(b: *Builder) !void { skip_non_native, true, // skip_libc skip_stage1, - omit_stage2 or true, // TODO get these all passing - is_stage1, + skip_stage2_tests or true, // TODO get these all passing )); - toolchain_step.dependOn(tests.addPkgTests( + test_step.dependOn(tests.addPkgTests( b, test_filter, "lib/c.zig", @@ -487,37 +481,36 @@ pub fn build(b: *Builder) !void { skip_non_native, true, // skip_libc skip_stage1, - omit_stage2 or true, // TODO get these all passing - is_stage1, + skip_stage2_tests or true, // TODO get these all passing )); - toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); - toolchain_step.dependOn(tests.addStandaloneTests( + test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); + test_step.dependOn(tests.addStandaloneTests( b, test_filter, modes, skip_non_native, enable_macos_sdk, target, - omit_stage2, + skip_stage2_tests, b.enable_darling, b.enable_qemu, b.enable_rosetta, b.enable_wasmtime, b.enable_wine, )); - toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, omit_stage2)); - toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); - toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes)); - toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); - toolchain_step.dependOn(tests.addTranslateCTests(b, test_filter)); + test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests)); + test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); + test_step.dependOn(tests.addCliTests(b, test_filter, modes)); + test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); + test_step.dependOn(tests.addTranslateCTests(b, test_filter)); if (!skip_run_translated_c) { - toolchain_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target)); + test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target)); } // tests for this feature are disabled until we have the self-hosted compiler available - // toolchain_step.dependOn(tests.addGenHTests(b, test_filter)); + // test_step.dependOn(tests.addGenHTests(b, test_filter)); - const std_step = tests.addPkgTests( + test_step.dependOn(tests.addPkgTests( b, test_filter, "lib/std/std.zig", @@ -528,14 +521,8 @@ pub fn build(b: *Builder) !void { skip_non_native, skip_libc, skip_stage1, - omit_stage2 or true, // TODO get these all passing - is_stage1, - ); - - const test_step = b.step("test", "Run all the tests"); - test_step.dependOn(toolchain_step); - test_step.dependOn(std_step); - test_step.dependOn(docs_step); + true, // TODO get these all passing + )); } const exe_cflags = [_][]const u8{ diff --git a/ci/azure/build.zig b/ci/azure/build.zig deleted file mode 100644 index 3fec555321..0000000000 --- a/ci/azure/build.zig +++ /dev/null @@ -1,976 +0,0 @@ -const std = @import("std"); -const builtin = std.builtin; -const Builder = std.build.Builder; -const BufMap = std.BufMap; -const mem = std.mem; -const ArrayList = std.ArrayList; -const io = std.io; -const fs = std.fs; -const InstallDirectoryOptions = std.build.InstallDirectoryOptions; -const assert = std.debug.assert; - -const zig_version = std.builtin.Version{ .major = 0, .minor = 10, .patch = 0 }; - -pub fn build(b: *Builder) !void { - b.setPreferredReleaseMode(.ReleaseFast); - const mode = b.standardReleaseOptions(); - const target = b.standardTargetOptions(.{}); - const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode"); - const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false; - - const docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); - docgen_exe.single_threaded = single_threaded; - - const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe); - const langref_out_path = fs.path.join( - b.allocator, - &[_][]const u8{ b.cache_root, "langref.html" }, - ) catch unreachable; - const docgen_cmd = docgen_exe.run(); - docgen_cmd.addArgs(&[_][]const u8{ - rel_zig_exe, - "doc" ++ fs.path.sep_str ++ "langref.html.in", - langref_out_path, - }); - docgen_cmd.step.dependOn(&docgen_exe.step); - - const docs_step = b.step("docs", "Build documentation"); - docs_step.dependOn(&docgen_cmd.step); - - const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false; - const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false; - const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false; - const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm); - const llvm_has_m68k = b.option( - bool, - "llvm-has-m68k", - "Whether LLVM has the experimental target m68k enabled", - ) orelse false; - const llvm_has_csky = b.option( - bool, - "llvm-has-csky", - "Whether LLVM has the experimental target csky enabled", - ) orelse false; - const llvm_has_arc = b.option( - bool, - "llvm-has-arc", - "Whether LLVM has the experimental target arc enabled", - ) orelse false; - const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); - - b.installDirectory(InstallDirectoryOptions{ - .source_dir = "lib", - .install_dir = .lib, - .install_subdir = "zig", - .exclude_extensions = &[_][]const u8{ - // exclude files from lib/std/compress/ - ".gz", - ".z.0", - ".z.9", - "rfc1951.txt", - "rfc1952.txt", - // exclude files from lib/std/compress/deflate/testdata - ".expect", - ".expect-noinput", - ".golden", - ".input", - "compress-e.txt", - "compress-gettysburg.txt", - "compress-pi.txt", - "rfc1951.txt", - // exclude files from lib/std/tz/ - ".tzif", - // others - "README.md", - }, - .blank_extensions = &[_][]const u8{ - "test.zig", - }, - }); - - const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source"); - const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false; - const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false; - const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false; - const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm; - const strip = b.option(bool, "strip", "Omit debug information") orelse false; - const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false; - - const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { - if (strip) break :blk @as(u32, 0); - if (mode != .Debug) break :blk 0; - break :blk 4; - }; - - const main_file: ?[]const u8 = if (is_stage1) null else "src/main.zig"; - - const exe = b.addExecutable("zig", main_file); - exe.strip = strip; - exe.install(); - exe.setBuildMode(mode); - exe.setTarget(target); - - b.default_step.dependOn(&exe.step); - exe.single_threaded = single_threaded; - - if (target.isWindows() and target.getAbi() == .gnu) { - // LTO is currently broken on mingw, this can be removed when it's fixed. - exe.want_lto = false; - } - - const exe_options = b.addOptions(); - exe.addOptions("build_options", exe_options); - - exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames); - exe_options.addOption(bool, "skip_non_native", false); - exe_options.addOption(bool, "have_llvm", enable_llvm); - exe_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k); - exe_options.addOption(bool, "llvm_has_csky", llvm_has_csky); - exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc); - exe_options.addOption(bool, "force_gpa", force_gpa); - - if (link_libc) { - exe.linkLibC(); - } - - const is_debug = mode == .Debug; - const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug; - const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false; - - const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git."); - const version = if (opt_version_string) |version| version else v: { - const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch }); - - var code: u8 = undefined; - const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{ - "git", "-C", b.build_root, "describe", "--match", "*.*.*", "--tags", - }, &code, .Ignore) catch { - break :v version_string; - }; - const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r"); - - switch (mem.count(u8, git_describe, "-")) { - 0 => { - // Tagged release version (e.g. 0.9.0). - if (!mem.eql(u8, git_describe, version_string)) { - std.debug.print("Zig version '{s}' does not match Git tag '{s}'\n", .{ version_string, git_describe }); - std.process.exit(1); - } - break :v version_string; - }, - 2 => { - // Untagged development build (e.g. 0.9.0-dev.2025+ecf0050a9). - var it = mem.split(u8, git_describe, "-"); - const tagged_ancestor = it.next() orelse unreachable; - const commit_height = it.next() orelse unreachable; - const commit_id = it.next() orelse unreachable; - - const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor); - if (zig_version.order(ancestor_ver) != .gt) { - std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver }); - std.process.exit(1); - } - - // Check that the commit hash is prefixed with a 'g' (a Git convention). - if (commit_id.len < 1 or commit_id[0] != 'g') { - std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe}); - break :v version_string; - } - - // The version is reformatted in accordance with the https://semver.org specification. - break :v b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] }); - }, - else => { - std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe}); - break :v version_string; - }, - } - }; - exe_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version)); - - if (enable_llvm) { - const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option); - - if (is_stage1) { - const softfloat = b.addStaticLibrary("softfloat", null); - softfloat.setBuildMode(.ReleaseFast); - softfloat.setTarget(target); - softfloat.addIncludeDir("deps/SoftFloat-3e-prebuilt"); - softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086"); - softfloat.addIncludeDir("deps/SoftFloat-3e/source/include"); - softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" }); - softfloat.single_threaded = single_threaded; - - const zig0 = b.addExecutable("zig0", null); - zig0.addCSourceFiles(&.{"src/stage1/zig0.cpp"}, &exe_cflags); - zig0.addIncludeDir("zig-cache/tmp"); // for config.h - zig0.defineCMacro("ZIG_VERSION_MAJOR", b.fmt("{d}", .{zig_version.major})); - zig0.defineCMacro("ZIG_VERSION_MINOR", b.fmt("{d}", .{zig_version.minor})); - zig0.defineCMacro("ZIG_VERSION_PATCH", b.fmt("{d}", .{zig_version.patch})); - zig0.defineCMacro("ZIG_VERSION_STRING", b.fmt("\"{s}\"", .{version})); - - for ([_]*std.build.LibExeObjStep{ zig0, exe }) |artifact| { - artifact.addIncludeDir("src"); - artifact.addIncludeDir("deps/SoftFloat-3e/source/include"); - artifact.addIncludeDir("deps/SoftFloat-3e-prebuilt"); - - artifact.defineCMacro("ZIG_LINK_MODE", "Static"); - - artifact.addCSourceFiles(&stage1_sources, &exe_cflags); - artifact.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" }); - - artifact.linkLibrary(softfloat); - artifact.linkLibCpp(); - } - - try addStaticLlvmOptionsToExe(zig0); - - const zig1_obj_ext = target.getObjectFormat().fileExt(target.getCpuArch()); - const zig1_obj_path = b.pathJoin(&.{ "zig-cache", "tmp", b.fmt("zig1{s}", .{zig1_obj_ext}) }); - const zig1_compiler_rt_path = b.pathJoin(&.{ b.pathFromRoot("lib"), "std", "special", "compiler_rt.zig" }); - - const zig1_obj = zig0.run(); - zig1_obj.addArgs(&.{ - "src/stage1.zig", - "-target", - try target.zigTriple(b.allocator), - "-mcpu=baseline", - "--name", - "zig1", - "--zig-lib-dir", - b.pathFromRoot("lib"), - b.fmt("-femit-bin={s}", .{b.pathFromRoot(zig1_obj_path)}), - "-fcompiler-rt", - "-lc", - }); - { - zig1_obj.addArgs(&.{ "--pkg-begin", "build_options" }); - zig1_obj.addFileSourceArg(exe_options.getSource()); - zig1_obj.addArgs(&.{ "--pkg-end", "--pkg-begin", "compiler_rt", zig1_compiler_rt_path, "--pkg-end" }); - } - switch (mode) { - .Debug => {}, - .ReleaseFast => { - zig1_obj.addArg("-OReleaseFast"); - zig1_obj.addArg("--strip"); - }, - .ReleaseSafe => { - zig1_obj.addArg("-OReleaseSafe"); - zig1_obj.addArg("--strip"); - }, - .ReleaseSmall => { - zig1_obj.addArg("-OReleaseSmall"); - zig1_obj.addArg("--strip"); - }, - } - if (single_threaded orelse false) { - zig1_obj.addArg("-fsingle-threaded"); - } - - exe.step.dependOn(&zig1_obj.step); - exe.addObjectFile(zig1_obj_path); - - // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case - // of being built by cmake. But when built by zig it's gonna get a compiler_rt so that - // is pointless. - exe.addPackagePath("compiler_rt", "src/empty.zig"); - } - if (cmake_cfg) |cfg| { - // Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD. - // That means we also have to rely on stage1 compiled c++ files. We parse config.h to find - // the information passed on to us from cmake. - if (cfg.cmake_prefix_path.len > 0) { - b.addSearchPrefix(cfg.cmake_prefix_path); - } - - try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx); - } else { - // Here we are -Denable-llvm but no cmake integration. - try addStaticLlvmOptionsToExe(exe); - } - } - - const semver = try std.SemanticVersion.parse(version); - exe_options.addOption(std.SemanticVersion, "semver", semver); - - exe_options.addOption(bool, "enable_logging", enable_logging); - exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots); - exe_options.addOption(bool, "enable_tracy", tracy != null); - exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack); - exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation); - exe_options.addOption(bool, "value_tracing", value_tracing); - exe_options.addOption(bool, "is_stage1", is_stage1); - exe_options.addOption(bool, "omit_stage2", omit_stage2); - if (tracy) |tracy_path| { - const client_cpp = fs.path.join( - b.allocator, - &[_][]const u8{ tracy_path, "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.addIncludeDir(tracy_path); - exe.addCSourceFile(client_cpp, tracy_c_flags); - if (!enable_llvm) { - exe.linkSystemLibraryName("c++"); - } - exe.linkLibC(); - - if (target.isWindows()) { - exe.linkSystemLibrary("dbghelp"); - exe.linkSystemLibrary("ws2_32"); - } - } -} - -const exe_cflags = [_][]const u8{ - "-std=c++14", - "-D__STDC_CONSTANT_MACROS", - "-D__STDC_FORMAT_MACROS", - "-D__STDC_LIMIT_MACROS", - "-D_GNU_SOURCE", - "-fvisibility-inlines-hidden", - "-fno-exceptions", - "-fno-rtti", - "-Werror=type-limits", - "-Wno-missing-braces", - "-Wno-comment", -}; - -fn addCmakeCfgOptionsToExe( - b: *Builder, - cfg: CMakeConfig, - exe: *std.build.LibExeObjStep, - use_zig_libcxx: bool, -) !void { - exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ - cfg.cmake_binary_dir, - "zigcpp", - b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }), - }) catch unreachable); - assert(cfg.lld_include_dir.len != 0); - exe.addIncludeDir(cfg.lld_include_dir); - addCMakeLibraryList(exe, cfg.clang_libraries); - addCMakeLibraryList(exe, cfg.lld_libraries); - addCMakeLibraryList(exe, cfg.llvm_libraries); - - if (use_zig_libcxx) { - exe.linkLibCpp(); - } else { - const need_cpp_includes = true; - - // System -lc++ must be used because in this code path we are attempting to link - // against system-provided LLVM, Clang, LLD. - if (exe.target.getOsTag() == .linux) { - // First we try to static link against gcc libstdc++. If that doesn't work, - // we fall back to -lc++ and cross our fingers. - addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) { - error.RequiredLibraryNotFound => { - exe.linkSystemLibrary("c++"); - }, - else => |e| return e, - }; - exe.linkSystemLibrary("unwind"); - } else if (exe.target.isFreeBSD()) { - try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); - exe.linkSystemLibrary("pthread"); - } else if (exe.target.getOsTag() == .openbsd) { - try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); - try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes); - } else if (exe.target.isDarwin()) { - exe.linkSystemLibrary("c++"); - } - } - - if (cfg.dia_guids_lib.len != 0) { - exe.addObjectFile(cfg.dia_guids_lib); - } -} - -fn addStaticLlvmOptionsToExe( - exe: *std.build.LibExeObjStep, -) !void { - // Adds the Zig C++ sources which both stage1 and stage2 need. - // - // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling - // in a dependency on llvm::cfg::Update::dump() which is - // unavailable when LLVM is compiled in Release mode. - const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"}; - exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags); - - for (clang_libs) |lib_name| { - exe.linkSystemLibrary(lib_name); - } - - for (lld_libs) |lib_name| { - exe.linkSystemLibrary(lib_name); - } - - for (llvm_libs) |lib_name| { - exe.linkSystemLibrary(lib_name); - } - - exe.linkSystemLibrary("z"); - - // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. - exe.linkSystemLibrary("c++"); - - if (exe.target.getOs().tag == .windows) { - exe.linkSystemLibrary("version"); - exe.linkSystemLibrary("uuid"); - exe.linkSystemLibrary("ole32"); - } -} - -fn addCxxKnownPath( - b: *Builder, - ctx: CMakeConfig, - exe: *std.build.LibExeObjStep, - objname: []const u8, - errtxt: ?[]const u8, - need_cpp_includes: bool, -) !void { - const path_padded = try b.exec(&[_][]const u8{ - ctx.cxx_compiler, - b.fmt("-print-file-name={s}", .{objname}), - }); - const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?; - if (mem.eql(u8, path_unpadded, objname)) { - if (errtxt) |msg| { - std.debug.print("{s}", .{msg}); - } else { - std.debug.print("Unable to determine path to {s}\n", .{objname}); - } - return error.RequiredLibraryNotFound; - } - exe.addObjectFile(path_unpadded); - - // TODO a way to integrate with system c++ include files here - // cc -E -Wp,-v -xc++ /dev/null - if (need_cpp_includes) { - // I used these temporarily for testing something but we obviously need a - // more general purpose solution here. - //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0"); - //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0/x86_64-unknown-linux-gnu"); - //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0/backward"); - } -} - -fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void { - var it = mem.tokenize(u8, list, ";"); - while (it.next()) |lib| { - if (mem.startsWith(u8, lib, "-l")) { - exe.linkSystemLibrary(lib["-l".len..]); - } else { - exe.addObjectFile(lib); - } - } -} - -const CMakeConfig = struct { - cmake_binary_dir: []const u8, - cmake_prefix_path: []const u8, - cxx_compiler: []const u8, - lld_include_dir: []const u8, - lld_libraries: []const u8, - clang_libraries: []const u8, - llvm_libraries: []const u8, - dia_guids_lib: []const u8, -}; - -const max_config_h_bytes = 1 * 1024 * 1024; - -fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeConfig { - const config_h_text: []const u8 = if (config_h_path_option) |config_h_path| blk: { - break :blk fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable; - } else blk: { - // TODO this should stop looking for config.h once it detects we hit the - // zig source root directory. - var check_dir = fs.path.dirname(b.zig_exe).?; - while (true) { - var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable; - defer dir.close(); - - break :blk dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) { - error.FileNotFound => { - const new_check_dir = fs.path.dirname(check_dir); - if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) { - return null; - } - check_dir = new_check_dir.?; - continue; - }, - else => unreachable, - }; - } else unreachable; // TODO should not need `else unreachable`. - }; - - var ctx: CMakeConfig = .{ - .cmake_binary_dir = undefined, - .cmake_prefix_path = undefined, - .cxx_compiler = undefined, - .lld_include_dir = undefined, - .lld_libraries = undefined, - .clang_libraries = undefined, - .llvm_libraries = undefined, - .dia_guids_lib = undefined, - }; - - const mappings = [_]struct { prefix: []const u8, field: []const u8 }{ - .{ - .prefix = "#define ZIG_CMAKE_BINARY_DIR ", - .field = "cmake_binary_dir", - }, - .{ - .prefix = "#define ZIG_CMAKE_PREFIX_PATH ", - .field = "cmake_prefix_path", - }, - .{ - .prefix = "#define ZIG_CXX_COMPILER ", - .field = "cxx_compiler", - }, - .{ - .prefix = "#define ZIG_LLD_INCLUDE_PATH ", - .field = "lld_include_dir", - }, - .{ - .prefix = "#define ZIG_LLD_LIBRARIES ", - .field = "lld_libraries", - }, - .{ - .prefix = "#define ZIG_CLANG_LIBRARIES ", - .field = "clang_libraries", - }, - .{ - .prefix = "#define ZIG_LLVM_LIBRARIES ", - .field = "llvm_libraries", - }, - .{ - .prefix = "#define ZIG_DIA_GUIDS_LIB ", - .field = "dia_guids_lib", - }, - }; - - var lines_it = mem.tokenize(u8, config_h_text, "\r\n"); - while (lines_it.next()) |line| { - inline for (mappings) |mapping| { - if (mem.startsWith(u8, line, mapping.prefix)) { - var it = mem.split(u8, line, "\""); - _ = it.next().?; // skip the stuff before the quote - const quoted = it.next().?; // the stuff inside the quote - @field(ctx, mapping.field) = toNativePathSep(b, quoted); - } - } - } - return ctx; -} - -fn toNativePathSep(b: *Builder, s: []const u8) []u8 { - const duplicated = b.allocator.dupe(u8, s) catch unreachable; - for (duplicated) |*byte| switch (byte.*) { - '/' => byte.* = fs.path.sep, - else => {}, - }; - return duplicated; -} - -const softfloat_sources = [_][]const u8{ - "deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c", - "deps/SoftFloat-3e/source/8086/extF80M_isSignalingNaN.c", - "deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c", - "deps/SoftFloat-3e/source/8086/s_commonNaNToExtF80M.c", - "deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c", - "deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c", - "deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c", - "deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c", - "deps/SoftFloat-3e/source/8086/s_extF80MToCommonNaN.c", - "deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c", - "deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c", - "deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c", - "deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c", - "deps/SoftFloat-3e/source/8086/s_propagateNaNExtF80M.c", - "deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c", - "deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c", - "deps/SoftFloat-3e/source/f128M_add.c", - "deps/SoftFloat-3e/source/f128M_div.c", - "deps/SoftFloat-3e/source/f128M_eq.c", - "deps/SoftFloat-3e/source/f128M_eq_signaling.c", - "deps/SoftFloat-3e/source/f128M_le.c", - "deps/SoftFloat-3e/source/f128M_le_quiet.c", - "deps/SoftFloat-3e/source/f128M_lt.c", - "deps/SoftFloat-3e/source/f128M_lt_quiet.c", - "deps/SoftFloat-3e/source/f128M_mul.c", - "deps/SoftFloat-3e/source/f128M_mulAdd.c", - "deps/SoftFloat-3e/source/f128M_rem.c", - "deps/SoftFloat-3e/source/f128M_roundToInt.c", - "deps/SoftFloat-3e/source/f128M_sqrt.c", - "deps/SoftFloat-3e/source/f128M_sub.c", - "deps/SoftFloat-3e/source/f128M_to_f16.c", - "deps/SoftFloat-3e/source/f128M_to_f32.c", - "deps/SoftFloat-3e/source/f128M_to_f64.c", - "deps/SoftFloat-3e/source/f128M_to_extF80M.c", - "deps/SoftFloat-3e/source/f128M_to_i32.c", - "deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c", - "deps/SoftFloat-3e/source/f128M_to_i64.c", - "deps/SoftFloat-3e/source/f128M_to_i64_r_minMag.c", - "deps/SoftFloat-3e/source/f128M_to_ui32.c", - "deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c", - "deps/SoftFloat-3e/source/f128M_to_ui64.c", - "deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c", - "deps/SoftFloat-3e/source/extF80M_add.c", - "deps/SoftFloat-3e/source/extF80M_div.c", - "deps/SoftFloat-3e/source/extF80M_eq.c", - "deps/SoftFloat-3e/source/extF80M_le.c", - "deps/SoftFloat-3e/source/extF80M_lt.c", - "deps/SoftFloat-3e/source/extF80M_mul.c", - "deps/SoftFloat-3e/source/extF80M_rem.c", - "deps/SoftFloat-3e/source/extF80M_roundToInt.c", - "deps/SoftFloat-3e/source/extF80M_sqrt.c", - "deps/SoftFloat-3e/source/extF80M_sub.c", - "deps/SoftFloat-3e/source/extF80M_to_f16.c", - "deps/SoftFloat-3e/source/extF80M_to_f32.c", - "deps/SoftFloat-3e/source/extF80M_to_f64.c", - "deps/SoftFloat-3e/source/extF80M_to_f128M.c", - "deps/SoftFloat-3e/source/f16_add.c", - "deps/SoftFloat-3e/source/f16_div.c", - "deps/SoftFloat-3e/source/f16_eq.c", - "deps/SoftFloat-3e/source/f16_isSignalingNaN.c", - "deps/SoftFloat-3e/source/f16_lt.c", - "deps/SoftFloat-3e/source/f16_mul.c", - "deps/SoftFloat-3e/source/f16_mulAdd.c", - "deps/SoftFloat-3e/source/f16_rem.c", - "deps/SoftFloat-3e/source/f16_roundToInt.c", - "deps/SoftFloat-3e/source/f16_sqrt.c", - "deps/SoftFloat-3e/source/f16_sub.c", - "deps/SoftFloat-3e/source/f16_to_extF80M.c", - "deps/SoftFloat-3e/source/f16_to_f128M.c", - "deps/SoftFloat-3e/source/f16_to_f64.c", - "deps/SoftFloat-3e/source/f32_to_extF80M.c", - "deps/SoftFloat-3e/source/f32_to_f128M.c", - "deps/SoftFloat-3e/source/f64_to_extF80M.c", - "deps/SoftFloat-3e/source/f64_to_f128M.c", - "deps/SoftFloat-3e/source/f64_to_f16.c", - "deps/SoftFloat-3e/source/i32_to_f128M.c", - "deps/SoftFloat-3e/source/s_add256M.c", - "deps/SoftFloat-3e/source/s_addCarryM.c", - "deps/SoftFloat-3e/source/s_addComplCarryM.c", - "deps/SoftFloat-3e/source/s_addF128M.c", - "deps/SoftFloat-3e/source/s_addExtF80M.c", - "deps/SoftFloat-3e/source/s_addM.c", - "deps/SoftFloat-3e/source/s_addMagsF16.c", - "deps/SoftFloat-3e/source/s_addMagsF32.c", - "deps/SoftFloat-3e/source/s_addMagsF64.c", - "deps/SoftFloat-3e/source/s_approxRecip32_1.c", - "deps/SoftFloat-3e/source/s_approxRecipSqrt32_1.c", - "deps/SoftFloat-3e/source/s_approxRecipSqrt_1Ks.c", - "deps/SoftFloat-3e/source/s_approxRecip_1Ks.c", - "deps/SoftFloat-3e/source/s_compare128M.c", - "deps/SoftFloat-3e/source/s_compare96M.c", - "deps/SoftFloat-3e/source/s_compareNonnormExtF80M.c", - "deps/SoftFloat-3e/source/s_countLeadingZeros16.c", - "deps/SoftFloat-3e/source/s_countLeadingZeros32.c", - "deps/SoftFloat-3e/source/s_countLeadingZeros64.c", - "deps/SoftFloat-3e/source/s_countLeadingZeros8.c", - "deps/SoftFloat-3e/source/s_eq128.c", - "deps/SoftFloat-3e/source/s_invalidF128M.c", - "deps/SoftFloat-3e/source/s_invalidExtF80M.c", - "deps/SoftFloat-3e/source/s_isNaNF128M.c", - "deps/SoftFloat-3e/source/s_le128.c", - "deps/SoftFloat-3e/source/s_lt128.c", - "deps/SoftFloat-3e/source/s_mul128MTo256M.c", - "deps/SoftFloat-3e/source/s_mul64To128M.c", - "deps/SoftFloat-3e/source/s_mulAddF128M.c", - "deps/SoftFloat-3e/source/s_mulAddF16.c", - "deps/SoftFloat-3e/source/s_mulAddF32.c", - "deps/SoftFloat-3e/source/s_mulAddF64.c", - "deps/SoftFloat-3e/source/s_negXM.c", - "deps/SoftFloat-3e/source/s_normExtF80SigM.c", - "deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c", - "deps/SoftFloat-3e/source/s_normRoundPackMToExtF80M.c", - "deps/SoftFloat-3e/source/s_normRoundPackToF16.c", - "deps/SoftFloat-3e/source/s_normRoundPackToF32.c", - "deps/SoftFloat-3e/source/s_normRoundPackToF64.c", - "deps/SoftFloat-3e/source/s_normSubnormalF128SigM.c", - "deps/SoftFloat-3e/source/s_normSubnormalF16Sig.c", - "deps/SoftFloat-3e/source/s_normSubnormalF32Sig.c", - "deps/SoftFloat-3e/source/s_normSubnormalF64Sig.c", - "deps/SoftFloat-3e/source/s_remStepMBy32.c", - "deps/SoftFloat-3e/source/s_roundMToI64.c", - "deps/SoftFloat-3e/source/s_roundMToUI64.c", - "deps/SoftFloat-3e/source/s_roundPackMToExtF80M.c", - "deps/SoftFloat-3e/source/s_roundPackMToF128M.c", - "deps/SoftFloat-3e/source/s_roundPackToF16.c", - "deps/SoftFloat-3e/source/s_roundPackToF32.c", - "deps/SoftFloat-3e/source/s_roundPackToF64.c", - "deps/SoftFloat-3e/source/s_roundToI32.c", - "deps/SoftFloat-3e/source/s_roundToI64.c", - "deps/SoftFloat-3e/source/s_roundToUI32.c", - "deps/SoftFloat-3e/source/s_roundToUI64.c", - "deps/SoftFloat-3e/source/s_shiftLeftM.c", - "deps/SoftFloat-3e/source/s_shiftNormSigF128M.c", - "deps/SoftFloat-3e/source/s_shiftRightJam256M.c", - "deps/SoftFloat-3e/source/s_shiftRightJam32.c", - "deps/SoftFloat-3e/source/s_shiftRightJam64.c", - "deps/SoftFloat-3e/source/s_shiftRightJamM.c", - "deps/SoftFloat-3e/source/s_shiftRightM.c", - "deps/SoftFloat-3e/source/s_shortShiftLeft64To96M.c", - "deps/SoftFloat-3e/source/s_shortShiftLeftM.c", - "deps/SoftFloat-3e/source/s_shortShiftRightExtendM.c", - "deps/SoftFloat-3e/source/s_shortShiftRightJam64.c", - "deps/SoftFloat-3e/source/s_shortShiftRightJamM.c", - "deps/SoftFloat-3e/source/s_shortShiftRightM.c", - "deps/SoftFloat-3e/source/s_sub1XM.c", - "deps/SoftFloat-3e/source/s_sub256M.c", - "deps/SoftFloat-3e/source/s_subM.c", - "deps/SoftFloat-3e/source/s_subMagsF16.c", - "deps/SoftFloat-3e/source/s_subMagsF32.c", - "deps/SoftFloat-3e/source/s_subMagsF64.c", - "deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c", - "deps/SoftFloat-3e/source/s_tryPropagateNaNExtF80M.c", - "deps/SoftFloat-3e/source/softfloat_state.c", - "deps/SoftFloat-3e/source/ui32_to_f128M.c", - "deps/SoftFloat-3e/source/ui64_to_f128M.c", - "deps/SoftFloat-3e/source/ui32_to_extF80M.c", - "deps/SoftFloat-3e/source/ui64_to_extF80M.c", -}; - -const stage1_sources = [_][]const u8{ - "src/stage1/analyze.cpp", - "src/stage1/astgen.cpp", - "src/stage1/bigfloat.cpp", - "src/stage1/bigint.cpp", - "src/stage1/buffer.cpp", - "src/stage1/codegen.cpp", - "src/stage1/errmsg.cpp", - "src/stage1/error.cpp", - "src/stage1/heap.cpp", - "src/stage1/ir.cpp", - "src/stage1/ir_print.cpp", - "src/stage1/mem.cpp", - "src/stage1/os.cpp", - "src/stage1/parser.cpp", - "src/stage1/range_set.cpp", - "src/stage1/stage1.cpp", - "src/stage1/target.cpp", - "src/stage1/tokenizer.cpp", - "src/stage1/util.cpp", - "src/stage1/softfloat_ext.cpp", -}; -const optimized_c_sources = [_][]const u8{ - "src/stage1/parse_f128.c", -}; -const zig_cpp_sources = [_][]const u8{ - // These are planned to stay even when we are self-hosted. - "src/zig_llvm.cpp", - "src/zig_clang.cpp", - "src/zig_llvm-ar.cpp", - "src/zig_clang_driver.cpp", - "src/zig_clang_cc1_main.cpp", - "src/zig_clang_cc1as_main.cpp", - // https://github.com/ziglang/zig/issues/6363 - "src/windows_sdk.cpp", -}; - -const clang_libs = [_][]const u8{ - "clangFrontendTool", - "clangCodeGen", - "clangFrontend", - "clangDriver", - "clangSerialization", - "clangSema", - "clangStaticAnalyzerFrontend", - "clangStaticAnalyzerCheckers", - "clangStaticAnalyzerCore", - "clangAnalysis", - "clangASTMatchers", - "clangAST", - "clangParse", - "clangSema", - "clangBasic", - "clangEdit", - "clangLex", - "clangARCMigrate", - "clangRewriteFrontend", - "clangRewrite", - "clangCrossTU", - "clangIndex", - "clangToolingCore", -}; -const lld_libs = [_][]const u8{ - "lldMinGW", - "lldELF", - "lldCOFF", - "lldWasm", - "lldMachO", - "lldCommon", -}; -// This list can be re-generated with `llvm-config --libfiles` and then -// reformatting using your favorite text editor. Note we do not execute -// `llvm-config` here because we are cross compiling. Also omit LLVMTableGen -// from these libs. -const llvm_libs = [_][]const u8{ - "LLVMWindowsManifest", - "LLVMXRay", - "LLVMLibDriver", - "LLVMDlltoolDriver", - "LLVMCoverage", - "LLVMLineEditor", - "LLVMXCoreDisassembler", - "LLVMXCoreCodeGen", - "LLVMXCoreDesc", - "LLVMXCoreInfo", - "LLVMX86TargetMCA", - "LLVMX86Disassembler", - "LLVMX86AsmParser", - "LLVMX86CodeGen", - "LLVMX86Desc", - "LLVMX86Info", - "LLVMWebAssemblyDisassembler", - "LLVMWebAssemblyAsmParser", - "LLVMWebAssemblyCodeGen", - "LLVMWebAssemblyDesc", - "LLVMWebAssemblyUtils", - "LLVMWebAssemblyInfo", - "LLVMVEDisassembler", - "LLVMVEAsmParser", - "LLVMVECodeGen", - "LLVMVEDesc", - "LLVMVEInfo", - "LLVMSystemZDisassembler", - "LLVMSystemZAsmParser", - "LLVMSystemZCodeGen", - "LLVMSystemZDesc", - "LLVMSystemZInfo", - "LLVMSparcDisassembler", - "LLVMSparcAsmParser", - "LLVMSparcCodeGen", - "LLVMSparcDesc", - "LLVMSparcInfo", - "LLVMRISCVDisassembler", - "LLVMRISCVAsmParser", - "LLVMRISCVCodeGen", - "LLVMRISCVDesc", - "LLVMRISCVInfo", - "LLVMPowerPCDisassembler", - "LLVMPowerPCAsmParser", - "LLVMPowerPCCodeGen", - "LLVMPowerPCDesc", - "LLVMPowerPCInfo", - "LLVMNVPTXCodeGen", - "LLVMNVPTXDesc", - "LLVMNVPTXInfo", - "LLVMMSP430Disassembler", - "LLVMMSP430AsmParser", - "LLVMMSP430CodeGen", - "LLVMMSP430Desc", - "LLVMMSP430Info", - "LLVMMipsDisassembler", - "LLVMMipsAsmParser", - "LLVMMipsCodeGen", - "LLVMMipsDesc", - "LLVMMipsInfo", - "LLVMLanaiDisassembler", - "LLVMLanaiCodeGen", - "LLVMLanaiAsmParser", - "LLVMLanaiDesc", - "LLVMLanaiInfo", - "LLVMHexagonDisassembler", - "LLVMHexagonCodeGen", - "LLVMHexagonAsmParser", - "LLVMHexagonDesc", - "LLVMHexagonInfo", - "LLVMBPFDisassembler", - "LLVMBPFAsmParser", - "LLVMBPFCodeGen", - "LLVMBPFDesc", - "LLVMBPFInfo", - "LLVMAVRDisassembler", - "LLVMAVRAsmParser", - "LLVMAVRCodeGen", - "LLVMAVRDesc", - "LLVMAVRInfo", - "LLVMARMDisassembler", - "LLVMARMAsmParser", - "LLVMARMCodeGen", - "LLVMARMDesc", - "LLVMARMUtils", - "LLVMARMInfo", - "LLVMAMDGPUTargetMCA", - "LLVMAMDGPUDisassembler", - "LLVMAMDGPUAsmParser", - "LLVMAMDGPUCodeGen", - "LLVMAMDGPUDesc", - "LLVMAMDGPUUtils", - "LLVMAMDGPUInfo", - "LLVMAArch64Disassembler", - "LLVMAArch64AsmParser", - "LLVMAArch64CodeGen", - "LLVMAArch64Desc", - "LLVMAArch64Utils", - "LLVMAArch64Info", - "LLVMOrcJIT", - "LLVMMCJIT", - "LLVMJITLink", - "LLVMInterpreter", - "LLVMExecutionEngine", - "LLVMRuntimeDyld", - "LLVMOrcTargetProcess", - "LLVMOrcShared", - "LLVMDWP", - "LLVMSymbolize", - "LLVMDebugInfoPDB", - "LLVMDebugInfoGSYM", - "LLVMOption", - "LLVMObjectYAML", - "LLVMMCA", - "LLVMMCDisassembler", - "LLVMLTO", - "LLVMPasses", - "LLVMCFGuard", - "LLVMCoroutines", - "LLVMObjCARCOpts", - "LLVMipo", - "LLVMVectorize", - "LLVMLinker", - "LLVMInstrumentation", - "LLVMFrontendOpenMP", - "LLVMFrontendOpenACC", - "LLVMExtensions", - "LLVMDWARFLinker", - "LLVMGlobalISel", - "LLVMMIRParser", - "LLVMAsmPrinter", - "LLVMDebugInfoMSF", - "LLVMSelectionDAG", - "LLVMCodeGen", - "LLVMIRReader", - "LLVMAsmParser", - "LLVMInterfaceStub", - "LLVMFileCheck", - "LLVMFuzzMutate", - "LLVMTarget", - "LLVMScalarOpts", - "LLVMInstCombine", - "LLVMAggressiveInstCombine", - "LLVMTransformUtils", - "LLVMBitWriter", - "LLVMAnalysis", - "LLVMProfileData", - "LLVMDebugInfoDWARF", - "LLVMObject", - "LLVMTextAPI", - "LLVMMCParser", - "LLVMMC", - "LLVMDebugInfoCodeView", - "LLVMBitReader", - "LLVMCore", - "LLVMRemarks", - "LLVMBitstreamReader", - "LLVMBinaryFormat", - "LLVMSupport", - "LLVMDemangle", -}; diff --git a/ci/azure/macos_arm64_script b/ci/azure/macos_arm64_script deleted file mode 100755 index 4df3106f31..0000000000 --- a/ci/azure/macos_arm64_script +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/sh - -set -x -set -e - -brew update && brew install ncurses s3cmd - -ZIGDIR="$(pwd)" - -HOST_ARCH="x86_64" -HOST_TARGET="$HOST_ARCH-macos-none" -HOST_MCPU="baseline" -HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.10.0-dev.2931+bdf3fa12f" -HOST_PREFIX="$HOME/$HOST_CACHE_BASENAME" - -ARCH="aarch64" -TARGET="$ARCH-macos-none" -MCPU="apple_a14" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.2931+bdf3fa12f" -PREFIX="$HOME/$CACHE_BASENAME" - -JOBS="-j2" - -rm -rf $HOST_PREFIX $PREFIX -cd $HOME - -wget -nv "https://ziglang.org/deps/$HOST_CACHE_BASENAME.tar.xz" -wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz" -tar xf "$HOST_CACHE_BASENAME.tar.xz" -tar xf "$CACHE_BASENAME.tar.xz" - -cd $ZIGDIR - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git config core.abbrev 9 -git fetch --unshallow || true -git fetch --tags - -# Build host zig compiler in debug so that we can get the -# current version when packaging - -ZIG="$HOST_PREFIX/bin/zig" - -export CC="$ZIG cc -target $HOST_TARGET -mcpu=$HOST_MCPU" -export CXX="$ZIG c++ -target $HOST_TARGET -mcpu=$HOST_MCPU" - -mkdir build.host -cd build.host -cmake .. \ - -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \ - -DCMAKE_PREFIX_PATH="$HOST_PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DZIG_TARGET_TRIPLE="$HOST_TARGET" \ - -DZIG_TARGET_MCPU="$HOST_MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_OMIT_STAGE2=ON - -unset CC -unset CXX - -make $JOBS install - -# Build zig compiler cross-compiled for arm64 -cd $ZIGDIR - -ZIG="$ZIGDIR/build.host/release/bin/zig" - -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -mkdir build -cd build -cmake .. \ - -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_EXECUTABLE="$ZIG" \ - -DZIG_STATIC=ON - -unset CC -unset CXX - -make $JOBS install - -if [ "${BUILD_REASON}" != "PullRequest" ]; then - mv ../LICENSE release/ - - # We do not run test suite but still need langref. - mkdir -p release/docs - $ZIG run ../doc/docgen.zig -- $ZIG ../doc/langref.html.in release/docs/langref.html - - # Produce the experimental std lib documentation. - mkdir -p release/docs/std - $ZIG test ../lib/std/std.zig \ - --zig-lib-dir ../lib \ - -femit-docs=release/docs/std \ - -fno-emit-bin - - mv release/bin/zig release/ - rmdir release/bin - - VERSION=$(../build.host/release/bin/zig version) - DIRNAME="zig-macos-$ARCH-$VERSION" - TARBALL="$DIRNAME.tar.xz" - mv release "$DIRNAME" - tar cfJ "$TARBALL" "$DIRNAME" - - mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg" - s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/ - - SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1) - BYTESIZE=$(wc -c < $TARBALL) - - JSONFILE="macos-$GITBRANCH.json" - touch $JSONFILE - echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE - echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE - echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE - - s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE" - s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json" - - # `set -x` causes these variables to be mangled. - # See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html - set +x - echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL" - echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM" - echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE" -fi diff --git a/ci/azure/macos_script b/ci/azure/macos_script index b244a73869..4bb083e5e2 100755 --- a/ci/azure/macos_script +++ b/ci/azure/macos_script @@ -34,13 +34,12 @@ git fetch --tags mkdir build cd build cmake .. \ - -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \ + -DCMAKE_INSTALL_PREFIX="stage3-release" \ -DCMAKE_PREFIX_PATH="$PREFIX" \ -DCMAKE_BUILD_TYPE=Release \ -DZIG_TARGET_TRIPLE="$TARGET" \ -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_OMIT_STAGE2=ON + -DZIG_STATIC=ON # Now cmake will use zig as the C/C++ compiler. We reset the environment variables # so that installation and testing do not get affected by them. @@ -49,45 +48,21 @@ unset CXX make $JOBS install -# Here we rebuild zig but this time using the Zig binary we just now produced to -# build zig1.o rather than relying on the one built with stage0. See -# https://github.com/ziglang/zig/issues/6830 for more details. -cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig" -make $JOBS install - -# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt. -release/bin/zig build -p stage2 -Denable-llvm - -stage2/bin/zig build test-behavior - -# TODO: upgrade these to test stage2 instead of stage1 -# TODO: upgrade these to test stage3 instead of stage2 -release/bin/zig build test-behavior -Denable-macos-sdk -Domit-stage2 -release/bin/zig build test-compiler-rt -Denable-macos-sdk -release/bin/zig build test-std -Denable-macos-sdk -release/bin/zig build test-universal-libc -Denable-macos-sdk -release/bin/zig build test-compare-output -Denable-macos-sdk -release/bin/zig build test-standalone -Denable-macos-sdk -release/bin/zig build test-stack-traces -Denable-macos-sdk -release/bin/zig build test-cli -Denable-macos-sdk -release/bin/zig build test-asm-link -Denable-macos-sdk -release/bin/zig build test-translate-c -Denable-macos-sdk -release/bin/zig build test-run-translated-c -Denable-macos-sdk -release/bin/zig build docs -Denable-macos-sdk -release/bin/zig build test-fmt -Denable-macos-sdk -release/bin/zig build test-cases -Denable-macos-sdk -Dsingle-threaded -release/bin/zig build test-link -Denable-macos-sdk -Domit-stage2 +stage3-release/bin/zig build test docs \ + -Denable-macos-sdk \ + -Dstatic-llvm \ + --search-prefix "$PREFIX" if [ "${BUILD_REASON}" != "PullRequest" ]; then - mv ../LICENSE release/ - mv ../zig-cache/langref.html release/ - mv release/bin/zig release/ - rmdir release/bin + mv ../LICENSE stage3-release/ + mv ../zig-cache/langref.html stage3-release/ + mv stage3-release/bin/zig stage3-release/ + rmdir stage3-release/bin - VERSION=$(release/zig version) + VERSION=$(stage3-release/zig version) DIRNAME="zig-macos-$ARCH-$VERSION" TARBALL="$DIRNAME.tar.xz" - mv release "$DIRNAME" + mv stage3-release "$DIRNAME" tar cfJ "$TARBALL" "$DIRNAME" mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg" diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml index 75e9e7ef8e..45504c5b6e 100644 --- a/ci/azure/pipelines.yml +++ b/ci/azure/pipelines.yml @@ -10,24 +10,13 @@ jobs: - script: ci/azure/macos_script name: main displayName: 'Build and test' -- job: BuildMacOS_arm64 - pool: - vmImage: 'macOS-11' - timeoutInMinutes: 180 - steps: - - task: DownloadSecureFile@1 - inputs: - secureFile: s3cfg - - script: ci/azure/macos_arm64_script - name: main - displayName: 'Build' - job: BuildWindows timeoutInMinutes: 360 pool: vmImage: 'windows-2019' variables: TARGET: 'x86_64-windows-gnu' - ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.2931+bdf3fa12f' + ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3733+a9af47272' ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip' steps: - pwsh: | @@ -37,10 +26,17 @@ jobs: displayName: 'Install ZIG/LLVM/CLANG/LLD' - pwsh: | - Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build" - Set-Variable -Name ZIGINSTALLDIR -Value "${ZIGBUILDDIR}\dist" + Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib" + Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release" Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)" + function CheckLastExitCode { + if (!$?) { + exit 1 + } + return 0 + } + # Make the `zig version` number consistent. # This will affect the `zig build` command below which uses `git describe`. git config core.abbrev 9 @@ -49,64 +45,45 @@ jobs: git fetch --unshallow # `git describe` won't work on a shallow repo } - # The dev kit zip file that we have here is old, and may be incompatible with - # the build.zig script of master branch. So we keep an old version of build.zig - # here in the CI directory. - mv build.zig build.zig.master - mv ci/azure/build.zig build.zig - - mkdir $ZIGBUILDDIR - cd $ZIGBUILDDIR - - & "${ZIGPREFIXPATH}/bin/zig.exe" build ` + & "$ZIGPREFIXPATH\bin\zig.exe" build ` --prefix "$ZIGINSTALLDIR" ` --search-prefix "$ZIGPREFIXPATH" ` - -Dstage1 ` - <# stage2 is omitted until we resolve https://github.com/ziglang/zig/issues/6485 #> ` - -Domit-stage2 ` + --zig-lib-dir "$ZIGLIBDIR" ` + -Denable-stage1 ` -Dstatic-llvm ` -Drelease ` -Dstrip ` -Duse-zig-libcxx ` -Dtarget=$(TARGET) - - cd - - - # Now that we have built an up-to-date zig.exe, we restore the original - # build script from master branch. - rm build.zig - mv build.zig.master build.zig - + CheckLastExitCode name: build displayName: 'Build' - pwsh: | - Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist" + Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release" - # Sadly, stage2 is omitted from this build to save memory on the CI server. Once self-hosted is - # built with itself and does not gobble as much memory, we can enable these tests. - #& "$ZIGINSTALLDIR\bin\zig.exe" test "..\test\behavior.zig" -fno-stage1 -fLLVM -I "..\test" 2>&1 + function CheckLastExitCode { + if (!$?) { + exit 1 + } + return 0 + } - & "$ZIGINSTALLDIR\bin\zig.exe" build test-toolchain -Dskip-non-native -Dskip-stage2-tests 2>&1 - & "$ZIGINSTALLDIR\bin\zig.exe" build test-std -Dskip-non-native 2>&1 + & "$ZIGINSTALLDIR\bin\zig.exe" build test docs ` + --search-prefix "$ZIGPREFIXPATH" ` + -Dstatic-llvm ` + -Dskip-non-native ` + -Dskip-stage2-tests + CheckLastExitCode name: test displayName: 'Test' - - pwsh: | - Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist" - - & "$ZIGINSTALLDIR\bin\zig.exe" build docs - timeoutInMinutes: 60 - name: doc - displayName: 'Documentation' - - task: DownloadSecureFile@1 inputs: name: aws_credentials secureFile: aws_credentials - pwsh: | - Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build" $Env:AWS_SHARED_CREDENTIALS_FILE = "$Env:DOWNLOADSECUREFILE_SECUREFILEPATH" # Workaround Azure networking issue @@ -114,21 +91,20 @@ jobs: $Env:AWS_EC2_METADATA_DISABLED = "true" $Env:AWS_REGION = "us-west-2" - cd "$ZIGBUILDDIR" - mv ../LICENSE dist/ - mv ../zig-cache/langref.html dist/ - mv dist/bin/zig.exe dist/ - rmdir dist/bin + mv LICENSE stage3-release/ + mv zig-cache/langref.html stage3-release/ + mv stage3-release/bin/zig.exe stage3-release/ + rmdir stage3-release/bin # Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig - mv dist/lib/zig dist/lib2 - rmdir dist/lib - mv dist/lib2 dist/lib + mv stage3-release/lib/zig stage3-release/lib2 + rmdir stage3-release/lib + mv stage3-release/lib2 stage3-release/lib - Set-Variable -Name VERSION -Value $(./dist/zig.exe version) + Set-Variable -Name VERSION -Value $(./stage3-release/zig.exe version) Set-Variable -Name DIRNAME -Value "zig-windows-x86_64-$VERSION" Set-Variable -Name TARBALL -Value "$DIRNAME.zip" - mv dist "$DIRNAME" + mv stage3-release "$DIRNAME" 7z a "$TARBALL" "$DIRNAME" aws s3 cp ` @@ -168,7 +144,6 @@ jobs: - job: OnMasterSuccess dependsOn: - BuildMacOS - - BuildMacOS_arm64 - BuildWindows condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) strategy: diff --git a/ci/drone/drone.yml b/ci/drone/drone.yml index 363d168a21..6a66913a5a 100644 --- a/ci/drone/drone.yml +++ b/ci/drone/drone.yml @@ -13,65 +13,65 @@ steps: commands: - ./ci/drone/linux_script_build -- name: test-1 +- name: behavior depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 1 + - ./ci/drone/test_linux_behavior -- name: test-2 +- name: std_Debug depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 2 + - ./ci/drone/test_linux_std_Debug -- name: test-3 +- name: std_ReleaseSafe depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 3 + - ./ci/drone/test_linux_std_ReleaseSafe -- name: test-4 +- name: std_ReleaseFast depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 4 + - ./ci/drone/test_linux_std_ReleaseFast -- name: test-5 +- name: std_ReleaseSmall depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 5 + - ./ci/drone/test_linux_std_ReleaseSmall -- name: test-6 +- name: misc depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 6 + - ./ci/drone/test_linux_misc -- name: test-7 +- name: cases depends_on: - build image: ziglang/static-base:llvm14-aarch64-3 commands: - - ./ci/drone/linux_script_test 7 + - ./ci/drone/test_linux_cases - name: finalize depends_on: - build - - test-1 - - test-2 - - test-3 - - test-4 - - test-5 - - test-6 - - test-7 + - behavior + - std_Debug + - std_ReleaseSafe + - std_ReleaseFast + - std_ReleaseSmall + - misc + - cases image: ziglang/static-base:llvm14-aarch64-3 environment: SRHT_OAUTH_TOKEN: diff --git a/ci/drone/linux_script_base b/ci/drone/linux_script_base deleted file mode 100755 index 2788eb2df6..0000000000 --- a/ci/drone/linux_script_base +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -# https://docs.drone.io/pipeline/docker/syntax/workspace/ -# -# Drone automatically creates a temporary volume, known as your workspace, -# where it clones your repository. The workspace is the current working -# directory for each step in your pipeline. -# -# Because the workspace is a volume, filesystem changes are persisted between -# pipeline steps. In other words, individual steps can communicate and share -# state using the filesystem. -# -# Workspace volumes are ephemeral. They are created when the pipeline starts -# and destroyed after the pipeline completes. - -set -x -set -e - -TRIPLEARCH="$(uname -m)" -DISTDIR="$DRONE_WORKSPACE/dist" - -export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" diff --git a/ci/drone/linux_script_build b/ci/drone/linux_script_build index 58dad5f14c..022de1d217 100755 --- a/ci/drone/linux_script_build +++ b/ci/drone/linux_script_build @@ -1,17 +1,16 @@ #!/bin/sh -. ./ci/drone/linux_script_base +set -x +set -e -# Probe CPU/brand details. -# TODO: `lscpu` is changing package names in EDGE to `util-linux-misc` -apk update -apk add util-linux -echo "lscpu:" -lscpu | sed 's,^, : ,' +ARCH="$(uname -m)" +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" + +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" PREFIX="/deps/local" ZIG="$PREFIX/bin/zig" -TARGET="$TRIPLEARCH-linux-musl" +TARGET="$ARCH-linux-musl" MCPU="baseline" export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" @@ -30,8 +29,8 @@ cat <<'ENDFILE' >$PREFIX/bin/ranlib /deps/local/bin/zig ranlib $@ ENDFILE -chmod +x $PREFIX/bin/ar -chmod +x $PREFIX/bin/ranlib +chmod +x "$PREFIX/bin/ar" +chmod +x "$PREFIX/bin/ranlib" # Make the `zig version` number consistent. # This will affect the cmake command below. @@ -42,8 +41,8 @@ git fetch --tags mkdir build cd build cmake .. \ - -DCMAKE_INSTALL_PREFIX="$DISTDIR" \ -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_AR="$PREFIX/bin/ar" \ -DCMAKE_RANLIB="$PREFIX/bin/ranlib" \ @@ -57,9 +56,3 @@ cmake .. \ unset CC unset CXX samu install - -# Here we rebuild Zig but this time using the Zig binary we just now produced to -# build zig1.o rather than relying on the one built with stage0. See -# https://github.com/ziglang/zig/issues/6830 for more details. -cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig" -samu install diff --git a/ci/drone/linux_script_finalize b/ci/drone/linux_script_finalize index 9d70a9b09c..4219bd19ac 100755 --- a/ci/drone/linux_script_finalize +++ b/ci/drone/linux_script_finalize @@ -1,6 +1,12 @@ #!/bin/sh -. ./ci/drone/linux_script_base +set -x +set -e + +ARCH="$(uname -m)" +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" + +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" if [ -n "$DRONE_PULL_REQUEST" ]; then exit 0 @@ -12,16 +18,16 @@ pip3 install s3cmd cd build -mv ../LICENSE "$DISTDIR/" -mv ../zig-cache/langref.html "$DISTDIR/" -mv "$DISTDIR/bin/zig" "$DISTDIR/" -rmdir "$DISTDIR/bin" +mv ../LICENSE "$INSTALL_PREFIX/" +mv ../zig-cache/langref.html "$INSTALL_PREFIX/" +mv "$INSTALL_PREFIX/bin/zig" "$INSTALL_PREFIX/" +rmdir "$INSTALL_PREFIX/bin" GITBRANCH="$DRONE_BRANCH" -VERSION="$("$DISTDIR/zig" version)" -DIRNAME="zig-linux-$TRIPLEARCH-$VERSION" +VERSION="$("$INSTALL_PREFIX/zig" version)" +DIRNAME="zig-linux-$ARCH-$VERSION" TARBALL="$DIRNAME.tar.xz" -mv "$DISTDIR" "$DIRNAME" +mv "$INSTALL_PREFIX" "$DIRNAME" tar cfJ "$TARBALL" "$DIRNAME" s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/ @@ -35,7 +41,7 @@ echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE -s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json" +s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-linux-$VERSION.json" if [ "$GITBRANCH" = "master" ]; then # avoid leaking oauth token set +x diff --git a/ci/drone/linux_script_test b/ci/drone/linux_script_test deleted file mode 100755 index b748745da9..0000000000 --- a/ci/drone/linux_script_test +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -. ./ci/drone/linux_script_base - -BUILD_FLAGS="-Dskip-non-native" - -case "$1" in - 1) - ./build/zig build $BUILD_FLAGS test-behavior - ./build/zig build $BUILD_FLAGS test-compiler-rt - ./build/zig build $BUILD_FLAGS test-fmt - ./build/zig build $BUILD_FLAGS docs - ;; - 2) - # Debug - ./build/zig build $BUILD_FLAGS test-std -Dskip-release-safe -Dskip-release-fast -Dskip-release-small - ;; - 3) - # ReleaseSafe - ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-fast -Dskip-release-small -Dskip-non-native -Dskip-single-threaded - ;; - 4) - # ReleaseFast - ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-safe -Dskip-release-small -Dskip-non-native -Dskip-single-threaded - ;; - 5) - # ReleaseSmall - ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-safe -Dskip-release-fast - ;; - 6) - ./build/zig build $BUILD_FLAGS test-universal-libc - ./build/zig build $BUILD_FLAGS test-compare-output - ./build/zig build $BUILD_FLAGS test-standalone -Dskip-release-safe - ./build/zig build $BUILD_FLAGS test-stack-traces - ./build/zig build $BUILD_FLAGS test-cli - ./build/zig build $BUILD_FLAGS test-asm-link - ./build/zig build $BUILD_FLAGS test-translate-c - ;; - 7) - ./build/zig build $BUILD_FLAGS # test building self-hosted without LLVM - ./build/zig build $BUILD_FLAGS test-cases - ;; - '') - echo "error: expecting test group argument" - exit 1 - ;; - *) - echo "error: unknown test group: $1" - exit 1 - ;; -esac diff --git a/ci/drone/test_linux_behavior b/ci/drone/test_linux_behavior new file mode 100755 index 0000000000..fb5b1fa9e4 --- /dev/null +++ b/ci/drone/test_linux_behavior @@ -0,0 +1,13 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +$ZIG build test-behavior -Dskip-non-native +$ZIG build test-compiler-rt -Dskip-non-native +$ZIG build test-fmt +$ZIG build docs diff --git a/ci/drone/test_linux_cases b/ci/drone/test_linux_cases new file mode 100755 index 0000000000..383ddf7b37 --- /dev/null +++ b/ci/drone/test_linux_cases @@ -0,0 +1,11 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +$ZIG build -Dskip-non-native # test building self-hosted without LLVM +$ZIG build -Dskip-non-native test-cases diff --git a/ci/drone/test_linux_misc b/ci/drone/test_linux_misc new file mode 100755 index 0000000000..fc3dfcf4d4 --- /dev/null +++ b/ci/drone/test_linux_misc @@ -0,0 +1,16 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +$ZIG build test-universal-libc -Dskip-non-native +$ZIG build test-compare-output -Dskip-non-native +$ZIG build test-standalone -Dskip-non-native -Dskip-release-safe +$ZIG build test-stack-traces -Dskip-non-native +$ZIG build test-cli -Dskip-non-native +$ZIG build test-asm-link -Dskip-non-native +$ZIG build test-translate-c -Dskip-non-native diff --git a/ci/drone/test_linux_std_Debug b/ci/drone/test_linux_std_Debug new file mode 100755 index 0000000000..d05554d5a5 --- /dev/null +++ b/ci/drone/test_linux_std_Debug @@ -0,0 +1,10 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +$ZIG build test-std -Dskip-release-safe -Dskip-release-fast -Dskip-release-small -Dskip-non-native diff --git a/ci/drone/test_linux_std_ReleaseFast b/ci/drone/test_linux_std_ReleaseFast new file mode 100755 index 0000000000..7e117b313a --- /dev/null +++ b/ci/drone/test_linux_std_ReleaseFast @@ -0,0 +1,10 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +$ZIG build test-std -Dskip-debug -Dskip-release-safe -Dskip-release-small -Dskip-non-native -Dskip-single-threaded diff --git a/ci/drone/test_linux_std_ReleaseSafe b/ci/drone/test_linux_std_ReleaseSafe new file mode 100755 index 0000000000..b494ea6e47 --- /dev/null +++ b/ci/drone/test_linux_std_ReleaseSafe @@ -0,0 +1,10 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +$ZIG build test-std -Dskip-debug -Dskip-release-fast -Dskip-release-small -Dskip-non-native -Dskip-single-threaded diff --git a/ci/drone/test_linux_std_ReleaseSmall b/ci/drone/test_linux_std_ReleaseSmall new file mode 100755 index 0000000000..ffd366d454 --- /dev/null +++ b/ci/drone/test_linux_std_ReleaseSmall @@ -0,0 +1,16 @@ +#!/bin/sh + +set -x +set -e + +INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release" +ZIG="$INSTALL_PREFIX/bin/zig" +export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache" + +# Empirically, this takes about 55 minutes on the CI, and is the bottleneck +# causing timeouts. So this is disabled in favor of running a smaller set +# of ReleaseSmall std lib tests. +# $ZIG build test-std -Dskip-debug -Dskip-release-safe -Dskip-release-fast -Dskip-non-native + +$ZIG test lib/std/std.zig -OReleaseSmall +$ZIG test lib/std/std.zig -OReleaseSmall -lc diff --git a/ci/srht/freebsd_script b/ci/srht/freebsd_script index 9fd7c0be65..326e3cadf5 100755 --- a/ci/srht/freebsd_script +++ b/ci/srht/freebsd_script @@ -7,7 +7,9 @@ sudo pkg update -fq sudo pkg install -y cmake py39-s3cmd wget curl jq samurai ZIGDIR="$(pwd)" -CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.10.0-dev.2931+bdf3fa12f" +TARGET="x86_64-freebsd-gnu" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.3524+74673b7f6" PREFIX="$HOME/$CACHE_BASENAME" cd $HOME @@ -29,34 +31,47 @@ export TERM=dumb mkdir build cd build -cmake .. \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_PREFIX_PATH=$PREFIX \ - "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \ - -DZIG_STATIC=ON \ - -DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \ - -GNinja -samu install -# TODO ld.lld: error: undefined symbol: main -# >>> referenced by crt1_c.c:75 (/usr/src/lib/csu/amd64/crt1_c.c:75) -# >>> /usr/lib/crt1.o:(_start) -#release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH=$PREFIX \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -GNinja + +# TODO: eliminate this workaround. Without this, zig does not end up passing +# -isystem /usr/include when building libc++, resulting in #include +# "file not found" errors. +echo "include_dir=/usr/include" >>libc.txt +echo "sys_include_dir=/usr/include" >>libc.txt +echo "crt_dir=/usr/lib" >>libc.txt +echo "msvc_lib_dir=" >>libc.txt +echo "kernel32_lib_dir=" >>libc.txt +echo "gcc_dir=" >>libc.txt +ZIG_LIBC_TXT="$(pwd)/libc.txt" + +ZIG_LIBC="$ZIG_LIBC_TXT" samu install # Here we skip some tests to save time. -release/bin/zig build test -Dskip-stage1 -Dskip-non-native +stage3/bin/zig build test docs \ + -Dstatic-llvm \ + --search-prefix "$PREFIX" \ + -Dskip-stage1 \ + -Dskip-non-native if [ -f ~/.s3cfg ]; then - mv ../LICENSE release/ - mv ../zig-cache/langref.html release/ - mv release/bin/zig release/ - rmdir release/bin + mv ../LICENSE stage3/ + mv ../zig-cache/langref.html stage3/ + mv stage3/bin/zig stage3/ + rmdir stage3/bin GITBRANCH=$(basename $GITHUB_REF) - VERSION=$(release/zig version) + VERSION=$(stage3/zig version) DIRNAME="zig-freebsd-x86_64-$VERSION" TARBALL="$DIRNAME.tar.xz" - mv release "$DIRNAME" + mv stage3 "$DIRNAME" tar cfJ "$TARBALL" "$DIRNAME" s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/ diff --git a/ci/srht/update_download_page b/ci/srht/update_download_page index f064712d4e..89c26952e5 100755 --- a/ci/srht/update_download_page +++ b/ci/srht/update_download_page @@ -100,6 +100,27 @@ cd "$SRCTARBALLDIR/ci/srht" CIDIR="$(pwd)" cd "$HOME" + +# Upload new stdlib autodocs +mkdir -p docs_to_upload/documentation/master/std/ +gzip -c -9 "$ZIGDIR/docs/std/index.html" > docs_to_upload/documentation/master/std/index.html +gzip -c -9 "$ZIGDIR/docs/std/data.js" > docs_to_upload/documentation/master/std/data.js +gzip -c -9 "$ZIGDIR/docs/std/main.js" > docs_to_upload/documentation/master/std/main.js +gzip -c -9 "$LANGREF" > docs_to_upload/documentation/master/index.html +$S3CMD put -P --no-mime-magic --recursive --add-header="Content-Encoding:gzip" --add-header="Cache-Control: max-age=0, must-revalidate" "docs_to_upload/" s3://ziglang.org/ + +mkdir -p docs_src_to_upload/documentation/master/std/ +cp -r "$ZIGDIR/docs/std/src" docs_src_to_upload/documentation/master/std/ +$S3CMD put -P --no-mime-magic --recursive --add-header:"Content-Type:text/html" --add-header="Cache-Control: max-age=0, must-revalidate" "docs_src_to_upload/" s3://ziglang.org/ + +## Copy without compression: +# mkdir -p docs_to_upload/documentation/master/std/ +# cp "$ZIGDIR/docs/std/index.html" docs_to_upload/documentation/master/std/index.html +# cp "$ZIGDIR/docs/std/data.js" docs_to_upload/documentation/master/std/data.js +# cp "$ZIGDIR/docs/std/main.js" docs_to_upload/documentation/master/std/main.js +# cp "$LANGREF" docs_to_upload/documentation/master/index.html +# $S3CMD put -P --no-mime-magic --recursive --add-header="Cache-Control: max-age=0, must-revalidate" "docs_to_upload/" s3://ziglang.org/ + git clone --depth 1 git@github.com:ziglang/www.ziglang.org.git cd www.ziglang.org WWWDIR="$(pwd)" @@ -108,12 +129,6 @@ $S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536 cd "$WWWDIR" cp "$CIDIR/out/index.json" data/releases.json -mkdir -p content/documentation/master/std -cp "$LANGREF" content/documentation/master/index.html -cp "$ZIGDIR/docs/std/index.html" content/documentation/master/std/index.html -cp "$ZIGDIR/docs/std/data.js" content/documentation/master/std/data.js -cp "$ZIGDIR/docs/std/main.js" content/documentation/master/std/main.js git add data/releases.json -git add content/ -git commit -m "CI: update releases and docs" +git commit -m "CI: update releases" git push origin master diff --git a/ci/zinc/build_aarch64_macos b/ci/zinc/build_aarch64_macos new file mode 100755 index 0000000000..5e97ccc913 --- /dev/null +++ b/ci/zinc/build_aarch64_macos @@ -0,0 +1,20 @@ +#!/bin/sh + +set -x +set -e + +RELEASE_STAGING="$DRONE_WORKSPACE/_release/staging" +TARGET="aarch64-macos-none" +MCPU="apple_a14" +INSTALL_PREFIX="$DRONE_WORKSPACE/$TARGET" +SEARCH_PREFIX="/deps/$TARGET" + +"$RELEASE_STAGING/bin/zig" build \ + --prefix "$INSTALL_PREFIX" \ + --search-prefix "$SEARCH_PREFIX" \ + -Dstatic-llvm \ + -Drelease \ + -Dstrip \ + -Dtarget="$TARGET" \ + -Dmcpu="$MCPU" \ + -Denable-stage1 diff --git a/ci/zinc/configure_git b/ci/zinc/configure_git new file mode 100755 index 0000000000..146eafe601 --- /dev/null +++ b/ci/zinc/configure_git @@ -0,0 +1,10 @@ +#!/bin/sh + +set -x +set -e + +# Make the `zig version` number consistent. +# This will affect the cmake commands that follow. +# This is in its own script because git does not support this command +# being run concurrently with itself. +git config core.abbrev 9 diff --git a/ci/zinc/drone.yml b/ci/zinc/drone.yml index 6bb7d73b41..3aa9e9af7b 100644 --- a/ci/zinc/drone.yml +++ b/ci/zinc/drone.yml @@ -9,26 +9,75 @@ workspace: path: /workspace steps: -- name: test - image: ci/debian-amd64:11.1-6 +- name: configure_git + image: ci/debian-amd64:11.1-9 commands: - - ./ci/zinc/linux_test.sh + - ./ci/zinc/configure_git -- name: package +- name: test_stage3_debug depends_on: - - test + - configure_git + image: ci/debian-amd64:11.1-9 + commands: + - ./ci/zinc/linux_test_stage3_debug + +- name: test_stage3_release + depends_on: + - configure_git + image: ci/debian-amd64:11.1-9 + commands: + - ./ci/zinc/linux_test_stage3_release + +- name: build_aarch64_macos + depends_on: + - test_stage3_release + image: ci/debian-amd64:11.1-9 + commands: + - ./ci/zinc/build_aarch64_macos + +- name: linux_package + depends_on: + - test_stage3_debug + - test_stage3_release when: branch: - master event: - push - image: ci/debian-amd64:11.1-6 + image: ci/debian-amd64:11.1-9 environment: AWS_ACCESS_KEY_ID: from_secret: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: from_secret: AWS_SECRET_ACCESS_KEY + commands: + - ./ci/zinc/linux_package + +- name: macos_package + depends_on: + - test_stage3_debug + - build_aarch64_macos + when: + branch: + - master + event: + - push + image: ci/debian-amd64:11.1-9 + environment: + AWS_ACCESS_KEY_ID: + from_secret: AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: + from_secret: AWS_SECRET_ACCESS_KEY + commands: + - ./ci/zinc/macos_package + +- name: notify_lavahut + depends_on: + - macos_package + - linux_package + image: ci/debian-amd64:11.1-9 + environment: SRHT_OAUTH_TOKEN: from_secret: SRHT_OAUTH_TOKEN commands: - - ./ci/zinc/linux_package.sh + - ./ci/zinc/notify_lavahut diff --git a/ci/zinc/linux_base.sh b/ci/zinc/linux_base.sh deleted file mode 100755 index f1e9924258..0000000000 --- a/ci/zinc/linux_base.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# https://docs.drone.io/pipeline/docker/syntax/workspace/ -# -# Drone automatically creates a temporary volume, known as your workspace, -# where it clones your repository. The workspace is the current working -# directory for each step in your pipeline. -# -# Because the workspace is a volume, filesystem changes are persisted between -# pipeline steps. In other words, individual steps can communicate and share -# state using the filesystem. -# -# Workspace volumes are ephemeral. They are created when the pipeline starts -# and destroyed after the pipeline completes. - -set -x -set -e - -ARCH="$(uname -m)" - -DEPS_LOCAL="/deps/local" -WORKSPACE="$DRONE_WORKSPACE" - -DEBUG_STAGING="$WORKSPACE/_debug/staging" -RELEASE_STAGING="$WORKSPACE/_release/staging" - -export PATH=$DEPS_LOCAL/bin:$PATH diff --git a/ci/zinc/linux_package.sh b/ci/zinc/linux_package similarity index 54% rename from ci/zinc/linux_package.sh rename to ci/zinc/linux_package index 547a2d76b8..f7a7dccbae 100755 --- a/ci/zinc/linux_package.sh +++ b/ci/zinc/linux_package @@ -1,25 +1,30 @@ #!/bin/sh -. ./ci/zinc/linux_base.sh +set -x +set -e -cp LICENSE $RELEASE_STAGING/ -cp zig-cache/langref.html $RELEASE_STAGING/docs/ +ARCH="$(uname -m)" +OS="linux" +RELEASE_STAGING="$DRONE_WORKSPACE/_release/staging" +VERSION=$($RELEASE_STAGING/bin/zig version) +BASENAME="zig-$OS-$ARCH-$VERSION" +TARBALL="$BASENAME.tar.xz" + +# This runs concurrently with the macos_package script, so it should not make +# any changes to the filesystem that will cause problems for the other script. + +cp -r "$RELEASE_STAGING" "$BASENAME" # Remove the unnecessary bin dir in $prefix/bin/zig -mv $RELEASE_STAGING/bin/zig $RELEASE_STAGING/ -rmdir $RELEASE_STAGING/bin +mv $BASENAME/bin/zig $BASENAME/ +rmdir $BASENAME/bin # Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig -mv $RELEASE_STAGING/lib/zig $RELEASE_STAGING/lib2 -rmdir $RELEASE_STAGING/lib -mv $RELEASE_STAGING/lib2 $RELEASE_STAGING/lib +mv $BASENAME/lib/zig $BASENAME/lib2 +rmdir $BASENAME/lib +mv $BASENAME/lib2 $BASENAME/lib -VERSION=$($RELEASE_STAGING/zig version) -BASENAME="zig-linux-$ARCH-$VERSION" -TARBALL="$BASENAME.tar.xz" -mv "$RELEASE_STAGING" "$BASENAME" tar cfJ "$TARBALL" "$BASENAME" -ls -l "$TARBALL" SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1) BYTESIZE=$(wc -c < $TARBALL) @@ -34,15 +39,7 @@ echo "\"size\": \"$BYTESIZE\"}" >>$MANIFEST s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/ # Publish manifest. -s3cmd put -P --add-header="cache-control: max-age=0, must-revalidate" "$MANIFEST" "s3://ziglang.org/builds/$ARCH-linux-$VERSION.json" - -# Avoid leaking oauth token. -set +x - -cd $WORKSPACE -./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN" - -set -x +s3cmd put -P --add-header="cache-control: max-age=0, must-revalidate" "$MANIFEST" "s3://ziglang.org/builds/$ARCH-$OS-$VERSION.json" # Explicit exit helps show last command duration. exit diff --git a/ci/zinc/linux_test.sh b/ci/zinc/linux_test.sh deleted file mode 100755 index 3a54e82c38..0000000000 --- a/ci/zinc/linux_test.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/sh - -. ./ci/zinc/linux_base.sh - -OLD_ZIG="$DEPS_LOCAL/bin/zig" -TARGET="${ARCH}-linux-musl" -MCPU="baseline" - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git config core.abbrev 9 - -echo "building debug zig with zig version $($OLD_ZIG version)" - -export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU" - -mkdir _debug -cd _debug -cmake .. \ - -DCMAKE_INSTALL_PREFIX="$DEBUG_STAGING" \ - -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -GNinja - -# Now cmake will use zig as the C/C++ compiler. We reset the environment variables -# so that installation and testing do not get affected by them. -unset CC -unset CXX - -ninja install - -STAGE1_ZIG="$DEBUG_STAGING/bin/zig" - -# Here we rebuild zig but this time using the Zig binary we just now produced to -# build zig1.o rather than relying on the one built with stage0. See -# https://github.com/ziglang/zig/issues/6830 for more details. -cmake .. -DZIG_EXECUTABLE="$STAGE1_ZIG" -ninja install - -cd $WORKSPACE - -echo "Looking for non-conforming code formatting..." -echo "Formatting errors can be fixed by running 'zig fmt' on the files printed here." -$STAGE1_ZIG fmt --check . --exclude test/cases/ - -$STAGE1_ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL" -stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL" -stage3/bin/zig build # test building self-hosted without LLVM -stage3/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm - -stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-behavior -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-std -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm -stage3/bin/zig build test-cases -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL" -stage3/bin/zig build test-link -fqemu -fwasmtime -Denable-llvm - -$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime -$STAGE1_ZIG build docs -fqemu -fwasmtime - -# Produce the experimental std lib documentation. -mkdir -p "$RELEASE_STAGING/docs/std" -stage3/bin/zig test lib/std/std.zig \ - --zig-lib-dir lib \ - -femit-docs=$RELEASE_STAGING/docs/std \ - -fno-emit-bin - -# Look for HTML errors. -tidy --drop-empty-elements no -qe zig-cache/langref.html - -# Build release zig. -stage3/bin/zig build \ - --prefix "$RELEASE_STAGING" \ - --search-prefix "$DEPS_LOCAL" \ - -Dstatic-llvm \ - -Drelease \ - -Dstrip \ - -Dtarget="$TARGET" \ - -Dstage1 - -# Explicit exit helps show last command duration. -exit diff --git a/ci/zinc/linux_test_stage3_debug b/ci/zinc/linux_test_stage3_debug new file mode 100755 index 0000000000..074e80d19b --- /dev/null +++ b/ci/zinc/linux_test_stage3_debug @@ -0,0 +1,61 @@ +#!/bin/sh + +set -x +set -e + +ARCH="$(uname -m)" +DEPS_LOCAL="/deps/local" +OLD_ZIG="$DEPS_LOCAL/bin/zig" +TARGET="${ARCH}-linux-musl" +MCPU="baseline" + +export PATH=$DEPS_LOCAL/bin:$PATH + +echo "building stage3-debug with zig version $($OLD_ZIG version)" + +# Override the cache directories so that we don't clobber with the release +# testing script which is running concurrently and in the same directory. +# Normally we want processes to cooperate, but in this case we want them isolated. +export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-cache-local-debug" +export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-cache-global-debug" + +export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU" + +mkdir build-debug +cd build-debug +cmake .. \ + -DCMAKE_INSTALL_PREFIX="$(pwd)/stage3" \ + -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DZIG_STATIC=ON \ + -DZIG_USE_LLVM_CONFIG=OFF \ + -GNinja + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +echo "Looking for non-conforming code formatting..." +stage3/bin/zig fmt --check .. \ + --exclude ../test/cases/ \ + --exclude ../build-debug \ + --exclude ../build-release \ + --exclude "$ZIG_LOCAL_CACHE_DIR" \ + --exclude "$ZIG_GLOBAL_CACHE_DIR" + +# simultaneously test building self-hosted without LLVM and with 32-bit arm +stage3/bin/zig build -Dtarget=arm-linux-musleabihf + +stage3/bin/zig build test \ + -fqemu \ + -fwasmtime \ + -Dstatic-llvm \ + -Dtarget=native-native-musl \ + --search-prefix "$DEPS_LOCAL" + +# Explicit exit helps show last command duration. +exit diff --git a/ci/zinc/linux_test_stage3_release b/ci/zinc/linux_test_stage3_release new file mode 100755 index 0000000000..24bdde17d0 --- /dev/null +++ b/ci/zinc/linux_test_stage3_release @@ -0,0 +1,58 @@ +#!/bin/sh + +set -x +set -e + +ARCH="$(uname -m)" +DEPS_LOCAL="/deps/local" +RELEASE_STAGING="$DRONE_WORKSPACE/_release/staging" +OLD_ZIG="$DEPS_LOCAL/bin/zig" +TARGET="${ARCH}-linux-musl" +MCPU="baseline" + +export PATH=$DEPS_LOCAL/bin:$PATH + +echo "building stage3-release with zig version $($OLD_ZIG version)" + +export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU" + +mkdir build-release +cd build-release +cmake .. \ + -DCMAKE_INSTALL_PREFIX="$RELEASE_STAGING" \ + -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \ + -DCMAKE_BUILD_TYPE=Release \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -GNinja + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +"$RELEASE_STAGING/bin/zig" build test docs \ + -fqemu \ + -fwasmtime \ + -Dstatic-llvm \ + -Dtarget=native-native-musl \ + --search-prefix "$DEPS_LOCAL" + +# Produce the experimental std lib documentation. +mkdir -p "$RELEASE_STAGING/docs/std" +"$RELEASE_STAGING/bin/zig" test ../lib/std/std.zig \ + -femit-docs=$RELEASE_STAGING/docs/std \ + -fno-emit-bin + +cp ../LICENSE $RELEASE_STAGING/ +cp ../zig-cache/langref.html $RELEASE_STAGING/docs/ + +# Look for HTML errors. +tidy --drop-empty-elements no -qe $RELEASE_STAGING/docs/langref.html + +# Explicit exit helps show last command duration. +exit diff --git a/ci/zinc/macos_package b/ci/zinc/macos_package new file mode 100755 index 0000000000..1ee4d5f18d --- /dev/null +++ b/ci/zinc/macos_package @@ -0,0 +1,49 @@ +#!/bin/sh + +set -x +set -e + +ARCH="aarch64" +OS=macos +ZIG_PREFIX="$DRONE_WORKSPACE/_release/staging" +VERSION=$($ZIG_PREFIX/bin/zig version) +TARGET="$ARCH-$OS-none" +INSTALL_PREFIX="$DRONE_WORKSPACE/$TARGET" +BASENAME="zig-$OS-$ARCH-$VERSION" +TARBALL="$BASENAME.tar.xz" + +# This runs concurrently with the linux_package script, so it should not make +# any changes to the filesystem that will cause problems for the other script. + +# Remove the unnecessary bin dir in $prefix/bin/zig +mv $INSTALL_PREFIX/bin/zig $INSTALL_PREFIX/ +rmdir $INSTALL_PREFIX/bin + +# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig +mv $INSTALL_PREFIX/lib/zig $INSTALL_PREFIX/lib2 +rmdir $INSTALL_PREFIX/lib +mv $INSTALL_PREFIX/lib2 $INSTALL_PREFIX/lib + +cp -r "$ZIG_PREFIX/docs" "$INSTALL_PREFIX/" +cp "$ZIG_PREFIX/LICENSE" "$INSTALL_PREFIX/" + +mv "$INSTALL_PREFIX" "$BASENAME" +tar cfJ "$TARBALL" "$BASENAME" + +SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1) +BYTESIZE=$(wc -c < $TARBALL) + +MANIFEST="manifest.json" +touch $MANIFEST +echo "{\"tarball\": \"$TARBALL\"," >>$MANIFEST +echo "\"shasum\": \"$SHASUM\"," >>$MANIFEST +echo "\"size\": \"$BYTESIZE\"}" >>$MANIFEST + +# Publish artifact. +s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/ + +# Publish manifest. +s3cmd put -P --add-header="cache-control: max-age=0, must-revalidate" "$MANIFEST" "s3://ziglang.org/builds/$ARCH-$OS-$VERSION.json" + +# Explicit exit helps show last command duration. +exit diff --git a/ci/zinc/notify_lavahut b/ci/zinc/notify_lavahut new file mode 100755 index 0000000000..4306e5ae69 --- /dev/null +++ b/ci/zinc/notify_lavahut @@ -0,0 +1,9 @@ +#!/bin/sh + +set +x # Avoid leaking oauth token. +set -e + +ZIG_PREFIX="$DRONE_WORKSPACE/_release/staging" +VERSION=$($ZIG_PREFIX/bin/zig version) +cd $DRONE_WORKSPACE +./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN" diff --git a/cmake/install.cmake b/cmake/install.cmake deleted file mode 100644 index 386773e30c..0000000000 --- a/cmake/install.cmake +++ /dev/null @@ -1,37 +0,0 @@ -message("-- Installing: ${CMAKE_INSTALL_PREFIX}/lib") - -if(NOT EXISTS ${zig_EXE}) - message("::") - message(":: ERROR: Executable not found") - message(":: (execute_process)") - message("::") - message(":: executable: ${zig_EXE}") - message("::") - message(FATAL_ERROR) -endif() - -execute_process(COMMAND ${zig_EXE} ${ZIG_INSTALL_ARGS} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - RESULT_VARIABLE _result -) -if(_result) - message("::") - message(":: ERROR: ${_result}") - message(":: (execute_process)") - - string(REPLACE ";" " " s_INSTALL_LIBSTAGE2_ARGS "${ZIG_INSTALL_ARGS}") - message("::") - message(":: argv: ${zig_EXE} ${s_INSTALL_LIBSTAGE2_ARGS}") - - set(_args ${zig_EXE} ${ZIG_INSTALL_ARGS}) - list(LENGTH _args _len) - math(EXPR _len "${_len} - 1") - message("::") - foreach(_i RANGE 0 ${_len}) - list(GET _args ${_i} _arg) - message(":: argv[${_i}]: ${_arg}") - endforeach() - - message("::") - message(FATAL_ERROR) -endif() diff --git a/doc/docgen.zig b/doc/docgen.zig index a101b96be7..0f0e212e3c 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -285,6 +285,7 @@ const Code = struct { link_objects: []const []const u8, target_str: ?[]const u8, link_libc: bool, + backend_stage1: bool, link_mode: ?std.builtin.LinkMode, disable_cache: bool, verbose_cimport: bool, @@ -554,6 +555,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { var link_mode: ?std.builtin.LinkMode = null; var disable_cache = false; var verbose_cimport = false; + var backend_stage1 = false; const source_token = while (true) { const content_tok = try eatToken(tokenizer, Token.Id.Content); @@ -586,6 +588,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { link_libc = true; } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { link_mode = .Dynamic; + } else if (mem.eql(u8, end_tag_name, "backend_stage1")) { + backend_stage1 = true; } else if (mem.eql(u8, end_tag_name, "code_end")) { _ = try eatToken(tokenizer, Token.Id.BracketClose); break content_tok; @@ -609,6 +613,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { .link_objects = link_objects.toOwnedSlice(), .target_str = target_str, .link_libc = link_libc, + .backend_stage1 = backend_stage1, .link_mode = link_mode, .disable_cache = disable_cache, .verbose_cimport = verbose_cimport, @@ -1187,6 +1192,9 @@ fn printShell(out: anytype, shell_content: []const u8) !void { try out.writeAll(""); } +// Override this to skip to later tests +const debug_start_line = 0; + fn genHtml( allocator: Allocator, tokenizer: *Tokenizer, @@ -1266,6 +1274,13 @@ fn genHtml( continue; } + if (debug_start_line > 0) { + const loc = tokenizer.getTokenLocation(code.source_token); + if (debug_start_line > loc.line) { + continue; + } + } + const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end]; const trimmed_raw_source = mem.trim(u8, raw_source, " \n"); const tmp_source_file_name = try fs.path.join( @@ -1311,6 +1326,10 @@ fn genHtml( try build_args.append("-lc"); try shell_out.print("-lc ", .{}); } + if (code.backend_stage1) { + try build_args.append("-fstage1"); + try shell_out.print("-fstage1", .{}); + } const target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = code.target_str orelse "native", }); @@ -1443,6 +1462,10 @@ fn genHtml( try test_args.append("-lc"); try shell_out.print("-lc ", .{}); } + if (code.backend_stage1) { + try test_args.append("-fstage1"); + try shell_out.print("-fstage1", .{}); + } if (code.target_str) |triple| { try test_args.appendSlice(&[_][]const u8{ "-target", triple }); try shell_out.print("-target {s} ", .{triple}); @@ -1490,6 +1513,14 @@ fn genHtml( try shell_out.print("-O {s} ", .{@tagName(code.mode)}); }, } + if (code.link_libc) { + try test_args.append("-lc"); + try shell_out.print("-lc ", .{}); + } + if (code.backend_stage1) { + try test_args.append("-fstage1"); + try shell_out.print("-fstage1", .{}); + } const result = try ChildProcess.exec(.{ .allocator = allocator, .argv = test_args.items, diff --git a/doc/langref.html.in b/doc/langref.html.in index c61f2d0790..0d10119cb7 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -535,8 +535,8 @@ const Timestamp = struct { {#header_close#} {#header_open|Top-Level Doc Comments#}

User documentation that doesn't belong to whatever - immediately follows it, like container level documentation, goes - in top level doc comments. A top level doc comment is one that + immediately follows it, like container-level documentation, goes + in top-level doc comments. A top-level doc comment is one that begins with two slashes and an exclamation point: {#syntax#}//!{#endsyntax#}.

{#code_begin|syntax|tldoc_comments#} @@ -1188,6 +1188,7 @@ test "this will be skipped" { (The evented IO mode is enabled using the --test-evented-io command line parameter.)

{#code_begin|test|async_skip#} + {#backend_stage1#} const std = @import("std"); test "async skip test" { @@ -1520,7 +1521,8 @@ fn divide(a: i32, b: i32) i32 { Zig supports arbitrary bit-width integers, referenced by using an identifier of i or u followed by digits. For example, the identifier {#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an - integer type is {#syntax#}65535{#endsyntax#}. + integer type is {#syntax#}65535{#endsyntax#}. For signed integer types, Zig uses a + two's complement representation.

{#see_also|Wrapping Operations#} {#header_close#} @@ -2768,7 +2770,7 @@ test "comptime @intToPtr" { } } {#code_end#} - {#see_also|Optional Pointers|@intToPtr|@ptrToInt|C Pointers|Pointers to Zero Bit Types#} + {#see_also|Optional Pointers|@intToPtr|@ptrToInt|C Pointers#} {#header_open|volatile#}

Loads and stores are assumed to not have side effects. If a given load or store should have side effects, such as Memory Mapped Input/Output (MMIO), use {#syntax#}volatile{#endsyntax#}. @@ -2862,19 +2864,22 @@ var foo: u8 align(4) = 100; test "global variable alignment" { try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); try expect(@TypeOf(&foo) == *align(4) u8); - const as_pointer_to_array: *[1]u8 = &foo; - const as_slice: []u8 = as_pointer_to_array; - try expect(@TypeOf(as_slice) == []align(4) u8); + const as_pointer_to_array: *align(4) [1]u8 = &foo; + const as_slice: []align(4) u8 = as_pointer_to_array; + const as_unaligned_slice: []u8 = as_slice; + try expect(as_unaligned_slice[0] == 100); } -fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } +fn derp() align(@sizeOf(usize) * 2) i32 { + return 1234; +} fn noop1() align(1) void {} fn noop4() align(4) void {} test "function alignment" { try expect(derp() == 1234); - try expect(@TypeOf(noop1) == fn() align(1) void); - try expect(@TypeOf(noop4) == fn() align(4) void); + try expect(@TypeOf(noop1) == fn () align(1) void); + try expect(@TypeOf(noop4) == fn () align(4) void); noop1(); noop4(); } @@ -3336,6 +3341,7 @@ fn doTheTest() !void { Zig allows the address to be taken of a non-byte-aligned field:

{#code_begin|test|pointer_to_non-byte_aligned_field#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -3391,7 +3397,8 @@ fn bar(x: *const u3) u3 {

Pointers to non-ABI-aligned fields share the same address as the other fields within their host integer:

- {#code_begin|test|pointer_to_non-bit_aligned_field#} + {#code_begin|test|packed_struct_field_addrs#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -3407,7 +3414,7 @@ var bit_field = BitField{ .c = 3, }; -test "pointer to non-bit-aligned field" { +test "pointers of sub-byte-aligned fields share addresses" { try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b)); try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c)); } @@ -3438,20 +3445,22 @@ test "pointer to non-bit-aligned field" { } {#code_end#}

- Packed structs have 1-byte alignment. However if you have an overaligned pointer to a packed struct, - Zig should correctly understand the alignment of fields. However there is - a bug: + Packed structs have the same alignment as their backing integer, however, overaligned + pointers to packed structs can override this:

- {#code_begin|test_err|expected type '*u32', found '*align(1) u32'#} + {#code_begin|test|overaligned_packed_struct#} +const std = @import("std"); +const expect = std.testing.expect; + const S = packed struct { a: u32, b: u32, }; test "overaligned pointer to packed struct" { - var foo: S align(4) = undefined; + var foo: S align(4) = .{ .a = 1, .b = 2 }; const ptr: *align(4) S = &foo; const ptr_to_b: *u32 = &ptr.b; - _ = ptr_to_b; + try expect(ptr_to_b.* == 2); } {#code_end#}

When this bug is fixed, the above test in the documentation will unexpectedly pass, which will @@ -3698,7 +3707,7 @@ test "@tagName" {

By default, enums are not guaranteed to be compatible with the C ABI:

- {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'C'#} + {#code_begin|obj_err|parameter of type 'test.Foo' not allowed in function with calling convention 'C'#} const Foo = enum { a, b, c }; export fn entry(foo: Foo) void { _ = foo; } {#code_end#} @@ -4004,7 +4013,7 @@ fn makeNumber() Number { This is typically used for type safety when interacting with C code that does not expose struct details. Example:

- {#code_begin|test_err|expected type '*Derp', found '*Wat'#} + {#code_begin|test_err|expected type '*test.Derp', found '*test.Wat'#} const Derp = opaque {}; const Wat = opaque {}; @@ -4203,7 +4212,7 @@ test "switch on tagged union" { When a {#syntax#}switch{#endsyntax#} expression does not have an {#syntax#}else{#endsyntax#} clause, it must exhaustively list all the possible values. Failure to do so is a compile error:

- {#code_begin|test_err|not handled in switch#} + {#code_begin|test_err|unhandled enumeration value#} const Color = enum { auto, off, @@ -5015,8 +5024,8 @@ fn shiftLeftOne(a: u32) callconv(.Inline) u32 { // Another file can use @import and call sub2 pub fn sub2(a: i8, b: i8) i8 { return a - b; } -// Functions can be used as values and are equivalent to pointers. -const call2_op = fn (a: i8, b: i8) i8; +// Function pointers are prefixed with `*const `. +const call2_op = *const fn (a: i8, b: i8) i8; fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 { return fn_call(op1, op2); } @@ -5026,17 +5035,9 @@ test "function" { try expect(do_op(sub2, 5, 6) == -1); } {#code_end#} -

Function values are like pointers:

- {#code_begin|obj#} -const assert = @import("std").debug.assert; - -comptime { - assert(@TypeOf(foo) == fn()void); - assert(@sizeOf(fn()void) == @sizeOf(?fn()void)); -} - -fn foo() void { } - {#code_end#} +

There is a difference between a function body and a function pointer. + Function bodies are {#link|comptime#}-only types while function {#link|Pointers#} may be + runtime-known.

{#header_open|Pass-by-value Parameters#}

Primitive types such as {#link|Integers#} and {#link|Floats#} passed as parameters @@ -6123,10 +6124,11 @@ test "float widening" { two choices about the coercion.

{#code_begin|test_err#} + {#backend_stage1#} // Compile time coercion of float to int test "implicit cast to comptime_int" { var f: f32 = 54.0 / 5; @@ -6302,19 +6304,6 @@ test "coercion between unions and enums" { {#code_end#} {#see_also|union|enum#} {#header_close#} - {#header_open|Type Coercion: Zero Bit Types#} -

{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#}, - regardless of const.

-

TODO document the reasoning for this

-

TODO document whether vice versa should work and why

- {#code_begin|test|coerce_zero_bit_types#} -test "coercion of zero bit types" { - var x: void = {}; - var y: *void = x; - _ = y; -} - {#code_end#} - {#header_close#} {#header_open|Type Coercion: undefined#}

{#link|undefined#} can be cast to any type.

{#header_close#} @@ -6467,7 +6456,6 @@ test "peer type resolution: *const T and ?*T" {
  • An {#link|enum#} with only 1 tag.
  • A {#link|struct#} with all fields being zero bit types.
  • A {#link|union#} with only 1 field which is a zero bit type.
  • -
  • {#link|Pointers to Zero Bit Types#} are themselves zero bit types.
  • These types can only ever have one possible value, and thus @@ -6527,7 +6515,7 @@ test "turn HashMap into a set with void" {

    Expressions of type {#syntax#}void{#endsyntax#} are the only ones whose value can be ignored. For example:

    - {#code_begin|test_err|expression value is ignored#} + {#code_begin|test_err|ignored#} test "ignoring expression value" { foo(); } @@ -6553,37 +6541,6 @@ fn foo() i32 { } {#code_end#} {#header_close#} - - {#header_open|Pointers to Zero Bit Types#} -

    Pointers to zero bit types also have zero bits. They always compare equal to each other:

    - {#code_begin|test|pointers_to_zero_bits#} -const std = @import("std"); -const expect = std.testing.expect; - -test "pointer to empty struct" { - const Empty = struct {}; - var a = Empty{}; - var b = Empty{}; - var ptr_a = &a; - var ptr_b = &b; - comptime try expect(ptr_a == ptr_b); -} - {#code_end#} -

    The type being pointed to can only ever be one value; therefore loads and stores are - never generated. {#link|ptrToInt#} and {#link|intToPtr#} are not allowed:

    - {#code_begin|test_err#} -const Empty = struct {}; - -test "@ptrToInt for pointer to zero bit type" { - var a = Empty{}; - _ = @ptrToInt(&a); -} - -test "@intToPtr for pointer to zero bit type" { - _ = @intToPtr(*Empty, 0x1); -} - {#code_end#} - {#header_close#} {#header_close#} {#header_open|Result Location Semantics#} @@ -6666,7 +6623,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {

    For example, if we were to introduce another function to the above snippet:

    - {#code_begin|test_err|values of type 'type' must be comptime known#} + {#code_begin|test_err|unable to resolve comptime value#} fn max(comptime T: type, a: T, b: T) T { return if (a > b) a else b; } @@ -6692,7 +6649,7 @@ fn foo(condition: bool) void {

    For example:

    - {#code_begin|test_err|operator not allowed for type 'bool'#} + {#code_begin|test_err|operator > not allowed for type 'bool'#} fn max(comptime T: type, a: T, b: T) T { return if (a > b) a else b; } @@ -6837,7 +6794,7 @@ fn performFn(start_value: i32) i32 { use a {#syntax#}comptime{#endsyntax#} expression to guarantee that the expression will be evaluated at compile-time. If this cannot be accomplished, the compiler will emit an error. For example:

    - {#code_begin|test_err|unable to evaluate constant expression#} + {#code_begin|test_err|comptime call of extern function#} extern fn exit() noreturn; test "foo" { @@ -6889,7 +6846,7 @@ test "fibonacci" {

    Imagine if we had forgotten the base case of the recursive function and tried to run the tests:

    - {#code_begin|test_err|operation caused overflow#} + {#code_begin|test_err|overflow of integer type#} const expect = @import("std").testing.expect; fn fibonacci(index: u32) u32 { @@ -6913,7 +6870,8 @@ test "fibonacci" { But what would have happened if we used a signed integer?

    {#code_begin|test_err|evaluation exceeded 1000 backwards branches#} -const expect = @import("std").testing.expect; + {#backend_stage1#} +const assert = @import("std").debug.assert; fn fibonacci(index: i32) i32 { //if (index < 2) return index; @@ -6922,7 +6880,7 @@ fn fibonacci(index: i32) i32 { test "fibonacci" { comptime { - try expect(fibonacci(7) == 13); + try assert(fibonacci(7) == 13); } } {#code_end#} @@ -6935,8 +6893,8 @@ test "fibonacci" {

    What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?

    - {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#} -const expect = @import("std").testing.expect; + {#code_begin|test_err|reached unreachable#} +const assert = @import("std").debug.assert; fn fibonacci(index: i32) i32 { if (index < 2) return index; @@ -6945,16 +6903,10 @@ fn fibonacci(index: i32) i32 { test "fibonacci" { comptime { - try expect(fibonacci(7) == 99999); + try assert(fibonacci(7) == 99999); } } {#code_end#} -

    - What happened is Zig started interpreting the {#syntax#}expect{#endsyntax#} function with the - parameter {#syntax#}ok{#endsyntax#} set to {#syntax#}false{#endsyntax#}. When the interpreter hit - {#syntax#}@panic{#endsyntax#} it emitted a compile error because a panic during compile - causes a compile error if it is detected at compile-time. -

    At container level (outside of any function), all expressions are implicitly @@ -7280,6 +7232,7 @@ pub fn main() void {

    {#code_begin|exe#} {#target_linux_x86_64#} + {#backend_stage1#} pub fn main() noreturn { const msg = "hello world\n"; _ = syscall3(SYS_write, STDOUT_FILENO, @ptrToInt(msg), msg.len); @@ -7497,6 +7450,7 @@ test "global assembly" { or resumer (in the case of subsequent suspensions).

    {#code_begin|test|suspend_no_resume#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -7524,6 +7478,7 @@ fn func() void { {#link|@frame#} provides access to the async function frame pointer.

    {#code_begin|test|async_suspend_block#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -7562,6 +7517,7 @@ fn testSuspendBlock() void { never returns to its resumer and continues executing.

    {#code_begin|test|resume_from_suspend#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -7598,6 +7554,7 @@ fn testResumeFromSuspend(my_result: *i32) void { and the return value of the async function would be lost.

    {#code_begin|test|async_await#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -7642,6 +7599,7 @@ fn func() void { return value directly from the target function's frame.

    {#code_begin|test|async_await_sequence#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -7695,6 +7653,7 @@ fn seq(c: u8) void { {#syntax#}async{#endsyntax#}/{#syntax#}await{#endsyntax#} usage:

    {#code_begin|exe|async#} + {#backend_stage1#} const std = @import("std"); const Allocator = std.mem.Allocator; @@ -7773,6 +7732,7 @@ fn readFile(allocator: Allocator, filename: []const u8) ![]u8 { observe the same behavior, with one tiny difference:

    {#code_begin|exe|blocking#} + {#backend_stage1#} const std = @import("std"); const Allocator = std.mem.Allocator; @@ -7910,6 +7870,7 @@ comptime { {#syntax#}await{#endsyntax#} will copy the result from {#syntax#}result_ptr{#endsyntax#}.

    {#code_begin|test|async_struct_field_fn_pointer#} + {#backend_stage1#} const std = @import("std"); const expect = std.testing.expect; @@ -8071,8 +8032,8 @@ fn func(y: *i32) void { {#header_close#} {#header_open|@byteSwap#} -
    {#syntax#}@byteSwap(comptime T: type, operand: T) T{#endsyntax#}
    -

    {#syntax#}T{#endsyntax#} must be an integer type with bit count evenly divisible by 8.

    +
    {#syntax#}@byteSwap(operand: anytype) T{#endsyntax#}
    +

    {#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type with bit count evenly divisible by 8.

    {#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

    Swaps the byte order of the integer. This converts a big endian integer to a little endian integer, @@ -8089,8 +8050,8 @@ fn func(y: *i32) void { {#header_close#} {#header_open|@bitReverse#} -

    {#syntax#}@bitReverse(comptime T: type, integer: T) T{#endsyntax#}
    -

    {#syntax#}T{#endsyntax#} accepts any integer type.

    +
    {#syntax#}@bitReverse(integer: anytype) T{#endsyntax#}
    +

    {#syntax#}@TypeOf(anytype){#endsyntax#} accepts any integer type or integer vector type.

    Reverses the bitpattern of an integer value, including the sign bit if applicable.

    @@ -8229,8 +8190,8 @@ pub const CallOptions = struct { {#header_close#} {#header_open|@clz#} -
    {#syntax#}@clz(comptime T: type, operand: T){#endsyntax#}
    -

    {#syntax#}T{#endsyntax#} must be an integer type.

    +
    {#syntax#}@clz(operand: anytype){#endsyntax#}
    +

    {#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.

    {#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

    This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer. @@ -8375,8 +8336,8 @@ test "main" { {#header_close#} {#header_open|@ctz#} -

    {#syntax#}@ctz(comptime T: type, operand: T){#endsyntax#}
    -

    {#syntax#}T{#endsyntax#} must be an integer type.

    +
    {#syntax#}@ctz(operand: anytype){#endsyntax#}
    +

    {#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.

    {#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

    This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer. @@ -8677,6 +8638,7 @@ test "decl access by string" { allows one to, for example, heap-allocate an async function frame:

    {#code_begin|test|heap_allocated_frame#} + {#backend_stage1#} const std = @import("std"); test "heap allocated frame" { @@ -9011,8 +8973,8 @@ test "@wasmMemoryGrow" { {#header_close#} {#header_open|@popCount#} -
    {#syntax#}@popCount(comptime T: type, operand: T){#endsyntax#}
    -

    {#syntax#}T{#endsyntax#} must be an integer type.

    +
    {#syntax#}@popCount(operand: anytype){#endsyntax#}
    +

    {#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.

    {#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

    Counts the number of bits set in an integer.

    @@ -9423,12 +9385,6 @@ const std = @import("std"); const expect = std.testing.expect; test "vector @reduce" { - // This test regressed with LLVM 14: - // https://github.com/llvm/llvm-project/issues/55522 - // We'll skip this test unless the self-hosted compiler is being used. - // After LLVM 15 is released we can delete this line. - if (@import("builtin").zig_backend == .stage1) return; - const value = @Vector(4, i32){ 1, -1, 1, -1 }; const result = value > @splat(4, @as(i32, 0)); // result is { true, false, true, false }; @@ -9938,7 +9894,7 @@ pub fn main() void { {#header_close#} {#header_open|Index out of Bounds#}

    At compile-time:

    - {#code_begin|test_err|index 5 outside array of size 5#} + {#code_begin|test_err|index 5 outside array of length 5#} comptime { const array: [5]u8 = "hello".*; const garbage = array[5]; @@ -9959,9 +9915,9 @@ fn foo(x: []const u8) u8 { {#header_close#} {#header_open|Cast Negative Number to Unsigned Integer#}

    At compile-time:

    - {#code_begin|test_err|attempt to cast negative value to unsigned integer#} + {#code_begin|test_err|type 'u32' cannot represent integer value '-1'#} comptime { - const value: i32 = -1; + var value: i32 = -1; const unsigned = @intCast(u32, value); _ = unsigned; } @@ -9982,7 +9938,7 @@ pub fn main() void { {#header_close#} {#header_open|Cast Truncates Data#}

    At compile-time:

    - {#code_begin|test_err|cast from 'u16' to 'u8' truncates bits#} + {#code_begin|test_err|type 'u8' cannot represent integer value '300'#} comptime { const spartan_count: u16 = 300; const byte = @intCast(u8, spartan_count); @@ -10017,7 +9973,7 @@ pub fn main() void {
  • {#link|@divExact#} (division)
  • Example with addition at compile-time:

    - {#code_begin|test_err|operation caused overflow#} + {#code_begin|test_err|overflow of integer type 'u8' with value '256'#} comptime { var byte: u8 = 255; byte += 1; @@ -10118,6 +10074,7 @@ test "wraparound addition and subtraction" { {#header_open|Exact Left Shift Overflow#}

    At compile-time:

    {#code_begin|test_err|operation caused overflow#} + {#backend_stage1#} comptime { const x = @shlExact(@as(u8, 0b01010101), 2); _ = x; @@ -10137,6 +10094,7 @@ pub fn main() void { {#header_open|Exact Right Shift Overflow#}

    At compile-time:

    {#code_begin|test_err|exact shift shifted out 1 bits#} + {#backend_stage1#} comptime { const x = @shrExact(@as(u8, 0b10101010), 2); _ = x; @@ -10200,6 +10158,7 @@ pub fn main() void { {#header_open|Exact Division Remainder#}

    At compile-time:

    {#code_begin|test_err|exact division had a remainder#} + {#backend_stage1#} comptime { const a: u32 = 10; const b: u32 = 3; @@ -10302,7 +10261,7 @@ fn getNumberOrFail() !i32 { {#header_close#} {#header_open|Invalid Error Code#}

    At compile-time:

    - {#code_begin|test_err|integer value 11 represents no error#} + {#code_begin|test_err|integer value '11' represents no error#} comptime { const err = error.AnError; const number = @errorToInt(err) + 10; @@ -10324,7 +10283,7 @@ pub fn main() void { {#header_close#} {#header_open|Invalid Enum Cast#}

    At compile-time:

    - {#code_begin|test_err|has no tag matching integer value 3#} + {#code_begin|test_err|enum 'test.Foo' has no tag with value '3'#} const Foo = enum { a, b, @@ -10356,7 +10315,7 @@ pub fn main() void { {#header_open|Invalid Error Set Cast#}

    At compile-time:

    - {#code_begin|test_err|error.B not a member of error set 'Set2'#} + {#code_begin|test_err|'error.B' not a member of error set 'error{A,C}'#} const Set1 = error{ A, B, @@ -10417,7 +10376,7 @@ fn foo(bytes: []u8) u32 { {#header_close#} {#header_open|Wrong Union Field Access#}

    At compile-time:

    - {#code_begin|test_err|accessing union field 'float' while field 'int' is set#} + {#code_begin|test_err|access of union field 'float' while field 'int' is active#} comptime { var f = Foo{ .int = 42 }; f.float = 12.34; @@ -10509,6 +10468,7 @@ fn bar(f: *Foo) void {

    At compile-time:

    {#code_begin|test_err|null pointer casted to type#} + {#backend_stage1#} comptime { const opt_ptr: ?*i32 = null; const ptr = @ptrCast(*i32, opt_ptr); @@ -10551,7 +10511,8 @@ const expect = std.testing.expect; test "using an allocator" { var buffer: [100]u8 = undefined; - const allocator = std.heap.FixedBufferAllocator.init(&buffer).allocator(); + var fba = std.heap.FixedBufferAllocator.init(&buffer); + const allocator = fba.allocator(); const result = try concat(allocator, "foo", "bar"); try expect(std.mem.eql(u8, "foobar", result)); } @@ -10647,7 +10608,7 @@ pub fn main() !void {

    String literals such as {#syntax#}"foo"{#endsyntax#} are in the global constant data section. This is why it is an error to pass a string literal to a mutable slice, like this:

    - {#code_begin|test_err|cannot cast pointer to array literal to slice type '[]u8'#} + {#code_begin|test_err|expected type '[]u8', found '*const [5:0]u8'#} fn foo(s: []u8) void { _ = s; } @@ -11832,8 +11793,8 @@ fn readU32Be() u32 {}
    {#syntax#}anytype{#endsyntax#}
    - Function parameters and struct fields can be declared with {#syntax#}anytype{#endsyntax#} in place of the type. - The type will be inferred where the function is called or the struct is instantiated. + Function parameters can be declared with {#syntax#}anytype{#endsyntax#} in place of the type. + The type will be inferred where the function is called. diff --git a/lib/compiler_rt/addf3.zig b/lib/compiler_rt/addf3.zig index 7f2e368121..8edfef9838 100644 --- a/lib/compiler_rt/addf3.zig +++ b/lib/compiler_rt/addf3.zig @@ -9,7 +9,7 @@ const normalize = common.normalize; pub inline fn addf3(comptime T: type, a: T, b: T) T { const bits = @typeInfo(T).Float.bits; const Z = std.meta.Int(.unsigned, bits); - const S = std.meta.Int(.unsigned, bits - @clz(Z, @as(Z, bits) - 1)); + const S = std.meta.Int(.unsigned, bits - @clz(@as(Z, bits) - 1)); const typeWidth = bits; const significandBits = math.floatMantissaBits(T); @@ -118,7 +118,7 @@ pub inline fn addf3(comptime T: type, a: T, b: T) T { // If partial cancellation occured, we need to left-shift the result // and adjust the exponent: if (aSignificand < integerBit << 3) { - const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.Int(.unsigned, bits), integerBit << 3)); + const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(integerBit << 3)); aSignificand <<= @intCast(S, shift); aExponent -= shift; } diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index ab3d169d1b..0147bd423b 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -199,7 +199,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T); - const shift = @clz(Z, significand.*) - @clz(Z, integerBit); + const shift = @clz(significand.*) - @clz(integerBit); significand.* <<= @intCast(std.math.Log2Int(Z), shift); return @as(i32, 1) - shift; } diff --git a/lib/compiler_rt/divxf3.zig b/lib/compiler_rt/divxf3.zig index b8d27a6da0..2282c21299 100644 --- a/lib/compiler_rt/divxf3.zig +++ b/lib/compiler_rt/divxf3.zig @@ -206,5 +206,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { } test { + if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/12603 + _ = @import("divxf3_test.zig"); } diff --git a/lib/compiler_rt/extendf.zig b/lib/compiler_rt/extendf.zig index 8eb23c1d82..2bb40fc2bd 100644 --- a/lib/compiler_rt/extendf.zig +++ b/lib/compiler_rt/extendf.zig @@ -56,8 +56,8 @@ pub inline fn extendf( // a is denormal. // renormalize the significand and clear the leading bit, then insert // the correct adjusted exponent in the destination type. - const scale: u32 = @clz(src_rep_t, aAbs) - - @clz(src_rep_t, @as(src_rep_t, srcMinNormal)); + const scale: u32 = @clz(aAbs) - + @clz(@as(src_rep_t, srcMinNormal)); absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); absResult ^= dstMinNormal; const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; @@ -119,8 +119,8 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI // a is denormal. // renormalize the significand and clear the leading bit, then insert // the correct adjusted exponent in the destination type. - const scale: u16 = @clz(src_rep_t, a_abs) - - @clz(src_rep_t, @as(src_rep_t, src_min_normal)); + const scale: u16 = @clz(a_abs) - + @clz(@as(src_rep_t, src_min_normal)); dst.fraction = @as(u64, a_abs) << @intCast(u6, dst_sig_bits - src_sig_bits + scale); dst.fraction |= dst_int_bit; // bit 64 is always set for normal numbers diff --git a/lib/compiler_rt/extendxftf2.zig b/lib/compiler_rt/extendxftf2.zig index bb5d6a377b..077d510646 100644 --- a/lib/compiler_rt/extendxftf2.zig +++ b/lib/compiler_rt/extendxftf2.zig @@ -38,7 +38,7 @@ fn __extendxftf2(a: f80) callconv(.C) f128 { // a is denormal // renormalize the significand and clear the leading bit and integer part, // then insert the correct adjusted exponent in the destination type. - const scale: u32 = @clz(u64, a_rep.fraction); + const scale: u32 = @clz(a_rep.fraction); abs_result = @as(u128, a_rep.fraction) << @intCast(u7, dst_sig_bits - src_sig_bits + scale + 1); abs_result ^= dst_min_normal; abs_result |= @as(u128, scale + 1) << dst_sig_bits; diff --git a/lib/compiler_rt/int.zig b/lib/compiler_rt/int.zig index 53205e2ed9..43bc160cda 100644 --- a/lib/compiler_rt/int.zig +++ b/lib/compiler_rt/int.zig @@ -243,7 +243,7 @@ inline fn div_u32(n: u32, d: u32) u32 { // special cases if (d == 0) return 0; // ?! if (n == 0) return 0; - var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n))); + var sr = @bitCast(c_uint, @as(c_int, @clz(d)) - @as(c_int, @clz(n))); // 0 <= sr <= n_uword_bits - 1 or sr large if (sr > n_uword_bits - 1) { // d > r diff --git a/lib/compiler_rt/int_to_float.zig b/lib/compiler_rt/int_to_float.zig index 233dfec815..2eb7b5ade8 100644 --- a/lib/compiler_rt/int_to_float.zig +++ b/lib/compiler_rt/int_to_float.zig @@ -23,7 +23,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T { var result: uT = sign_bit; // Compute significand - var exp = int_bits - @clz(Z, abs_val) - 1; + var exp = int_bits - @clz(abs_val) - 1; if (int_bits <= fractional_bits or exp <= fractional_bits) { const shift_amt = fractional_bits - @intCast(math.Log2Int(uT), exp); @@ -32,7 +32,7 @@ pub fn intToFloat(comptime T: type, x: anytype) T { result ^= implicit_bit; // Remove implicit integer bit } else { var shift_amt = @intCast(math.Log2Int(Z), exp - fractional_bits); - const exact_tie: bool = @ctz(Z, abs_val) == shift_amt - 1; + const exact_tie: bool = @ctz(abs_val) == shift_amt - 1; // Shift down result and remove implicit integer bit result = @intCast(uT, (abs_val >> (shift_amt - 1))) ^ (implicit_bit << 1); diff --git a/lib/compiler_rt/mulf3.zig b/lib/compiler_rt/mulf3.zig index f6949ee3ce..770721cb80 100644 --- a/lib/compiler_rt/mulf3.zig +++ b/lib/compiler_rt/mulf3.zig @@ -186,7 +186,7 @@ fn normalize(comptime T: type, significand: *PowerOfTwoSignificandZ(T)) i32 { const Z = PowerOfTwoSignificandZ(T); const integerBit = @as(Z, 1) << math.floatFractionalBits(T); - const shift = @clz(Z, significand.*) - @clz(Z, integerBit); + const shift = @clz(significand.*) - @clz(integerBit); significand.* <<= @intCast(math.Log2Int(Z), shift); return @as(i32, 1) - shift; } diff --git a/lib/compiler_rt/udivmod.zig b/lib/compiler_rt/udivmod.zig index d941c242d2..065ea44896 100644 --- a/lib/compiler_rt/udivmod.zig +++ b/lib/compiler_rt/udivmod.zig @@ -75,12 +75,12 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: r[high] = n[high] & (d[high] - 1); rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421 } - return n[high] >> @intCast(Log2SingleInt, @ctz(SingleInt, d[high])); + return n[high] >> @intCast(Log2SingleInt, @ctz(d[high])); } // K K // --- // K 0 - sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); + sr = @bitCast(c_uint, @as(c_int, @clz(d[high])) - @as(c_int, @clz(n[high]))); // 0 <= sr <= single_int_bits - 2 or sr large if (sr > single_int_bits - 2) { if (maybe_rem) |rem| { @@ -110,7 +110,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: if (d[low] == 1) { return a; } - sr = @ctz(SingleInt, d[low]); + sr = @ctz(d[low]); q[high] = n[high] >> @intCast(Log2SingleInt, sr); q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr)); return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421 @@ -118,7 +118,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: // K X // --- // 0 K - sr = 1 + single_int_bits + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high])); + sr = 1 + single_int_bits + @as(c_uint, @clz(d[low])) - @as(c_uint, @clz(n[high])); // 2 <= sr <= double_int_bits - 1 // q.all = a << (double_int_bits - sr); // r.all = a >> sr; @@ -144,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: // K X // --- // K K - sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); + sr = @bitCast(c_uint, @as(c_int, @clz(d[high])) - @as(c_int, @clz(n[high]))); // 0 <= sr <= single_int_bits - 1 or sr large if (sr > single_int_bits - 1) { if (maybe_rem) |rem| { diff --git a/lib/docs/index.html b/lib/docs/index.html index dbcb54288a..ddc0ecbfb2 100644 --- a/lib/docs/index.html +++ b/lib/docs/index.html @@ -25,9 +25,10 @@ --search-bg-color-focus: #ffffff; --search-sh-color: rgba(0, 0, 0, 0.18); --help-sh-color: rgba(0, 0, 0, 0.75); + --help-bg-color: #aaa; } - html, body { margin: 0; padding:0; height: 100%; } + html, body { margin: 0; padding: 0; height: 100%; } a { text-decoration: none; @@ -168,8 +169,8 @@ width: 100%; margin-bottom: 0.8rem; padding: 0.5rem; - font-size: 1rem; font-family: var(--ui); + font-size: 1rem; color: var(--tx-color); background-color: var(--search-bg-color); border-top: 0; @@ -190,11 +191,11 @@ box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color); } - .docs .search::placeholder { - font-size: 1rem; - font-family: var(--ui); - color: var(--tx-color); - opacity: 0.5; + #searchPlaceholder { + position: absolute; + pointer-events: none; + top: 5px; + left: 5px; } .docs a { @@ -207,9 +208,9 @@ .docs pre { font-family: var(--mono); - font-size:1em; - background-color:#F5F5F5; - padding:1em; + font-size: 1em; + background-color: #F5F5F5; + padding: 1em; overflow-x: auto; } @@ -225,7 +226,7 @@ border-bottom: 0.0625rem dashed; } - .docs h2 { + .docs h2 { font-size: 1.3em; margin: 0.5em 0; padding: 0; @@ -289,12 +290,12 @@ } .fieldDocs { - border: 1px solid #2A2A2A; + border: 1px solid #F5F5F5; border-top: 0px; padding: 1px 1em; } - /* help dialog */ + /* help modal */ .help-modal { display: flex; width: 100%; @@ -308,13 +309,13 @@ backdrop-filter: blur(0.3em); } - .help-modal > .dialog { + .help-modal > .modal { max-width: 97vw; max-height: 97vh; overflow: auto; font-size: 1rem; color: #fff; - background-color: #333; + background-color: var(--help-bg-color); border: 0.125rem solid #000; box-shadow: 0 0.5rem 2.5rem 0.3rem var(--help-sh-color); } @@ -335,11 +336,11 @@ margin-right: 0.5em; } - .help-modal kbd { + kbd { display: inline-block; padding: 0.3em 0.2em; - font-size: 1.2em; - font-size: var(--mono); + font-family: var(--mono); + font-size: 1em; line-height: 0.8em; vertical-align: middle; color: #000; @@ -348,16 +349,20 @@ border-bottom-color: #c6cbd1; border: solid 0.0625em; border-radius: 0.1875em; - box-shadow: inset 0 -0.0625em 0 #c6cbd1; + box-shadow: inset 0 -0.2em 0 #c6cbd1; cursor: default; } + + #listFns > div { + padding-bottom: 10px; + } - #listFns dt { - font-family: var(--mono); - } - .argBreaker { - display: none; - } + #listFns dt { + font-family: var(--mono); + } + .argBreaker { + display: none; + } /* tokens */ .tok-kw { @@ -391,7 +396,6 @@ /* dark mode */ @media (prefers-color-scheme: dark) { - :root { --tx-color: #bbb; --bg-color: #111; @@ -408,11 +412,15 @@ --search-bg-color-focus: #000; --search-sh-color: rgba(255, 255, 255, 0.28); --help-sh-color: rgba(142, 142, 142, 0.5); + --help-bg-color: #333; } .docs pre { background-color:#2A2A2A; } + .fieldDocs { + border-color:#2A2A2A; + } #listNav { background-color: #333; } @@ -457,7 +465,6 @@ .tok-type { color: #68f; } - } @media only screen and (max-width: 750px) { @@ -544,7 +551,7 @@ @@ -555,43 +562,43 @@ + -
    - - -
    +
    + + +
    -
    +
    - +
    + S to search, ? for more options + +

    Loading...

    -
    +
    -