43 Commits

Author SHA1 Message Date
Alexandros Naskos
52ba2c3a43 Reintroduce progress bar when compiling C files 2020-10-03 22:11:29 -04:00
Nathan Bourgeois
4566b27373 Patch in emit relocs support 2020-10-01 17:04:04 -04:00
Andrew Kelley
7bffa6f1fb clean up call to std.fs.rename
Thanks Ryan Liptak!
2020-09-29 21:47:37 -07:00
Andrew Kelley
1572cd4d76 different strategy to fix compiler_rt.zig and c.zig
with respect to std.builtin.link_libc.

The commit 27e008eb292038c5a6b9a13b64c7b69d1525f690 did not solve the
problem because although it got std.builtin.link_libc to be true for
compiler_rt.zig and c.zig, it had other unintentional side effects which
broke the build for -lc -target foo-linux-musl.

This commit introduces a new flag to Compilation to allow setting this
comptime flag to true without introducing other side effects to
compilation and linking.
2020-09-29 18:32:41 -07:00
Andrew Kelley
27e008eb29 fix not passing std.builtin.link_libc to compiler_rt.zig and c.zig
comment reproduced here:

This is so that compiler_rt and libc.zig libraries know whether they
will eventually be linked with libc. They make different decisions
about what to export depending on whether another libc will be linked
in. For example, compiler_rt will not export the __chkstk symbol if it
knows libc will provide it, and likewise c.zig will not export memcpy.
2020-09-29 17:24:21 -07:00
Andrew Kelley
f69650a478 update wasm to use ".o.wasm" extension for objects
This is convenient for debugging purposes, as well as simplifying the
caching system since executable basenames will not conflict with their
corresponding object files.
2020-09-29 17:01:05 -07:00
Andrew Kelley
0da7c4b0c8 improve stage2 COFF LLD linking
* change some {} to be {s} to gain type safety
 * fix libraries being libfoo.lib instead of foo.lib for COFF
 * when linking mingw-w64, add the "always link" libs so that we
   generate DLL import .lib files for them as the linker code relies on.
 * COFF LLD linker does not support -r so we do a file copy as an
   alternative to the -r thing that ELF linking does.
   I will file an issue for the corresponding TODO upon merging this
   branch, to look into an optimization that possibly elides this copy
   when the source and destination are both cache directories.
 * add a CLI error message when trying to link multiple objects into one
   and using COFF object format.
2020-09-29 14:48:12 -07:00
Andrew Kelley
3efdd7b2ad don't try to build musl crti.o crtn.o when it's not needed
such as on RISC-V
2020-09-29 01:30:35 -07:00
Andrew Kelley
d3a99c7bd5 add CLI options for darwin frameworks and -ffunction-sections
and add missing usage help text
2020-09-29 00:50:20 -07:00
Andrew Kelley
cfbcb41160 stage2: add CLI option for -fstack-report 2020-09-29 00:34:53 -07:00
Andrew Kelley
fa6d150441 stage2: MachO LLD Linking 2020-09-29 00:26:18 -07:00
Andrew Kelley
ed06a78f35 stage2: WASM LLD linking 2020-09-28 23:20:14 -07:00
Andrew Kelley
5fed42d70a the stage1 backend cache stores inferred link libs
So that we properly learn about extern "foo" functions called even when
we get a stage1 cache hit.
2020-09-28 20:55:52 -07:00
Andrew Kelley
ada19c498d stage2: building DLL import lib files 2020-09-28 19:20:58 -07:00
Andrew Kelley
412a2f966e store stage1 flags in a trailing byte in the hash id symlink
When we get a cache hit for a stage1 compilation, we need to know about
some of the flags such as have_winmain or have_dllmain to know which
subsystem to infer during linking.

