10520 Commits

Author SHA1 Message Date
Andrew Kelley
dc79651e6a stage2: add CLI for zig translate-c 2020-09-18 01:33:32 -07:00
Andrew Kelley
a9b18023a4 stage2: implement --show-builtin
This takes the place of `zig builtin`. This is an improvement over the
command because now the generated source will correctly show LinkMode
and OutputMode, whereas before it was always stuck as Static and Obj,
respectively.
2020-09-17 23:27:24 -07:00
Andrew Kelley
dc478687d9 delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
 * an implementation of blake hashing
 * the cache hash system
 * compiler.cpp
 * all the linking code, and everything having to do with building
   glibc, musl, and mingw-w64
 * much of the stage1 compiler internals got slimmed down since it
   now assumes it is always outputting an object file.

More stuff:
 * stage1 is now built with a different strategy: we have a tiny
   zig0.cpp which is a slimmed down version of what stage1 main.cpp used
   to be. Its only purpose is to build stage2 zig code into an object
   file, which is then linked by the host build system (cmake) into
   stage1. zig0.cpp uses the same C API that stage2 now has access to,
   so that stage2 zig code can call into stage1 c++ code.
   - stage1.h is
   - stage2.h is
   - stage1.zig is the main entry point for the Zig/C++
     hybrid compiler. It has the functions exported from Zig, called
     in C++, and bindings for the functions exported from C++, called
     from Zig.
 * removed the memory profiling instrumentation from stage1.
   Abandon ship!
 * Re-added the sections to the README about how to build stage2 and
   stage3.
 * stage2 now knows as a comptime boolean whether it is being compiled
   as part of stage1 or as stage2.
   - TODO use this flag to call into stage1 for compiling zig code.
 * introduce -fdll-export-fns and -fno-dll-export-fns and clarify
   its relationship to link_mode (static/dynamic)
 * implement depending on LLVM to detect native target cpu features when
   LLVM extensions are enabled and zig lacks CPU feature detection for
   that target architecture.
 * C importing is broken, will need some stage2 support to function
   again.
2020-09-17 18:29:38 -07:00
Andrew Kelley
bc01887376 stage2: verify -Wl zig cc behavior 2020-09-16 20:28:51 -07:00
Andrew Kelley
01a7affb87 stage2: ask for a higher open fd limit
Here's the doc comment from the commit:

For one example of why this is handy, consider the case of building musl libc.
We keep a lock open for each of the object files in the form of a file descriptor
until they are finally put into an archive file. This is to allow a zig-cache
garbage collector to run concurrently to zig processes, and to allow multiple
zig processes to run concurrently with each other, without clobbering each other.

This code is disabled until #6361 is implemented (getrlimit/setrlimit
are not yet added to the standard library).
2020-09-16 20:18:06 -07:00
Andrew Kelley
07eb2c65f6 stage2: don't add unused args to assembly compilations 2020-09-16 19:24:09 -07:00
Andrew Kelley
17d40ecb49 stage2: building libunwind.a
and put glibc shared objects on the elf linker line
2020-09-16 17:18:13 -07:00
Andrew Kelley
17f094ec5b stage2: build glibc shared objects using assembly files
closes #6358
2020-09-16 14:33:13 -07:00
Andrew Kelley
3256b3c485 stage2: glibc shared objects use ok file to detect cache hits 2020-09-16 13:41:53 -07:00
Andrew Kelley
670260aab6 stage2: std.log.err is an error not a warning 2020-09-16 13:41:28 -07:00
Andrew Kelley
883dcb8b18 stage2 Cache: use hex instead of base64 for file paths 2020-09-16 12:31:42 -07:00
Andrew Kelley
a863d899e1 ci: undo mangled autocrlf files before building 2020-09-16 11:58:26 -07:00
Andrew Kelley
80d8515e3a ci: disable git autocrlf
See also commit
2c8495b4bb261d440bc6d1a6b0415a64c8d99222
2020-09-16 10:49:43 -07:00
Andrew Kelley
95941c4e70 stage2: building glibc shared objects
* caching system: use 16 bytes siphash final(), there was a bug in the
   std lib that wasn't catching undefined values for 18 bytes. fixed in
   master branch.
 * fix caching system unit test logic to not cause error.TextBusy on windows
 * port the logic from stage1 for building glibc shared objects
 * add is_native_os to the base cache hash
 * fix incorrectly freeing crt_files key (which is always a reference to
   global static constant data)
 * fix 2 use-after-free in loading glibc metadata
 * fix memory leak in buildCRTFile (errdefer instead of defer on arena)
2020-09-16 03:02:46 -07:00
Andrew Kelley
da0fde59b6 stage2: update to new LibCInstallation API 2020-09-15 18:08:52 -07:00
Andrew Kelley
16bd0c63b4 Merge remote-tracking branch 'origin/master' into stage2-zig-cc
Pulling in the changes to libc_installation.zig
2020-09-15 18:04:37 -07:00
Andrew Kelley
99a2fc2cde stage2: implement .d file parsing for C objects 2020-09-15 18:02:42 -07:00
Andrew Kelley
a0b43ff3b3 stage2: eliminate one failure path in building c object 2020-09-15 15:24:34 -07:00
Andrew Kelley
f82b1831f7 std: handle sharing violation when deleting a file on windows 2020-09-15 15:24:13 -07:00
Andrew Kelley
7ccfb08a93 ci: update the on_master_success secret to lavatech 2020-09-15 15:08:35 -07:00
Samrat Man Singh
ca85e367f4 Use std.log in LibcInstallation parse instead of taking stderr 2020-09-15 18:03:55 -04:00
Andrew Kelley
c803d334d0 update the zen of zig 2020-09-15 13:40:01 -07:00
Andrew Kelley
b2860aa3e4 stage2: add missing import to libc_installation.zig 2020-09-15 12:52:58 -07:00
Andrew Kelley
b3cc36857e
Merge pull request #6340 from Vexu/fix
Fixes
2020-09-15 14:28:16 -04:00
LemonBoy
c1c3212500 std: Fix typo in ELF section header iterator
The code accidentally used the phdr offset instead of the shdr one while
iterating over the section headers.

