821 Commits

Author SHA1 Message Date
Jakub Konka
ee7a027059 macho: parse dependent dylibs 2024-01-24 12:34:39 +01:00
ndbn
9e684e8d1a
Fix wrong if condition for windows (#18637)
Fixes #18594
2024-01-22 15:32:23 -05:00
Andrew Kelley
10aff67502
Merge pull request #18596 from ypsvlq/mingw
mingw-w64: add missing CRT sources
2024-01-20 12:01:33 -08:00
Andrew Kelley
5c4cb60f4f
Merge pull request #18622 from ziglang/zig-mod-edge-case
build system: better handle modules that do not have a zig root source file
2024-01-20 03:22:02 -08:00
Xavier Bouchoux
1a98fcd00a zig cc: expose clang precompiled C header support
see https://releases.llvm.org/17.0.1/tools/clang/docs/UsersManual.html#generating-a-pch-file

syntax examples:
`zig cc -x c-header test.h -o test.pch`
`zig cc -include-pch test.pch main.c`

`zig c++ -x c++-header test.h -o test.pch`
`zig c++ -include-pch test.pch main.cpp`
2024-01-19 22:05:09 -08:00
Andrew Kelley
41eff5723d Compilation: avoid caching root source file twice
The deleted lines here are redundant because they happen first thing
inside the function call below.

Additionally, skip hashing the root source file if it is an empty
string. I explored making this field along with `root` optional but
found this to be less messy actually.
2024-01-19 22:18:04 -07:00
Elaine Gibson
398ab5fcfb mingw: update build logic 2024-01-20 00:24:39 +00:00
Jan200101
8707555c0b compiler: move each_lib_rpath to frontend
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2024-01-14 16:16:00 -07:00
Andrew Kelley
3051d4390b Compilation: fix tsan error reporting 2024-01-10 00:51:02 -07:00
dhash
9bb6430318 Add support for --(no-)undefined-version
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Co-authored-by: Samuel Cantero <scanterog@gmail.com>
Co-authored-by: Giorgos Georgiou <giorgos.georgiou@datadoghq.com>
Co-authored-by: Carl Åstholm <carl@astholm.se>
2024-01-09 17:24:11 +01:00
Andrew Kelley
60094cc3fc
Merge pull request #18491 from ziglang/fix-mod-link-obj-path
std.Build.Step.Compile: fix link object paths
2024-01-09 01:11:15 -08:00
Andrew Kelley
3023d2845c compilation: fix bad path in error message 2024-01-08 18:20:06 -07:00
Andrew Kelley
99922c2708 Compilation: only add __MSVCRT_VERSION__ for -lc
prevents it from being defined twice when building mingw-w64 libs.
2024-01-08 11:52:38 -07:00
Andrew Kelley
7b3afc880b Compilation: add definition to prefer ucrt for windows C/C++ files
This makes C/C++ files when targeting mingw-w64 choose to depend on ucrt
for stdio.
2024-01-08 11:52:38 -07:00
Andrew Kelley
3f4c73ae93 mingw: update from msvcrt to ucrt 2024-01-08 11:52:38 -07:00
Tristan Ross
c78b6564df Compilation: pass code model in buildOutputFromZig 2024-01-06 18:33:24 -08:00
Andrew Kelley
2ac315c245 compiler: fix build runner not added to cache hash
Closes #18438
2024-01-03 17:36:54 -08:00
Andrew Kelley
d5c1e7f7b1 link: accept the update arena in flush
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-01 19:49:08 -07:00
Andrew Kelley
eae6d45cde CLI: introduce global -I args for C include paths
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-01 19:49:08 -07:00
Andrew Kelley
7fb9f58f85 Compilation: rename before flush during whole cache mode
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-01 19:49:08 -07:00
Andrew Kelley
a89d6878d2 Compilation: fix cache hash of incremental builds
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-01 19:49:08 -07:00
Andrew Kelley
e22102dfc6 Compilation: make create() take an arena allocator
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-01 19:49:08 -07:00
Andrew Kelley
b8674910d4 restore -fno-emit-bin -femit-llvm-ir functionality
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-01 19:49:08 -07:00
Andrew Kelley
659e043a34 Compilation: don't add importlib jobs when outputting C code
Fixes "building import libs not included in core functionality" when
bootstrapping on Windows.
2024-01-01 19:49:08 -07:00
Andrew Kelley
6509c492ad move misc_errors from linker to Compilation
So that they can be referenced by getAllErrorsAlloc(). Fixes missing
compile errors.
2024-01-01 19:49:07 -07:00
Andrew Kelley
476484f09c Compilation: inline the flush function
There is only one call to this function and this made it easier to
troubleshoot the logic.
2024-01-01 19:49:07 -07:00
Andrew Kelley
7f13754778 Compilation: fix whole mode cache hash
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-01 19:49:07 -07:00
Andrew Kelley
5b05e99dd4 Compilation: consolidate module hashing code 2024-01-01 19:49:07 -07:00
Andrew Kelley
372b407740 move eh_frame_hdr from link.File to Compilation
since it's accessed by Compilation. fixes an invalid check of
bin_file==null
2024-01-01 19:49:07 -07:00
Andrew Kelley
435b74acd6 move force_undefined_symbols into Compilation
This field is needed by Compilation regardless of whether a link file is
instantiated.

Fixes an invalid check for bin_file=null.
2024-01-01 19:49:07 -07:00
Andrew Kelley
524dc756b3 Compilation: several branch regression fixes
* 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-01 17:51:21 -07:00
Andrew Kelley
57562c8d50 compiler: push entry symbol name resolution into the linker
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-01 17:51:21 -07:00
Andrew Kelley
c9fe43679f frontend: remove deprecated field from Compilation 2024-01-01 17:51:21 -07:00
Andrew Kelley
951c5b3f67 frontend: fix "any" default resolution ambiguity
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-01 17:51:21 -07:00
Andrew Kelley
98dd4f7847 frontend: skip astgen for builtin.zig
since it's already done ahead of time and always unchanging
2024-01-01 17:51:21 -07:00
Andrew Kelley
9141e1a29c CLI: fix logic for sending output file path
via the compiler protocol
2024-01-01 17:51:21 -07:00
Andrew Kelley
8944dea23f CLI: fix regressed logic for any_dyn_libs
This value needs access to the fully resolved set of system libraries,
which required restructuring a bunch of CLI logic.
2024-01-01 17:51:20 -07:00
Andrew Kelley
4b667e7362 fix compilations without zig compilation units 2024-01-01 17:51:20 -07:00
Andrew Kelley
38f2172b0a fix memory leak in addModuleTableToCacheHash 2024-01-01 17:51:20 -07:00
Andrew Kelley
9b98d33d0b Compilation: don't store arena until it's done being used 2024-01-01 17:51:20 -07:00
Andrew Kelley
f256431838 fix compilation errors when enabling llvm 2024-01-01 17:51:20 -07:00
Andrew Kelley
57afdfc8fa compilation: fix build artifact communication from sub-compilation
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-01 17:51:20 -07:00
Andrew Kelley
0be97b5ae3 fix population of builtin.zig not making the parent dir 2024-01-01 17:51:20 -07:00
Andrew Kelley
9715936472 Compilation: oops! used comp before init 2024-01-01 17:51:20 -07:00
Andrew Kelley
2047a6b82d fix remaining compile errors except one 2024-01-01 17:51:20 -07:00
Andrew Kelley
48d5861f92 fix more compilation errors introduced by this branch 2024-01-01 17:51:20 -07:00
Andrew Kelley
638db680f4 move dll_export_fns and rdynamic to Compilation.Config 2024-01-01 17:51:20 -07:00
Andrew Kelley
92b54e50c8 glibc: update to new Compilation API 2024-01-01 17:51:19 -07:00
Andrew Kelley
7e7d5dc958 musl: update references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
c49957dbe8 fix a round of compile errors caused by this branch 2024-01-01 17:51:19 -07:00