125 Commits

Author SHA1 Message Date
Andrew Kelley
5b2a79848c stage2: cleanups regarding red zone CLI flags
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang.
 * build.zig: remove the double negative and make it an optional bool.
   This follows precedent from other flags, allowing the compiler CLI to
   be the decider of what is default instead of duplicating the default
   value into the build system code.
 * Compilation: make it an optional `want_red_zone` instead of a
   `no_red_zone` bool. The default is decided by a call to
   `target_util.hasRedZone`.
 * When creating a Clang command line, put -mred-zone on the command
   line if we are forcing it to be enabled.
 * Update update_clang_options.zig with respect to the recent {s}/{} format changes.
 * `zig cc` integration with red zone preference.
2021-01-11 22:07:21 -07:00
Lee Cannon
8932c2d745 Added support for no red zone 2021-01-11 22:07:14 -07:00
Andrew Kelley
29928af600
Merge pull request #7729 from jayschwa/remove-deprecated-stream
Remove deprecated stream aliases
2021-01-09 13:04:08 -08:00
xackus
e4b8148e9c Fix system library path detection on linux
Uses the NativeTargetInfo results instead of std.Target.current.
2021-01-08 20:07:59 -07:00
LemonBoy
eb696e453f stage2: Implicitly enable --eh_frame_hdr when compiling c/c++ files
Matches what Clang/GCC driver do.

Closes #7711
2021-01-08 19:01:05 -08:00
Jay Petacat
1595ce273e Remove deprecated stream aliases 2021-01-08 16:54:56 -05:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00
Jakub Konka
70771283c5 Want native headers when linking with frameworks
This PR ensures we use system libc headers and system search paths for
framework headers when linking against frameworks and compiling natively
on macOS.
2021-01-07 23:47:37 -08:00
Timon Kruiper
b1cfa923be stage2: rename and move files related to LLVM backend 2021-01-06 10:52:20 +01:00
Andrew Kelley
c8e44d82bd stage2: remove the Cache deadlock detection code
It's more trouble than it's worth; it didn't even catch the most recent
incident because it was across process boundaries anyway.
2021-01-03 20:34:51 -07:00
Andrew Kelley
404dc9692e stage2: fix Cache debug deadlock code memory leak 2021-01-03 20:34:51 -07:00
Andrew Kelley
d8f3f14532
Merge pull request #7647 from ziglang/stage2-comptime-fn-call
stage2: comptime function calls and inline function calls
2021-01-02 22:01:51 -08:00
g-w1
3d151fbfc8 fix 7665:
only add self exe path when testing
2021-01-02 20:35:44 -08:00
Andrew Kelley
50a530196c stage2: fix handling compile error in inline fn call
* scopes properly inherit inlining information
 * compile errors of inline function calls are properly attached to the
   caller rather than the callee.
   - added a test case for this
 * --watch still opens a repl if compile errors happen.
2021-01-02 19:11:56 -07:00
Andrew Kelley
974c008a0e convert more {} to {d} and {s} 2021-01-02 19:03:14 -07:00
LemonBoy
1c13ca5a05 stage2: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
Sizhe Zhao
af8eab546e Fix usage message 2021-01-02 16:03:41 -08:00
Jakub Konka
91a35e1a92 Detect native iframework dirs on macOS
This commit adds default search paths for system frameworks
on macOS while also adding `-isysroot` for OS versions at least BigSur.
Since BigSur (11.0.1), neither headers nor libs exist in standard
root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they
are now exclusively part of the installed developer toolchain (either
via XCode.app or CLT), and specifying `-isysroot` allows us to keep
using universal search paths such as `/System/Library/Frameworks` while
only changing the include flag from `-iframework` to
`-iframeworkwithsysroot`.
2021-01-02 15:29:05 +01:00
Andrew Kelley
0b46c27333 zig test: release Compilation Cache locks
before executing child process. This fixes a deadlock when the test
wanted to obtain the same lock on compiler_rt.o that was held by the
process building the test binary itself.
2020-12-29 11:47:29 -07:00
Andrew Kelley
a62353fb4b fix zig test with regards to passing parameters 2020-12-28 22:15:07 -07:00
Andrew Kelley
7ca9f3bc7b zig test: std.testing.zig_exe_path is now available
it will be set to the path of the zig executable which is running
`zig test`.
2020-12-28 20:00:34 -07:00
Timon Kruiper
4a0d64300b stage2: rename llvm.zig to llvm_bindings.zig
Putting functions in this file will create functions like
`llvm.function`, and the compiler thinks these are llvm intrinsics.
2020-12-28 21:15:13 +01:00
Andrew Kelley
3f9588ca29 std: do not call malloc() between fork() and execv()
We were violating the POSIX standard which resulted in a deadlock on
musl v1.1.24 on aarch64 alpine linux, uncovered with the new ThreadPool
usage in the stage2 compiler.

