90 Commits

Author SHA1 Message Date
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
Alexandros Naskos
2fae28b6af Added bundle-compiler-rt flag 2020-11-30 14:31:41 -07:00
Andrew Kelley
3fb0cc0a14 CLI: add missing usage help text 2020-11-29 16:32:24 -07:00
Andrew Kelley
c3b0182f31 restore sonames by default when using zig cli
Before this commit, the branch regressed this case:

zig build-lib foo.zig -dynamic
readelf -d libfoo.so
 x000000000000000e (SONAME) Library soname: [libfoo.so]

Now it works again, but it preserves the property that using `zig cc`
has the SONAME off by default to match C compilers.
2020-11-27 17:49:55 -07:00
Jakub Konka
375bab8460 stage2 elf: refactor override_soname to soname 2020-11-27 15:42:39 -07:00
Jakub Konka
7e8f7da3ec stage2 macho: rename inodes to prevent SIGKILL 2020-11-26 11:50:09 +01:00
Andrew Kelley
abc717f203 modernize the PIE patch for the latest master branch
This is the part of #3960 that has to be rewritten to apply to latest
master branch code.
2020-11-22 17:28:11 -07:00
LemonBoy
8eaaa905f7
stage2: Make zig cc more verbose (#7166)
* stage2: Make zig cc more verbose

Make `zig cc` print more info from Clang itself and from our own linker
invocation, this is needed for CMake to properly discover all the
include directories and library search paths.

Closes #7110

* Update `update_clang_options`

* Typo fixes

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-19 23:30:16 +01:00
Andrew Kelley
13cccdd92c add std.heap.raw_c_allocator
This API does what `std.heap.c_allocator` previously did. See the new
doc comments for more details.
2020-11-18 22:09:34 -07:00
Vexu
da84ef2a9c
make help in commands more consistent
Closes #7101

Co-authored-by: pfg <pfg@pfg.pw>
2020-11-18 13:58:27 +02:00
Veikka Tuominen
6d5b76a75d
Merge pull request #7005 from jshholland/deprecate-span
Remove ArrayList.span
2020-11-18 13:14:48 +02:00
Andrew Kelley
af4727814b cli: make -h, --help consistent in usage text and parsing
also trivial fixes in the general usage text
2020-11-17 16:53:45 -07:00
Alexandros Naskos
21a77f7ac3
Merge pull request #7032 from GuoxinYin/master
Add -h alias for --help
2020-11-17 15:52:39 +02:00
Andrew Kelley
2d42532fec main: clean up the error message for missing positional args 2020-11-11 19:35:07 -07:00
g-w1
61c51f0ac9
Add error for missing positional arguments in zig build-*
Closes #6938
2020-11-11 15:54:08 +02:00
Andrew Kelley
06a3a69e6f main: updateModule returns an error when there are any compile errors
closes #6976
2020-11-09 20:51:09 -07:00
Guoxin Yin
7b8cb002cb fix issue 6798 2020-11-09 02:58:45 +08:00
Guoxin Yin
b6c85df55a fix issue 6798 2020-11-09 02:48:17 +08:00
Josh Holland
c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
xackus
e023a5fe5d force comptime on isDarwin 2020-11-03 00:58:35 +01:00
Jakub Konka
8dda64fa3e
Fix Darwin codepath
On Darwin, according to the man pages for setrlimit(), when adjusting
max number of open fds, the reported hard max by getrlimit() is only
theoretical, while the actual maximum, set in the kernel, is hardcoded
in the header file. Therefore, the reported max has to be adjusted
as `min(OPEN_MAX, lim.max)`.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-03 00:38:43 +01:00
xackus
06b4526a3e fix freebsd compilation 2020-11-02 23:18:55 +01:00
xackus
7703f4c60a stage2: ask for more file descriptors 2020-11-01 23:32:25 +01:00
Vexu
4ed2c52fb7
stage2: switch put swap condbr and block
condbr is noreturn so having the other way around caused
subsequent cases to be eliminated as dead
2020-10-30 15:58:13 +02:00
Isaac Freund
0e4c3934a0 zig fmt: write modified files to stdout not stderr 2020-10-16 20:23:18 -04:00
Andrew Kelley
8364417c8f trivial refactor to remove redundant function call 2020-10-16 16:15:50 -07:00
Jakub Konka
abd72781a3 Allow linking with dynamic libraries in main CLI 2020-10-16 19:14:42 -04:00
Andrew Kelley
09a250c531 adjust error message of zig run with no args
previously it said "one source file" which was not correct
2020-10-15 17:44:10 -07:00
g-w1
dfce396cf8 friendly error message for zig run with no args 2020-10-15 17:43:44 -07:00
Andrew Kelley
43c2ce10a1 fixups
* extract logic into a `os_can_execve` and use it in the other place
   that we execve
 * outdent some code by introducing `run_or_test` variable
 * delete unnecessary and wasteful memory management logic
 * better error message for when execve fails
 * add comment to explain why we do not execve for `zig test`
2020-10-15 17:18:40 -07:00
g-w1
1c36680928 stage2: use execve where available for zig test and zig run
closes #6531
2020-10-15 16:54:50 -07:00
Andrew Kelley
2f52f95b92
Merge pull request #6669 from ifreund/color-fixes
std/build: support --color
2020-10-14 21:35:43 -04:00
Andrew Kelley
816304e7e1 add .tbd to usage text 2020-10-14 18:22:50 -07:00
Andrew Kelley
0f4386875f stage2: support ZIG_LIBC env var and detect self as system C compiler 2020-10-14 02:05:56 -07:00
Isaac Freund
6ba1fdf7e0
stage2: use meta.stringToEnum for Color parsing
This requires renaming the variants to be snake_case, which is the new
recommended style anyways.
2020-10-13 20:17:30 +02:00
xavier
eb33394d14 notice more kinds of optimization flags and debug flags
Closes #6091
2020-10-07 18:43:05 -04:00