aboutsummaryrefslogtreecommitdiff
path: root/src/Package/Module.zig
AgeCommit message (Collapse)Author
2025-02-28Revert "Merge pull request #22898 from kristoff-it/deprecated-proposal"Andrew Kelley
This reverts commit dea72d15da4fba909dc3ccb2e9dc5286372ac023, reversing changes made to ab381933c87bcc744058d25a876cfdc0d23fc674. The changeset does not work as advertised and does not have sufficient test coverage. Reopens #22822
2025-02-26don't inherit allowed deprecation from parent modulesAndrew Kelley
Inheriting allow-deprecation from parent modules doesn't make too much sense, so instead make them default to disallow unless otherwise specified. This allows build system to avoid redundant `-fno-allow-deprecated` args. This makes the generated CLIs smaller, and makes zig1.wasm update not needed. Also represented `is_root` differently (moved to field of graph).
2025-02-26initial implementation of `@deprecated`Loris Cro
2025-02-04compiler: don't perform semantic analysis if there are files without ZIRmlugg
2025-02-04Zcu: remove `*_loaded` fields on `File`mlugg
Instead, `source`, `tree`, and `zir` should all be optional. This is precisely what we're actually trying to model here; and `File` isn't optimized for memory consumption or serializability anyway, so it's fine to use a couple of extra bytes on actual optionals here.
2025-01-23Package.Module: Make create() fall back on options.global.root_optimize_mode.Alex Rønne Petersen
As is done for root_strip and root_error_tracing.
2025-01-23compiler: Fix computation of Compilation.Config.any_unwind_tables.Alex Rønne Petersen
This moves the default value logic to Package.Module.create() instead and makes it so that Compilation.Config.any_unwind_tables is computed similarly to any_sanitize_thread, any_fuzz, etc. It turns out that for any_unwind_tables, we only actually care if unwind tables are enabled at all, not at what level.
2025-01-18compiler: Fix @import("builtin").unwind_tables logic.Alex Rønne Petersen
2024-12-19Module: keep frame pointer in ReleaseSmall on x86wooster0
On x86 and x86_64 keeping the frame pointer usually reduces binary size, even for simple programs: ``` ~$ cat x.zig pub fn main() void { @import("std").debug.print("hello", .{}); } ~$ zig build-exe x.zig -target x86_64-linux -OReleaseSmall -fno-omit-frame-pointer && wc -c x 5168 x ~$ zig build-exe x.zig -target x86_64-linux -OReleaseSmall -fomit-frame-pointer && wc -c x 5216 x ``` ``` ~$ cat x.zig pub fn main() void { @import("std").debug.print("hello", .{}); } ~$ zig build-exe x.zig -target x86-linux -OReleaseSmall -fno-omit-frame-pointer && wc -c x 3400 x ~$ zig build-exe x.zig -target x86-linux -OReleaseSmall -fomit-frame-pointer && wc -c x 3556 x ``` A bigger benchmark is the Zig compiler: With no changes to anything on master branch: ``` $ zig build -Dno-lib -Dno-langref --zig-lib-dir lib -Doptimize=ReleaseSmall $ wc -c zig-out/bin/zig 10698792 zig-out/bin/zig ``` Adding `.omit_frame_pointer = false` in `addCompilerStep` in `build.zig`: ``` $ zig build -Dno-lib -Dno-langref --zig-lib-dir lib -Doptimize=ReleaseSmall $ wc -c zig-out/bin/zig 10155744 zig-out/bin/zig ```
2024-12-11compiler: Improve the handling of unwind table levels.Alex Rønne Petersen
The goal here is to support both levels of unwind tables (sync and async) in zig cc and zig build. Previously, the LLVM backend always used async tables while zig cc was partially influenced by whatever was Clang's default.
2024-12-08compiler: Only omit frame pointers by default for ReleaseSmall.Alex Rønne Petersen
Frame pointers make both debugging and profiling work better, and the overhead is reportedly 1% or less for typical programs [0]. I think the pros outweigh the cons here. People who *really* care about that 1% can simply use the -fomit-frame-pointer option to reclaim it. For ReleaseSmall, though, it makes sense to omit frame pointers by default for the sake of code size, as we already strip the binary in this case anyway. Closes #22161. [0] https://www.brendangregg.com/blog/2024-03-17/the-return-of-the-frame-pointers.html
2024-11-20Append disabled LLVM CPU features after enabled onesShawn Gao
2024-11-05Compilation: Move no_builtin to Package.Module.Alex Rønne Petersen
This option, by its very nature, needs to be attached to a module. If it isn't, the code in a module could break at random when compiled into an application that doesn't have this option set. After this change, skip_linker_dependencies no longer implies no_builtin in the LLVM backend.
2024-10-16incremental: introduce `file` dependencies to handle AstGen failuresmlugg
The re-analysis here is a little coarse; it'd be nice in the future to have a way for an AstGen failure to preserve *all* analysis which depends on the last success, and just hide the compile errors which depend on it somehow. But I'm not sure how we'd achieve that, so this works fine for now. Resolves: #21223
2024-07-22initial support for integrated fuzzingAndrew Kelley
* Add the `-ffuzz` and `-fno-fuzz` CLI arguments. * Detect fuzz testing flags from zig cc. * Set the correct clang flags when fuzz testing is requested. It can be combined with TSAN and UBSAN. * Compilation: build fuzzer library when needed which is currently an empty zig file. * Add optforfuzzing to every function in the llvm backend for modules that have requested fuzzing. * In ZigLLVMTargetMachineEmitToFile, add the optimization passes for sanitizer coverage. * std.mem.eql uses a naive implementation optimized for fuzzing when builtin.fuzz is true. Tracked by #20702
2024-07-04Zcu: extract permanent state from FileAndrew Kelley
Primarily, this commit removes 2 fields from File, relying on the data being stored in the `files` field, with the key as the path digest, and the value as the struct decl corresponding to the File. This table is serialized into the compiler state that survives between incremental updates. Meanwhile, the File struct remains ephemeral data that can be reconstructed the first time it is needed by the compiler process, as well as operated on by independent worker threads. A key outcome of this commit is that there is now a stable index that can be used to refer to a File. This will be needed when serializing error messages to survive incremental compilation updates.
2024-06-22rename src/Module.zig to src/Zcu.zigAndrew Kelley
This patch is a pure rename plus only changing the file path in `@import` sites, so it is expected to not create version control conflicts, even when rebasing.
2024-03-21move Package.Path to std.Build.Cache.PathAndrew Kelley
2024-03-11std.builtin: make link mode fields lowercaseTristan Ross
2024-03-07Package.Module: actually set File.path_digest for builtin modulesmlugg
2024-03-06Package.Module: deduplicate identical builtin modulesmlugg
Previously, when multiple modules had builtin modules with identical sources, two distinct `Module`s and `File`s were created pointing at the same file path. This led to a bug later in the frontend. These modules are now deduplicated with a simple hashmap on the builtin source.
2024-02-01remove std.io.ModeVeikka Tuominen
2024-01-01frontend: fix populateTestFunctions accessing the wrong moduleAndrew Kelley
The test runner reads the list of test function pointers from its own builtin module, which is the root_mod, not main_mod.
2024-01-01Package.Module: fix typo in default red-zone settingAndrew Kelley
oops, this was supposed to return true, not false.
2024-01-01fix compilation errors when enabling llvmAndrew Kelley
2024-01-01fix population of builtin.zig not making the parent dirAndrew Kelley
2024-01-01libcxx: update to new Compilation APIAndrew Kelley
2024-01-01update bin_file.options references in SemaAndrew Kelley
mainly pertaining to error return tracing
2024-01-01compiler: miscellaneous branch progressAndrew Kelley
implement builtin.zig file population for all modules rather than assuming there is only one global builtin.zig module. move some fields from link.File to Compilation move some fields from Module to Compilation compute debug_format in global Compilation config resolution wire up C compilation to the concept of owner modules make whole cache mode call link.File.createEmpty() instead of link.File.open()
2024-01-01compiler: update many references to bin_file.optionsAndrew Kelley
2024-01-01frontend: fix stack protector option logicAndrew Kelley
Commit 97e23896a9168132b6d36ca22ae1af10dd53d80d regressed this behavior because it made target_util.supportsStackProtector *correctly* notice which zig backend is being used to generate code, while the logic calling that function *incorrectly assumed* that .zig code is being compiled, when in reality it might be only C code being compiled. This commit adjusts the option resolution logic for stack protector so that it takes into account the zig backend only if there is a zig compilation unit. A separate piece of logic checks whether clang supports stack protector for a given target. closes #18009 closes #18114 closes #18254
2024-01-01WIP: move many global settings to become per-ModuleAndrew Kelley
Much of the logic from Compilation.create() is extracted into Compilation.Config.resolve() which accepts many optional settings and produces concrete settings. This separate step is needed by API users of Compilation so that they can pass the resolved global settings to the Module creation function, which itself needs to resolve per-Module settings. Since the target and other things are no longer global settings, I did not want them stored in link.File (in the `options` field). That options field was already a kludge; those options should be resolved into concrete settings. This commit also starts to work on that, deleting link.Options, moving the fields into Compilation and ObjectFormat-specific structs instead. Some fields were ephemeral and should not have been stored at all, such as symbol_size_hint. The link.File object of Compilation is now a `?*link.File` and `null` when -fno-emit-bin is passed. It is now arena-allocated along with Compilation itself, avoiding some messy cleanup code that was there before. On the command line, it is now possible to configure the standard library itself by using `--mod std` just like any other module. This meant that the CLI needed to create the standard library module rather than having Compilation create it. There are a lot of changes in this commit and it's still not done. I didn't realize how quickly this changeset was going to balloon out of control, and there are still many lines that need to be changed before it even compiles successfully. * introduce std.Build.Cache.HashHelper.oneShot * add error_tracing to std.Build.Module * extract build.zig file generation into src/Builtin.zig * each CSourceFile and RcSourceFile now has a Module owner, which determines some of the C compiler flags.
2024-01-01Compilation: cleanup hashmap usageJacob Young
2023-10-08give modules friendly names for error reportingAndrew Kelley
2023-10-08CLI: finish updating module API usageAndrew Kelley
Finish the work started in 4c4fb839972f66f55aa44fc0aca5f80b0608c731. Now the compiler compiles again. Wire up dependency tree fetching code in the CLI for `zig build`. Everything is hooked up except for `createDependenciesModule` is not yet implemented.
2023-10-08get `zig fetch` working with the new systemAndrew Kelley
* start renaming "package" to "module" (see #14307) - build system gains `main_mod_path` and `main_pkg_path` is still there but it is deprecated. * eliminate the object-oriented memory management style of what was previously `*Package`. Now it is `*Package.Module` and all pointers point to externally managed memory. * fixes to get the new Fetch.zig code working. The previous commit was work-in-progress. There are still two commented out code paths, the one that leads to `Compilation.create` and the one for `zig build` that fetches the entire dependency tree and creates the required modules for the build runner.