std.os execv functions that accept an Allocator parameter are removed
because they are footguns. The POSIX standard does not allow calls to
malloc() between fork() and execv() and since it is common to both
(1) call execv() after fork() and (2) use std.heap.c_allocator,
Programmers are encouraged to go through the `std.process` API
instead, causing some dissonance when combined with `std.os` APIs.

I also slapped a big warning message on all the relevant doc comments.
2020-12-26 13:50:26 -07:00
Andrew Kelley
42b4a48bc9 WIP start adding support for TSAN 2020-12-24 01:18:47 -07:00
Alex Cameron
ca282184ae Implement parsing for multi-arg Clang options. 2020-12-23 15:03:11 +02:00
g-w1
51a904677c
update depreciated code (#7502)
* `zig env`:

* fix depreciated interface, update outStream -> writer
* make code more readable by updating `anytype` -> `std.fs.File.Writer`
2020-12-23 13:01:29 +02:00
Veikka Tuominen
03113d9246
Merge pull request #7111 from tetsuo-cpp/emit-h
Implement emit-h
2020-12-23 00:01:22 +02:00
Veikka Tuominen
ba2f2e1393
Merge pull request #7476 from ifreund/pkgs
stage2: free Package resources, print package path on --pkg-begin failure
2020-12-23 00:00:37 +02:00
Alex Cameron
e834d0369a Make sure emit-h is off by default. 2020-12-23 01:14:35 +11:00
Alex Cameron
aba273d731 Enable emit-h by default for obj and lib compilation. 2020-12-23 01:14:35 +11:00
Andrew Kelley
0d1cd0d482 use kprotty's ThreadPool implementation (v5) 2020-12-20 15:08:59 -07:00
Andrew Kelley
013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
Isaac Freund
fa09c3a5e7
stage2: print package path on --pkg-begin failure
This makes it much easier for the user to figure out what has gone wrong
than dumping an error return trace.
2020-12-17 20:03:15 +01:00
Isaac Freund
c102eb83e6
stage2: free Package resources
Without this commit we leak file descriptors and memory
2020-12-17 19:32:40 +01:00
Andrew Kelley
6dfe9cc83e zig cc: default to a.exe on windows
This matches Clang. Thanks to Abner Coimbre for pointing this out.
2020-12-16 21:37:15 -07:00
Isaac Freund
1d8f33ca98
stage2: link musl dynamically by default if native
If targeting the native OS and the system libc is musl, link against it
dynamically by default.
2020-12-13 00:40:35 +01:00
Andrew Kelley
6ab5bebed1 stage2: proper file extension stripping
Previously it used mem.split on "." and took the first iterated item.
Now it uses fs.path.extension and strips off that number of bytes.

Closes #7404
2020-12-11 17:42:13 -07:00
Andrew Kelley
f7d600675c CLI: improved local cache directory logic
Previously, when choosing the local cache directory, if there was no
root source file, an explicitly chosen path, or other clues, zig would
choose cwd + zig-cache/ as the local cache directory.

This can be problematic if Zig is invoked with the CWD set to a
read-only directory, or a directory unrelated to the actual source files
being compiled. In the real world, we see this when using `zig cc` with
CGo, which for some reason changes the current working directory to the
read-only go standard library path before running the C compiler.

This commit conservatively chooses to use the global cache directory
as the local cache directory when there is no other reasonable choice,
and no longer will rely on the cwd path to choose a local cache directory.

As a reminder, the --cache-dir CLI flag and ZIG_LOCAL_CACHE_DIR
environment variable are available for overriding the decision. For the
zig build system, it will always choose the directory that build.zig is
+ zig-cache/.

Closes #7342
2020-12-10 16:17:02 -07:00
antlilja
26399b5249 Added global-cache argument to build system + removed extra args.
* Field global_cache_root was added to Builder struct along with
mandatory argument for build_runner.zig. Logic for using the custom
global cache was also added.

* The arguments --cache-dir and --global-cache-dir are no longer passed
directly through to build_runner.zig and are instead only passed through the
mandatory cache_root and global_cache_root arguments.
2020-12-10 18:06:19 -05:00
Andrew Kelley
cb896a6573 CLI: infer --name based on first C source file or object
Previously, --name would only be inferred if there was exactly 1 C
source file or exactly 1 object. Now it will be inferred if there is at
least one of either.
2020-12-09 21:20:13 -07:00
Timon Kruiper
4c51adeb0d Do not keep the build.zig cache manifest file locked.
This allows to have multiple instances of `zig build` at the same
time. For example when you have a long running `zig build run` and
then want to run `zig build somethingelse`.
2020-12-09 22:16:04 -05:00
Lee Cannon
3599fb9bfc Fixes #7352 - ignore zig fmt ignore zig-cache 2020-12-09 12:11:52 +02:00
Andrew Kelley
72f6c6e634 invoke LLD as a child process rather than a library
Closes #3825
2020-12-08 20:00:16 -07:00
Andrew Kelley
2759313263 add support for environment variables to control cache directories
This commit adds:

ZIG_LOCAL_CACHE_DIR corresponding to --cache-dir
ZIG_GLOBAL_CACHE_DIR corresponding to --global-cache-dir
ZIG_LIB_DIR corresponding to --override-lib-dir

The main use case is for `zig cc` where we are bound by clang's CLI
options and need alternate channels to pass these configuration options.
2020-12-08 14:39:17 -07:00
antlilja
5c60558796 Utilize std.fmt.parseUnsigned in main.zig.
* Remove function parseAnyBaseInt.
* Replace calls to parseAnyBaseInt to calls to std.fmt.parseUnsigned
with radix 0.
* Replace calls to parseInt where the type is unsigned with calls to
parseUnsigned. Note that the functionality of these arguments haven't
changed, they still retain the original radix specified.
2020-12-07 16:38:52 -05:00
Jakub Konka
d3be499270 lld+macho: address review comments 2020-12-03 21:57:26 +01:00
Jakub Konka
3e2d1ccaad lld+macho: rename final artefact in main.zig 2020-12-02 00:03:07 +01:00
Andrew Kelley
9d1816111d build system: pass dyn lib artifacts as positionals 2020-11-30 18:12:00 -07:00
Alexandros Naskos
beb9d33d6d Disallow absolute paths passed as system libraries
Added OBJECT_NAME_INVALID handling in faccessatW
2020-11-30 18:08:27 -07:00
Andrew Kelley
ff9798eb26 rework the bundle compiler-rt feature
* it is now -fcompiler-rt and -fno-compiler-rt to override the (quite
   reasonable) default of bundling compiler-rt only for executables and
   dynamic libraries.
   - the build.zig API is still called bundle_compiler_rt however it is
     now an optional bool instead of a bool. leaving it as `null` means
     to use the compiler default.
 * renamed some internal identifiers to make the source more readable
 * additionally support -fcompiler-rt when doing build-obj for ELF files
   since that target already supports linking multiple objects into one.
   - includes an error message when attempting this for non-ELF. in the
     future this could additionally be supported with a more advanced
     implementation that does not rely on the linker.
 * properly populate the linker cache hash
2020-11-30 16:35:00 -07:00