aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2024-01-01link: accept the update arena in flushAndrew Kelley
This branch introduced an arena allocator for temporary allocations in Compilation.update. Almost every implementation of flush() inside the linker code was already creating a local arena that had the lifetime of the function call. This commit passes the update arena so that all those local ones can be deleted, resulting in slightly more efficient memory usage with every compilation update. While at it, this commit also removes the Compilation parameter from the linker flush function API since a reference to the Compilation is now already stored in `link.File`.
2024-01-01CLI: introduce global -I args for C include pathsAndrew Kelley
This isn't technically needed since per-module -I args can suffice, but this can produce very long CLI invocations when several --mod args are combined with --search-prefix args since the -I args have to be repeated for each module. This is a partial revert of ecbe8bbf2df2ed4d473efbc32e0b6d7091fba76f.
2024-01-01Compilation: rename before flush during whole cache modeAndrew Kelley
The linker needs to know the file system path of output in the flush function because file paths inside the build artifacts reference each other. Fixes a regression introduced in this branch.
2024-01-01Compilation: fix cache hash of incremental buildsAndrew Kelley
Without this commit, unrelated test builds using incremental cache mode (self-hosted, no lld) would end up using the same cache namespace, which is undesireable since concurrent builds will clobber each other's work. This happened because of passing the root module to addModuleToCacheHash. In the case of a test build, the root module actually does not connect to the rest of the import table. Instead, the main module needs to be passed, which has "root" in its import table. The other call to addModuleTableToCacheHash which is in addNonIncrementalStuffToCacheManifest already correctly passes the main module. In the future, I think this problem can be fully addressed by obtaining an advisory lock on the output binary file. However, even in that case, it is still valuable to make different compilations use different cache namespaces lest unrelated compilations suffer from pointless thrashing rather than being independently edited.
2024-01-01Compilation: make create() take an arena allocatorAndrew Kelley
Instead of making its own inside create. 10 out of 10 calls to create() had already an arena in scope, so this commit means that 10 instances of Compilation now reuse an existing arena with the same lifetime rather than creating a redundant one. In other words, this very slightly optimizes initialization of the frontend in terms of memory allocation.
2024-01-01restore -fno-emit-bin -femit-llvm-ir functionalityAndrew Kelley
Now, link.File will always be null when -fno-emit-bin is specified, and in the case that LLVM artifacts are still required, the Zcu instance has an LlvmObject.
2024-01-01Compilation: don't add importlib jobs when outputting C codeAndrew Kelley
Fixes "building import libs not included in core functionality" when bootstrapping on Windows.
2024-01-01move misc_errors from linker to CompilationAndrew Kelley
So that they can be referenced by getAllErrorsAlloc(). Fixes missing compile errors.
2024-01-01Compilation: inline the flush functionAndrew Kelley
There is only one call to this function and this made it easier to troubleshoot the logic.
2024-01-01Compilation: fix whole mode cache hashAndrew Kelley
before this commit it was trying to hash based on resolved bin_file settings, but bin_file was always null since cache mode is always whole when this function is called! hash based on the lf_open_opts instead.
2024-01-01Compilation: consolidate module hashing codeAndrew Kelley
2024-01-01move eh_frame_hdr from link.File to CompilationAndrew Kelley
since it's accessed by Compilation. fixes an invalid check of bin_file==null
2024-01-01move force_undefined_symbols into CompilationAndrew Kelley
This field is needed by Compilation regardless of whether a link file is instantiated. Fixes an invalid check for bin_file=null.
2024-01-01Compilation: several branch regression fixesAndrew Kelley
* move wasi_emulated_libs into Compilation - It needs to be accessed from Compilation, which needs to potentially build those artifacts. * Compilation: improve error reporting for two cases - the setMiscFailure mechanism is handy - let's use it! * fix one instance of incorrectly checking for emit_bin via `comp.bin_file != null`. There are more instances of this that need to be fixed in a future commit. * fix renameTmpIntoCache not handling the case where it needs to make the "o" directory in the zig-cache directory. - while I'm at it, simplify the logic for handling the fact that Windows returns error.AccessDenied rather than error.PathAlreadyExists for failure to rename a directory over another one. * fix missing cache hash additions - there are still more to add in a future commit - addNonIncrementalStuffToCacheManifest is called when bin_file is always null, and then it incorrectly checks if bin_file is non-null and only then adds a bunch of stuff to the cache hash. It needs to instead add to the cache hash based on lf_open_opts.
2024-01-01compiler: push entry symbol name resolution into the linkerAndrew Kelley
This is necessary because on COFF, the entry symbol name is not known until the linker has looked at the set of global symbol names to determine which of the four possible main entry points is present.
2024-01-01frontend: remove deprecated field from CompilationAndrew Kelley
2024-01-01frontend: fix "any" default resolution ambiguityAndrew Kelley
In Compilation.create, update the resolved config to account for the default resolution of the root module. This makes it so that, for example, reading comp.config.any_non_single_threaded is valid in order to determine whether any module has single_threaded=false.
2024-01-01frontend: skip astgen for builtin.zigAndrew Kelley
since it's already done ahead of time and always unchanging
2024-01-01CLI: fix logic for sending output file pathAndrew Kelley
via the compiler protocol
2024-01-01CLI: fix regressed logic for any_dyn_libsAndrew Kelley
This value needs access to the fully resolved set of system libraries, which required restructuring a bunch of CLI logic.
2024-01-01fix compilations without zig compilation unitsAndrew Kelley
2024-01-01fix memory leak in addModuleTableToCacheHashAndrew Kelley
2024-01-01Compilation: don't store arena until it's done being usedAndrew Kelley
2024-01-01fix compilation errors when enabling llvmAndrew Kelley
2024-01-01compilation: fix build artifact communication from sub-compilationAndrew Kelley
in whole cache mode, build artifacts are communicated by accessing the whole cache information, for which there is a helper method called toCrtFile
2024-01-01fix population of builtin.zig not making the parent dirAndrew Kelley
2024-01-01Compilation: oops! used comp before initAndrew Kelley
2024-01-01fix remaining compile errors except oneAndrew Kelley
2024-01-01fix more compilation errors introduced by this branchAndrew Kelley
2024-01-01move dll_export_fns and rdynamic to Compilation.ConfigAndrew Kelley
2024-01-01glibc: update to new Compilation APIAndrew Kelley
2024-01-01musl: update references to bin_file.optionsAndrew Kelley
2024-01-01fix a round of compile errors caused by this branchAndrew Kelley
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-01Compilation: redo whole vs incremental logic in create and updateAndrew Kelley
2024-01-01compiler: update many references to bin_file.optionsAndrew Kelley
2024-01-01compiler: update references to targetAndrew Kelley
2024-01-01update libunwind references to bin_file.optionsAndrew Kelley
2024-01-01update references to module (to be renamed to zcu)Andrew Kelley
2024-01-01remove parent_compilation_link_libcAndrew Kelley
2024-01-01linkers: update references to "options" fieldAndrew Kelley
2024-01-01update image_base referencesAndrew Kelley
2024-01-01compiler: update references to single_threadedAndrew Kelley
2024-01-01move a large chunk of linker logic away from "options"Andrew Kelley
These options are only supposed to be provided to the initialization functions, resolved, and then computed values stored in the appropriate place (base struct or the object-format-specific structs). Many more to go...
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-01compiler: get the dynamic linker from the targetAndrew Kelley
instead of passing it to Compilation separately and storing it separately in the linker options.
2024-01-01std.Target: add DynamicLinkerAndrew Kelley
2024-01-01zig build system: change target, compilation, and module APIsAndrew Kelley
Introduce the concept of "target query" and "resolved target". A target query is what the user specifies, with some things left to default. A resolved target has the default things discovered and populated. In the future, std.zig.CrossTarget will be rename to std.Target.Query. Introduces `std.Build.resolveTargetQuery` to get from one to the other. The concept of `main_mod_path` is gone, no longer supported. You have to put the root source file at the module root now. * remove deprecated API * update build.zig for the breaking API changes in this branch * move std.Build.Step.Compile.BuildId to std.zig.BuildId * add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions, std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and std.Build.TestOptions. * remove `std.Build.constructCMacro`. There is no use for this API. * deprecate `std.Build.Step.Compile.defineCMacro`. Instead, `std.Build.Module.addCMacro` is provided. - remove `std.Build.Step.Compile.defineCMacroRaw`. * deprecate `std.Build.Step.Compile.linkFrameworkNeeded` - use `std.Build.Module.linkFramework` * deprecate `std.Build.Step.Compile.linkFrameworkWeak` - use `std.Build.Module.linkFramework` * move more logic into `std.Build.Module` * allow `target` and `optimize` to be `null` when creating a Module. Along with other fields, those unspecified options will be inherited from parent `Module` when inserted into an import table. * the `target` field of `addExecutable` is now required. pass `b.host` to get the host target.
2024-01-01Compilation: cleanup hashmap usageJacob Young
2023-12-13Compilation: remove parent_compilation_link_libcAndrew Kelley
This option is not needed since the link_libc flag can be set directly when creating compiler_rt. This fixes a problem where an immutable flag was being mutated in Sema.