Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move many settings from being per-Compilation to being per-Module #18160

Merged
merged 133 commits into from Jan 2, 2024

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Nov 29, 2023

Part 1: Per-Module Settings in the Build System

This moves many settings from std.Build.Step.Compile and into std.Build.Module, and then makes them transitive.

In other words, it adds support for exposing Zig modules in packages, which are configured in various ways, such as depending on other link objects, include paths, or even a different optimization mode.

Now, transitive dependencies will be included in the compilation, so you can, for example, make a Zig module depend on some C source code, and expose that Zig module in a package.

closes #14719

Part 2: Per-Module Settings in the Compiler

This branch also migrates many settings from being per-Compilation to being per-Module in the compiler itself. This required extensive changes to the interaction between the CLI as well as Compilation.

Before, the compiler frontend autogenerated only one @import("builtin") module for the entire compilation, however, this branch makes it honor the differences in modules, so that modules can be compiled with different optimization modes, code model, valgrind integration, or even target CPU feature set.

Part 2A: Yak Shave: Linker Options

This ballooned into an enormous changeset because I decided that the link.Options struct should not be stored in link.File, and I wanted to make those fields be resolved and set directly in link.File (the base struct) or the ObjectFormat-specific structs (such as MachO, Elf, etc.).

This change has been needed for a long time, so this pays off some tech debt. I hope it does not cause too many conflicts.

Merge Checklist

  • Rename std.zig.CrossTarget to std.zig.Target.Query
  • Make the dynamic linker part of std.Target
  • Introduce std.Build.ResolvedTarget to avoid redundantly resolving target queries
  • test on a project with a big dependency tree (groovebasin)
  • fix regression: race conditions on linux/elf
  • fix regression: test-stack-traces on macOS
  • fix regression: unable to bootstrap on windows due to error.AccessDenied when writing builtin.zig
  • Make sure there's a check and error message for other modules depending on the main module, since that's a scenario the frontend can't currently encode
  • Give each module its own @import("builtin") that can be different from the root module one.
  • Make each function respect the target CPU feature set, even in the LLVM backend.
  • Add a test for mixing modules with different optimization modes into the same compilation. replace @setRuntimeSafety with @optimizeFor #978
  • Make different optimization modes per function supported in the LLVM backend replace @setRuntimeSafety with @optimizeFor #978
  • write the upgrade guide
  • make it handle -fno-emit-bin -femit-llvm-bc
  • make compilation.create() take an arena
  • add CLI err when requesting hex or binary object format
  • make it so that --shared-memory automatically adds the needed CPU features if not explicitly specified
  • update flush and flushModule and other functions to not take Compilation parameter
  • put all the modules in a flat array to make them easier to iterate unimportant refactor, do it when there are fewer open PRs
  • flatten link.File into LinkFile.zig unimportant refactor, do it when there are fewer open PRs
  • rename bin_file to link_file unimportant refactor, do it when there are fewer open PRs
  • introduce global -I and global -L args so that they don't get duplicated so many times on the CLI
  • pass the update() arena to linker flush()
  • regression: aarch64-windows coff dwarf standalone test disabled test: coff_dwarf standalone test #18427

Upgrade Guide

  • Deprecated API removed: use the new API names

modules can now be configured in more useful ways

Now, every Compile step has a root_module field which can be accessed directly.

  • Many settings can be configured on a per-module basis now, such as optimize_mode, target (CPU features), single_threaded, and many more.
  • Link objects are now attached directly to modules, such as C source files, static libraries, system libraries
  • C compiler flags, lib paths, include directories, etc. can now be configured per-module

It's now possible to make a module depend on the main module of a compilation.

Many of these fields were moved from std.Build.Step.Compile to std.Build.Module. Instead of setting the field of Compile, set it in the options passed to addExecutable, addStaticLibrary, etc., or, change it to set the field of a Compile step's root_module.

main_mod_path is removed

There is no replacement. The root source file of a zig module determines the module's root directory - it is the root source file's direct parent. This was done to simplify Zig modules conceptually.