To do this, we append a hex-encoded byte into the intentionally-dangling
symlink which contains the cache hash digest rather than a filename. The
hex-encoded byte contains the flags we need to infer the subsystem
during linking.
2020-09-28 15:42:09 -07:00
Andrew Kelley
91a73a177b stage2: building mingw-w64 and COFF LDD linking
still TODO is the task of creating import .lib files for DLLs on the fly
both for -lfoo and for e.g. `extern "kernel32"`
2020-09-28 00:06:06 -07:00
Andrew Kelley
a9082b4ec5 stage2: add CLI support for --subsystem 2020-09-26 22:37:19 -07:00
Andrew Kelley
b6556c944b fix another round of regressions in this branch
* std.log: still print error messages in ReleaseSmall builds.
   - when start code gets an error code from main, it uses std.log.err
     to report the error. this resulted in a test failure because
     ReleaseSmall wasn't printing `error: TheErrorCode` when an error
     was returned from main. But that seems like it should keep working.
     So I changed the std.log defaults. I plan to follow this up with a
     proposal to change the names of and reduce the quantity of the
     log levels.
 * warning emitted when using -femit-h when using stage1 backend; fatal
   log message when using -femit-h with self-hosted backend (because the
   feature is not yet available)
 * fix double `test-cli` build steps in zig's build.zig
 * update docgen to use new CLI
 * translate-c uses `-x c` and generates a temporary basename with a
   `.h` extension. Otherwise clang reports an error.
 * --show-builtin implies -fno-emit-bin
 * restore the compile error for using an extern "c" function without
   putting -lc on the build line. we have to know about the libc
   dependency up front.
 * Fix ReleaseFast and ReleaseSmall getting swapped when passing the
   value to the stage1 backend.
 * correct the zig0 CLI usage text.
 * update test harness code to the new CLI.
2020-09-26 21:03:38 -07:00
Andrew Kelley
fe4c348f57 stage2: zig translate-c supports --enable-cache
This matches master branch behavior and makes the test-translate-c tests
pass.
2020-09-26 16:48:02 -07:00
Andrew Kelley
26f2f9bf1c stage2: implement -fno-emit-bin
we are now passing the cli tests
2020-09-26 12:42:07 -07:00
Andrew Kelley
1337f0bc6a move to stage1-specific cache manifest emission of extra stuff 2020-09-26 02:34:18 -07:00
Andrew Kelley
819625d274 fix logic for choosing when dynamic linking is required
When building object files or static libraries, link_mode can still be
static even if the OS needs libc for syscalls.
2020-09-26 01:58:16 -07:00
Andrew Kelley
6af2990549 implement -femit-asm, -femit-docs, -femit-llvm-ir, etc
These CLI options are now forwarded to the stage1 backend.

We're not going to support the -mllvm CLI option any longer. As a
compromise, we unconditionally tell LLVM to output intel x86 syntax when
using -femit-asm.

Simplify stage1 logic; it no longer has the concept of an output
directory. --output-dir is no longer a valid CLI option. cmake uses
the `-femit-bin=[path]` option.

Note the changes to test/cli.zig. This breaks the CLI API that Godbolt
is using so we're going to want to open a PR to help them upgrade to the
new CLI for the upcoming Zig 0.7.0 release.
2020-09-26 01:47:27 -07:00
Andrew Kelley
a337046832 stage2: properly handle zig cc used as a preprocessor
This cleans up how the CLI parses and handles -E, -S, and -c.
Compilation explicitly acknowledges when it is being used to do C
preprocessing.

-S is properly translated to -fno-emit-bin -femit-asm but Compilation
does not yet handle -femit-asm.

There is not yet a mechanism for skipping the linking step when there is
only a single object file, and so to make this work we have to do a file
copy in link.flush() to copy the file from zig-cache into the output
directory.
2020-09-25 20:52:02 -07:00
Andrew Kelley
70d7d7e919 stage2: disable lld caching when output dir is owned by user
Normally when using LLD to link, Zig uses a file named "lld.id" in the
same directory as the output binary which contains the hash of the link
operation, allowing Zig to skip linking when the hash would be unchanged.
In the case that the output binary is being emitted into a directory which
is externally modified - essentially anything other than zig-cache - then
this flag would be set to disable this machinery to avoid false positives.

 * Better defaults when using -fno-LLVM
 * Fix compiler_rt and libc static libraries were getting a .zig
   extension instead of .a extension.
 * when using the stage1 backend, put the object file next to the
   stage1.id file in the cache directory. this prevents an object file
   from polluting the cwd when using zig from the CLI.