Fixes #6338
2020-09-15 18:14:06 +03:00
Andrew Kelley
1da9e0fcaf stage2: building glibc libc_nonshared.a CRT file 2020-09-15 00:41:02 -07:00
Andrew Kelley
4fa8cc7369 stage2: don't depend on windows SDK C++ code when unavailable 2020-09-15 00:40:33 -07:00
Andrew Kelley
6e9396e32b integrate target features into building assembly code
This brings us up to par from what stage1 does. There will still be an
open issue for completing this.
2020-09-14 23:03:13 -07:00
Andrew Kelley
1ad60c4386 integrate target features into building C source files 2020-09-14 22:57:08 -07:00
Andrew Kelley
5d8fec3d4c Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-14 21:57:01 -07:00
Andrew Kelley
6acd903a95 stage2: support for machine code model CLI 2020-09-14 21:22:11 -07:00
Andrew Kelley
5e39ab4600 ci: disable some freebsd tests to save time 2020-09-14 21:11:34 -07:00
Andrew Kelley
0e94530c51 stage2: refactor 2 CObject fields to use CSourceFile 2020-09-14 19:52:36 -07:00
Andrew Kelley
29d9743f9d Revert "disable sourcehut freebsd CI checks"
This reverts commit 40cb712d13aff4bfe83256858ad6b18d82e70211.

Thanks to Ava & Luna of Lavatech, we don't need to resort to this, they
have graciously given zig a SourceHut instance to use that gives us 8GB
RAM.
2020-09-14 19:43:26 -07:00
Andrew Kelley
a8ae324130 Merge branch 'ci-freebsd'
Thanks to Ave & Luna for providing this service that lets us have enough
ram to properly test FreeBSD.
2020-09-14 19:38:36 -07:00
Andrew Kelley
44ef270de1 ci: use hut.lavatech.top for updating the download page 2020-09-14 19:37:59 -07:00
Andrew Kelley
558e22b2d0 ci: update freebsd to use hut.lavatech.top instead of sr.ht 2020-09-14 18:45:30 -07:00
Andrew Kelley
01c24c4509 ci: enable std lib tests for freebsd 2020-09-14 18:22:16 -07:00
Andrew Kelley
dffdb2844e track all TODO comments in BRANCH_TODO file
Before merging, do this for every item in the file:
 * solve the issue, or
 * convert the task to a github issue and update the comment
   to link to the issue (and remove "TODO" text from the comment).
Then delete the file.

Related: #363
2020-09-14 18:06:19 -07:00
Andrew Kelley
26798018b7 stage2: implement writing archive files 2020-09-14 15:28:09 -07:00
Vexu
a3624e94f8
translate-c: determine sizeof using std.meta.sizeof 2020-09-14 23:53:38 +03:00
Vexu
29fd0c6d61
fix meta.cast behavior; add exhaustive tests 2020-09-14 23:21:26 +03:00
Andrew Kelley
40cb712d13 disable sourcehut freebsd CI checks
Drew won't give us enough RAM for stage1 to build stage2. We'll still
have freebsd builds available on releases but we're going to lose
freebsd CI testing for master branch builds until we fully switch over
to stage2 (and have lower memory usage).

Let me know if anyone wants to run a SourceHut instance and give zig
access to run on slightly more powerful machines. We need about 8 GiB
RAM to run the CI test suite for now.

After we're fully self hosted I expect to re-enable this.
2020-09-14 11:10:38 -07:00
Andrew Kelley
778bb4bc9c move std.cache_hash from std to stage2
The API is pretty specific to the implementationt details of the
self-hosted compiler. I don't want to have to independently support
and maintain this as part of the standard library, and be obligated
to not make breaking changes to it with changes to the implementation of
stage2.
2020-09-14 11:05:51 -07:00
Andrew Kelley
04f6a26955 fix stage1 regressions in this branch
also prepare for supporting linking into archives
2020-09-14 10:42:29 -07:00
Andrew Kelley
c58e9951ef revert bogus enum keywords in zig_llvm.h 2020-09-14 10:31:34 -07:00
Veikka Tuominen
d073836894
Merge pull request #6172 from tadeokondrak/@Type(.Union)
Implement @Type for Union
2020-09-14 16:43:49 +03:00
Andrew Kelley
c49435f76b
Merge pull request #6331 from mattnite/bpf-helper-defs
BPF: helper definitions
2020-09-14 04:00:00 -04:00
Andrew Kelley
f2e380380e stage2: building glibc Scrt1.o 2020-09-14 00:24:03 -07:00
Andrew Kelley
060c91b97f stage2: namespace cache dir with C source path
This is not strictly necessary but it increases the likelihood of cache
hits because foo.c and bar.c now will have different cache directories
and can be updated independently without clobbering each other's cache
data.
2020-09-13 23:28:28 -07:00