If your code depends on setting main_mod_path, here are some ways to transition to the new API:

  1. Move your module's root source file so that its parent directory is inside the path you were setting as the main_mod_path.
  2. Instead of reaching outside of the module's directory tree, make the file(s) that you want to access into a separate module that can be accessed with @import.

Removal of vcpkg integration

Instead of vcpkg, users are encouraged to use the Zig package manager to fulfill dependencies on Windows.

std.zig.CrossTarget renamed to std.Target.Query

Now there is a clear delineation using the concept of a target query and a fully resolved target. Here is some example code:

pub fn build(b: *std.Build) void {
    const target_query: std.Target.Query = .{};
    const resolved_target: std.Build.ResolvedTarget = b.resolveTargetQuery(target_query);
    const target: std.Target = resolved_target.result;

    const lib = b.addStaticLibrary(.{
        .name = "ffmpeg",
        .target = resolved_target,
    });

I left the types in there for clarity, but in practice it will probably look more like this:

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const t = target.result;

    const lib = b.addStaticLibrary(.{
        .name = "ffmpeg",
        .target = target,
    });

    const avconfig_h = b.addConfigHeader(.{
        .style = .blank,
        .include_path = "libavutil/avconfig.h",
    }, .{
        .AV_HAVE_BIGENDIAN = @intFromBool(t.cpu.arch.endian() == .big),
        .AV_HAVE_FAST_UNALIGNED = @intFromBool(fastUnalignedLoads(t)),
    });
    lib.addConfigHeader(avconfig_h);

Error Return Tracing in ReleaseSafe Optimization Mode

Before, error return tracing defaulted to on in ReleaseSafe mode. Now it defaults to off since it is a debugging feature rather than a safety feature. To obtain the previous behavior, one can pass -ferror-tracing (CLI) or pass .error_tracing = true, to addExecutable and similar functions.

Like many other settings, this can now be configured on a per-Module basis.

CLI

Old syntax: --mod a:a,b=c:d --deps a,b=c
New syntax: --dep a --dep b=c --mod a d

Note that --mod takes two parameters. It is the only CLI option that takes two parameters.

All per-module settings on the CLI apply to the next --mod argument. Global settings are unaffected.

Any -I args appearing after the final --mod argument affect all modules.

All C source files are now attached to a module, as demonstrated by this error message:

$ zig build-exe --mod a b hello.c 
error: C source file 'hello.c' has no parent module

This is fixed by attaching the C source file to the module by putting it first:

zig build-exe hello.c --mod a b

If there is no --mod argument then zig infers one at the end, so this still works fine:

zig build-exe hello.c

--prominent-compile-errors

This was removed in 986a30e but it is now added again.

This reintroduced flag makes zig build behave the same as before this branch. Without this flag, the default behavior is now changed to display compilation errors inline with the rest of error messages and the build tree context.

This behavior is essential for making sense of error logs from projects that have two or more steps emitting compilation errors which is why it is now the default.

As an example, before, you could see something like this:

test-c-abi
└─ run test-c-abi-powerpc64le-linux.4.19...6.5.7-musl-ppc64le-ReleaseFast
   └─ zig test test-c-abi-powerpc64le-linux.4.19...6.5.7-musl-ppc64le-ReleaseFast ReleaseFast powerpc64le-linux-musl 1 errors
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig test -cflags -std=c99 -- /home/andy/dev/zig/test/c_abi/cfuncs.c -OReleaseFast -target powerpc64le-linux-musl -mcpu baseline --mod root /home/andy/dev/zig/test/c_abi/main.zig -lc --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test-c-abi-powerpc64le-linux.4.19...6.5.7-musl-ppc64le-ReleaseFast -L /home/andy/local/llvm17-assert/lib -I /home/andy/local/llvm17-assert/include -L /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/lib -I /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/include -L /nix/store/69jpyha5zbll6ppqzhbihhp51lac1hrp-zlib-1.2.13/lib -L /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/lib -I /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/include -L /nix/store/sp86px3bwaix43ywk194dmkdnf9dvxda-rr-5.6.0/lib -L /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/lib -I /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/include -L /nix/store/kbyd2711qxdy9r1ghfdk2piyrap8fk7i-bloaty-1.1/lib -L /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/lib -I /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/include -L /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/lib -I /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/include -L /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/lib -I /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/include -L /nix/store/i6y3vfw18aygsivl29fk7y0pb153j571-ncurses-6.4/lib -L /nix/store/lcf187gr6qq280qn14fdr8k5fjwp6n78-libedit-20221030-3.1/lib -L /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/lib -I /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/include -fno-lto --listen=- 
test-c-abi
└─ run test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-ReleaseFast
   └─ zig test test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-ReleaseFast ReleaseFast mips-linux-musl 1 errors
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig test -cflags -std=c99 -- /home/andy/dev/zig/test/c_abi/cfuncs.c -OReleaseFast -target mips-linux-musl -mcpu baseline --mod root /home/andy/dev/zig/test/c_abi/main.zig -lc --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-ReleaseFast -L /home/andy/local/llvm17-assert/lib -I /home/andy/local/llvm17-assert/include -L /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/lib -I /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/include -L /nix/store/69jpyha5zbll6ppqzhbihhp51lac1hrp-zlib-1.2.13/lib -L /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/lib -I /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/include -L /nix/store/sp86px3bwaix43ywk194dmkdnf9dvxda-rr-5.6.0/lib -L /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/lib -I /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/include -L /nix/store/kbyd2711qxdy9r1ghfdk2piyrap8fk7i-bloaty-1.1/lib -L /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/lib -I /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/include -L /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/lib -I /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/include -L /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/lib -I /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/include -L /nix/store/i6y3vfw18aygsivl29fk7y0pb153j571-ncurses-6.4/lib -L /nix/store/lcf187gr6qq280qn14fdr8k5fjwp6n78-libedit-20221030-3.1/lib -L /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/lib -I /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/include -fno-lto --listen=- 
test-c-abi
└─ run test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-ReleaseFast
   └─ zig test test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-ReleaseFast ReleaseFast powerpc-linux-musl 1 errors
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig test -cflags -std=c99 -- /home/andy/dev/zig/test/c_abi/cfuncs.c -OReleaseFast -target powerpc-linux-musl -mcpu baseline --mod root /home/andy/dev/zig/test/c_abi/main.zig -lc --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-ReleaseFast -L /home/andy/local/llvm17-assert/lib -I /home/andy/local/llvm17-assert/include -L /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/lib -I /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/include -L /nix/store/69jpyha5zbll6ppqzhbihhp51lac1hrp-zlib-1.2.13/lib -L /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/lib -I /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/include -L /nix/store/sp86px3bwaix43ywk194dmkdnf9dvxda-rr-5.6.0/lib -L /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/lib -I /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/include -L /nix/store/kbyd2711qxdy9r1ghfdk2piyrap8fk7i-bloaty-1.1/lib -L /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/lib -I /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/include -L /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/lib -I /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/include -L /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/lib -I /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/include -L /nix/store/i6y3vfw18aygsivl29fk7y0pb153j571-ncurses-6.4/lib -L /nix/store/lcf187gr6qq280qn14fdr8k5fjwp6n78-libedit-20221030-3.1/lib -L /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/lib -I /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/include -fno-lto --listen=- 
Build Summary: 54/91 steps succeeded; 18 failed (disable with --summary none)
test-c-abi transitive failure
├─ run test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-Debug transitive failure
│  └─ zig test test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-Debug Debug mips-linux-musl 1 errors
├─ run test-c-abi-wasm32-wasi-musl-generic-Debug transitive failure
│  └─ zig test test-c-abi-wasm32-wasi-musl-generic-Debug Debug wasm32-wasi-musl failure
├─ run test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-Debug transitive failure
│  └─ zig test test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-Debug Debug powerpc-linux-musl 1 errors
...
error: unable to build musl CRT file: ZigLacksTargetSupport
error: unable to build musl CRT file: ZigLacksTargetSupport
error: lld-link: /home/andy/.cache/zig/o/d79adfe179fb1ce97d10290c4e5d9f47/crt2.obj: machine type x86 conflicts with x64
error: lld-link: mingw32.lib(crt0_c.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(gccmain.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(natstart.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(wildcard.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(dllargv.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(_newmode.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlssup.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(xncommod.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(cinitexe.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(merr.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(usermatherr.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(CRT_fp10.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(mingw_helpers.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pseudo-reloc.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(xtxtmode.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(crt_handler.obj): machine type x86 conflicts with x64
error: lld-link: mingwex.lib(mingw_matherr.obj): machine type x86 conflicts with x64
error: lld-link: msvcrt-os.lib(invalid_parameter_handler.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlsthrd.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlsmcrt.obj): machine type x86 conflicts with x64
error: lld-link: msvcrt-os.lib(acrt_iob_func.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pesect.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pseudo-reloc-list.obj): machine type x86 conflicts with x64
error: unable to build musl CRT file: ZigLacksTargetSupport
error: unable to build musl CRT file: ZigLacksTargetSupport
error: lld-link: <root>: undefined symbol: _wWinMainCRTStartup
error: unable to build musl CRT file: ZigLacksTargetSupport
error: lld-link: /home/andy/.cache/zig/o/d79adfe179fb1ce97d10290c4e5d9f47/crt2.obj: machine type x86 conflicts with x64
error: lld-link: mingw32.lib(crt0_c.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(gccmain.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(natstart.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(wildcard.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(dllargv.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(_newmode.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlssup.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(xncommod.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(cinitexe.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(merr.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(usermatherr.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(CRT_fp10.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(mingw_helpers.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pseudo-reloc.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(xtxtmode.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(crt_handler.obj): machine type x86 conflicts with x64
error: lld-link: mingwex.lib(mingw_matherr.obj): machine type x86 conflicts with x64
error: lld-link: msvcrt-os.lib(invalid_parameter_handler.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlsthrd.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlsmcrt.obj): machine type x86 conflicts with x64
error: lld-link: msvcrt-os.lib(acrt_iob_func.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pesect.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pseudo-reloc-list.obj): machine type x86 conflicts with x64
error: unable to build musl CRT file: ZigLacksTargetSupport
error: unable to build musl CRT file: ZigLacksTargetSupport
error: lld-link: <root>: undefined symbol: _wWinMainCRTStartup
error: lld-link: /home/andy/.cache/zig/o/d79adfe179fb1ce97d10290c4e5d9f47/crt2.obj: machine type x86 conflicts with x64
error: lld-link: mingw32.lib(crt0_c.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(gccmain.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(natstart.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(wildcard.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(dllargv.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(_newmode.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlssup.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(xncommod.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(cinitexe.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(merr.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(usermatherr.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(CRT_fp10.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(mingw_helpers.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pseudo-reloc.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(xtxtmode.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(crt_handler.obj): machine type x86 conflicts with x64
error: lld-link: mingwex.lib(mingw_matherr.obj): machine type x86 conflicts with x64
error: lld-link: msvcrt-os.lib(invalid_parameter_handler.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlsthrd.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(tlsmcrt.obj): machine type x86 conflicts with x64
error: lld-link: msvcrt-os.lib(acrt_iob_func.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pesect.obj): machine type x86 conflicts with x64
error: lld-link: mingw32.lib(pseudo-reloc-list.obj): machine type x86 conflicts with x64
error: lld-link: <root>: undefined symbol: _wWinMainCRTStartup
error: unable to build musl CRT file: ZigLacksTargetSupport
error: unable to build musl CRT file: ZigLacksTargetSupport

which makes no goddamn sense at all. Now, it looks like this by default:

test-c-abi
└─ run test-c-abi-powerpc64le-linux.4.19...6.5.7-musl-ppc64le-ReleaseFast
   └─ zig test test-c-abi-powerpc64le-linux.4.19...6.5.7-musl-ppc64le-ReleaseFast ReleaseFast powerpc64le-linux-musl 1 errors
error: unable to build musl CRT file: ZigLacksTargetSupport
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig test -cflags -std=c99 -- /home/andy/dev/zig/test/c_abi/cfuncs.c -OReleaseFast -target powerpc64le-linux-musl -mcpu baseline --mod root /home/andy/dev/zig/test/c_abi/main.zig -lc --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test-c-abi-powerpc64le-linux.4.19...6.5.7-musl-ppc64le-ReleaseFast -L /home/andy/local/llvm17-assert/lib -I /home/andy/local/llvm17-assert/include -L /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/lib -I /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/include -L /nix/store/69jpyha5zbll6ppqzhbihhp51lac1hrp-zlib-1.2.13/lib -L /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/lib -I /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/include -L /nix/store/sp86px3bwaix43ywk194dmkdnf9dvxda-rr-5.6.0/lib -L /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/lib -I /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/include -L /nix/store/kbyd2711qxdy9r1ghfdk2piyrap8fk7i-bloaty-1.1/lib -L /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/lib -I /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/include -L /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/lib -I /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/include -L /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/lib -I /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/include -L /nix/store/i6y3vfw18aygsivl29fk7y0pb153j571-ncurses-6.4/lib -L /nix/store/lcf187gr6qq280qn14fdr8k5fjwp6n78-libedit-20221030-3.1/lib -L /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/lib -I /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/include -fno-lto --listen=- 
test-c-abi
└─ run test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-ReleaseFast
   └─ zig test test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-ReleaseFast ReleaseFast powerpc-linux-musl 1 errors
error: unable to build musl CRT file: ZigLacksTargetSupport
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig test -cflags -std=c99 -- /home/andy/dev/zig/test/c_abi/cfuncs.c -OReleaseFast -target powerpc-linux-musl -mcpu baseline --mod root /home/andy/dev/zig/test/c_abi/main.zig -lc --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-ReleaseFast -L /home/andy/local/llvm17-assert/lib -I /home/andy/local/llvm17-assert/include -L /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/lib -I /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/include -L /nix/store/69jpyha5zbll6ppqzhbihhp51lac1hrp-zlib-1.2.13/lib -L /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/lib -I /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/include -L /nix/store/sp86px3bwaix43ywk194dmkdnf9dvxda-rr-5.6.0/lib -L /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/lib -I /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/include -L /nix/store/kbyd2711qxdy9r1ghfdk2piyrap8fk7i-bloaty-1.1/lib -L /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/lib -I /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/include -L /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/lib -I /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/include -L /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/lib -I /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/include -L /nix/store/i6y3vfw18aygsivl29fk7y0pb153j571-ncurses-6.4/lib -L /nix/store/lcf187gr6qq280qn14fdr8k5fjwp6n78-libedit-20221030-3.1/lib -L /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/lib -I /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/include -fno-lto --listen=- 
test-c-abi
└─ run test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-ReleaseFast
   └─ zig test test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-ReleaseFast ReleaseFast mips-linux-musl 1 errors
error: unable to build musl CRT file: ZigLacksTargetSupport
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig test -cflags -std=c99 -- /home/andy/dev/zig/test/c_abi/cfuncs.c -OReleaseFast -target mips-linux-musl -mcpu baseline --mod root /home/andy/dev/zig/test/c_abi/main.zig -lc --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-ReleaseFast -L /home/andy/local/llvm17-assert/lib -I /home/andy/local/llvm17-assert/include -L /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/lib -I /nix/store/03grn1z9pl9m8702wkshj5pwnvknazim-zlib-1.2.13-dev/include -L /nix/store/69jpyha5zbll6ppqzhbihhp51lac1hrp-zlib-1.2.13/lib -L /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/lib -I /nix/store/fgkwipdckl30pdd80xr4l6hfk5h5qcqf-perf-linux-6.1.53/include -L /nix/store/sp86px3bwaix43ywk194dmkdnf9dvxda-rr-5.6.0/lib -L /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/lib -I /nix/store/n5qp1xk9gglc4k07y7sn1wqwk9cbzdbl-wabt-1.0.33/include -L /nix/store/kbyd2711qxdy9r1ghfdk2piyrap8fk7i-bloaty-1.1/lib -L /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/lib -I /nix/store/qws26d0bpdw5h7cf4bg29lxxrwhw7cz1-binaryen-112/include -L /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/lib -I /nix/store/3wdpi7s41ra9cbsc99myvi10cia74dpy-libedit-20221030-3.1-dev/include -L /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/lib -I /nix/store/3j8n1hl92r8bhwzqxgvx3nzpb6h59qm2-ncurses-6.4-dev/include -L /nix/store/i6y3vfw18aygsivl29fk7y0pb153j571-ncurses-6.4/lib -L /nix/store/lcf187gr6qq280qn14fdr8k5fjwp6n78-libedit-20221030-3.1/lib -L /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/lib -I /nix/store/b0n002j20xja9627550j61f0p6gs4j8w-wasmtime-10.0.1-dev/include -fno-lto --listen=- 
...
Build Summary: 54/91 steps succeeded; 18 failed (disable with --summary none)
test-c-abi transitive failure
├─ run test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-Debug transitive failure
│  └─ zig test test-c-abi-mips-linux.4.19...6.5.7-musl-mips32-Debug Debug mips-linux-musl 1 errors
├─ run test-c-abi-wasm32-wasi-musl-generic-Debug transitive failure
│  └─ zig test test-c-abi-wasm32-wasi-musl-generic-Debug Debug wasm32-wasi-musl failure
├─ run test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-Debug transitive failure
│  └─ zig test test-c-abi-powerpc-linux.4.19...6.5.7-musl-ppc-Debug Debug powerpc-linux-musl 1 errors
error: the following build command failed with exit code 1:
/home/andy/dev/zig/zig-cache/o/71ed747cc5906e89b3cc24d2890229f4/build /home/andy/dev/zig/build-release/stage4/bin/zig /home/andy/dev/zig /home/andy/dev/zig/zig-cache /home/andy/.cache/zig --seed 0x8d1ea933 test-c-abi -Denable-llvm -fwasmtime -fqemu

and you can get the nonsensical output if you pass --prominent-compile-errors.

That paste above is only the first 3, but you can already see how the output is more discernible.

@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. zig build system labels Nov 29, 2023
@MasterQ32
Copy link
Contributor

With that structure, how can i add a file that i can import with @embedFile? With the previous system, i added the binary file as a module and could just import it. Will that feature stay?

Copy link
Contributor

@sin-ack sin-ack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of typos I noticed in documentation.

pic: ?bool,
red_zone: ?bool,
/// Whether to omit the stack frame pointer. Frees up a register and makes it
/// more more difficiult to obtain stack traces. Has target-dependent effects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// more more difficiult to obtain stack traces. Has target-dependent effects.
/// more difficult to obtain stack traces. Has target-dependent effects.

depending_steps: std.AutoArrayHashMapUnmanaged(*std.Build.Step.Compile, void),
/// This could either be a generated file, in which case the module
/// contains exactly one file, or it could be a path to the root source
/// file of directory of files which constitute the module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be intended.

Suggested change
/// file of directory of files which constitute the module.
/// file or directory of files which constitute the module.

pic: ?bool = null,
red_zone: ?bool = null,
/// Whether to omit the stack frame pointer. Frees up a register and makes it
/// more more difficiult to obtain stack traces. Has target-dependent effects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// more more difficiult to obtain stack traces. Has target-dependent effects.
/// more difficult to obtain stack traces. Has target-dependent effects.

@xdBronch
Copy link
Contributor

how can i add a file that i can import with @embedfile?

if im not wrong you would do

exe.root_module.addAnonymousImport("name", .{ 
    .target = target,
    .optimize = optimize, 
    .root_source_file = some_lazy_path,
});

@mlugg
Copy link
Member

mlugg commented Nov 29, 2023

Nice - I had tried a few times to make this change in the frontend, but it does make sense to first make the corresponding build system changes, since they're the biggest practical issue. I can't look through this in much detail currently (got a lot going on), but I'm glad it's been worked on. Make sure there's a check and error message for other modules depending on the main module, since that's a scenario the frontend can't currently encode!

@andrewrk
Copy link
Member Author

andrewrk commented Dec 3, 2023

With that structure, how can i add a file that i can import with @embedFile? With the previous system, i added the binary file as a module and could just import it. Will that feature stay?

Still works. Perhaps a convenience API could be added to make it more clear that it's allowed.

@andrewrk andrewrk force-pushed the std-build-module branch 3 times, most recently from 2920061 to a5cc086 Compare December 5, 2023 04:30
@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Dec 5, 2023
@kubkon
Copy link
Member

kubkon commented Dec 5, 2023

@andrewrk I believe #18207 should fix the CI for you.

@andrewrk andrewrk force-pushed the std-build-module branch 3 times, most recently from 11f86d4 to e785d4f Compare December 10, 2023 23:12
@andrewrk andrewrk force-pushed the std-build-module branch 3 times, most recently from cf7864c to c36c3e4 Compare December 25, 2023 07:21
@andrewrk andrewrk changed the title introduce std.Build.Module and extract some logic into it Move many settings from being per-Compilation to being per-Module Dec 27, 2023
@andrewrk andrewrk added frontend Tokenization, parsing, AstGen, Sema, and Liveness. linking labels Dec 27, 2023
@andrewrk andrewrk force-pushed the std-build-module branch 4 times, most recently from 0ca3db0 to 4c6a12d Compare December 29, 2023 23:59
00JCIV00 added a commit to 00JCIV00/cova that referenced this pull request Jan 6, 2024
- Fixed Module usage in `build.zig` for the latest Zig Build API.
- Ref: ziglang/zig#18160
abhinav added a commit to abhinav/txtar.zig that referenced this pull request Jan 6, 2024
ziglang/zig#18160 introduces a few breaking
changes to the build APIs.

This handles those differences where relevant,
building with both, 0.11 and the latest master.
abhinav added a commit to abhinav/txtar.zig that referenced this pull request Jan 6, 2024
ziglang/zig#18160 introduces a few breaking
changes to the build APIs.

This handles those differences where relevant,
building with both, 0.11 and the latest master.
jiacai2050 added a commit to jiacai2050/zigcli that referenced this pull request Jan 7, 2024
jiacai2050 added a commit to zigcc/zig-cookbook that referenced this pull request Jan 7, 2024
batiati added a commit to batiati/mustache-zig that referenced this pull request Jan 7, 2024
batiati added a commit to batiati/mustache-zig that referenced this pull request Jan 7, 2024
Phytolizer added a commit to Phytolizer/Minsk that referenced this pull request Jan 12, 2024
Arnau478 added a commit to os-chain/chain that referenced this pull request Jan 14, 2024
- VMM
- Paging for x86_64
- Updated to zig master
- Now exceptions halt the OS, to avoid double faults
- Because of the removal of `main_mod_path` (see ziglang/zig#18160) the file with the entry point has to be directly on the module root path. To solve this, we now have a `src/main.zig` that does a `usingnamespace` with a `switch` for the appropiate `start.zig` file. As a benefit, some generic functions like `panic` or the `root.os` abstraction layer can be here.
- HAL system, mainly to abstract `cpu.zig`
RonaldZielaznicki added a commit to RonaldZielaznicki/zig.guide that referenced this pull request Jan 26, 2024
ziglang/zig#18160 changed module syntax. This change brings the documentation in line with these updates.
Sobeston pushed a commit to Sobeston/zig.guide that referenced this pull request Feb 2, 2024
ziglang/zig#18160 changed module syntax. This change brings the documentation in line with these updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. frontend Tokenization, parsing, AstGen, Sema, and Liveness. linking standard library This issue involves writing Zig code for the standard library. zig build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.Build.Module should include APIs from CompileStep
6 participants