2020-09-25 18:01:35 -07:00
Andrew Kelley
670e7d456c add some tracy calls 2020-09-25 14:47:09 -07:00
Andrew Kelley
30dfdfdbd0 fix a round of regressions in this branch
* Don't try to generate C header files yet since it will only cause a
   crash saying the feature is unimplemented.
 * Rename the CLI options for release modes to use the `-O` prefix to
   match C compiler precedent. Options are now `-ODebug`,
   `-OReleaseFast`, `-OReleaseSafe`, `-OReleaseSmall`. The optimization
   mode matches the enum tags of std.builtin.Mode. It is planned to, at
   some point, rename std.builtin.Mode to std.builtin.OptimizationMode
   and modify the tags to be lower case to match the style convention.
   - Update build.zig code to support this new CLI.
 * update std.zig.binNameAlloc to support an optional Version and update
   the implementation to correctly deal with dynamic library version
   suffixes.
2020-09-24 23:50:15 -07:00
Andrew Kelley
67463c4357 correct @cImport caching to handle "unhit" case
if you hit() you have to unhit() to get the same digest if you don't
end up treating it as a hit.
2020-09-24 21:52:37 -07:00
Andrew Kelley
4f0850fe28 don't delete C import .c source from zig-cache
preventing CacheUnavailable error when doing `@cImport`
2020-09-24 21:13:01 -07:00
Andrew Kelley
054fafd7d9 stage2: implement @cImport
Also rename Cache.CacheHash to Cache.Manifest
2020-09-24 16:22:45 -07:00
Andrew Kelley
b08fd0e8fc stage2: building musl libc from source 2020-09-23 20:48:47 -07:00
Andrew Kelley
b183b612c9 stage2: don't build libunwind on OS's that don't need it 2020-09-23 11:15:27 -07:00
Andrew Kelley
02886a8b93 stage2: support rpaths 2020-09-23 11:01:15 -07:00
Andrew Kelley
d03fcc73fc stage2: implement --main-pkg-path 2020-09-23 09:56:30 -07:00
Andrew Kelley
15b2bae517 fix trying to link libc for static libs and objects 2020-09-23 09:41:55 -07:00
Andrew Kelley
fc88d36dae stage2: link_libc=true on OS's that require it for syscalls 2020-09-22 23:31:32 -07:00
Andrew Kelley
c2b1cd7c45 stage2: implement zig build
As part of this:

 * add std.process.cleanExit. closes #6395
   - use it in several places
 * adjust the alignment of text in `zig build --help` menu
 * Cache: support the concept of "unhit" so that we properly keep track
   of the cache when we find out using the secondary hash that the cache
   "hit" was actually a miss. Use this to fix false negatives of caching
   of stage1 build artifacts.
 * fix not deleting the symlink hash for stage1 build artifacts causing
   false positives.
 * implement support for Package arguments in stage1 build artifacts
 * update and add missing usage text
 * add --override-lib-dir and --enable-cache CLI options
   - `--enable-cache` takes the place of `--cache on`
 * CLI supports -femit-bin=foo combined with --enable-cache to do an
   "update file" operation. --enable-cache without that argument
   will build the output into a cache directory and then print the path
   to stdout (matching master branch behavior).
 * errors surfacing from main() now print "error: Foo" instead of
   "error: error.Foo".
2020-09-22 22:18:19 -07:00
Andrew Kelley
dacd36ca9b stage2: implement using the global cache dir 2020-09-22 14:08:08 -07:00
Andrew Kelley
877e4248fc stage2: implement building & linking against libcxx and libcxxabi 2020-09-21 22:38:45 -07:00
Andrew Kelley
974333faaf stage2: fix linking libc trying to depend on itself 2020-09-21 21:42:27 -07:00
Andrew Kelley
afac5d2895 fix regressed stage2 test harness 2020-09-21 21:14:01 -07:00
Andrew Kelley
ead50ea665 stage2: implement zig run and zig test 2020-09-21 21:01:04 -07:00
Andrew Kelley
528832bd3a rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -07:00