Commit Graph

4206 Commits (a337046832b936d912b6902e331cb58bdc513a2d)

Author SHA1 Message Date
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 812e482bef ELF linking supports root src directory to be cwd 2020-09-25 13:37:10 -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 5440ca8eb7 --main-pkg-path properly resolves the relative root src file path 2020-09-24 22:15:40 -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 1123c90987 stage2: print the test command after it fails 2020-09-23 23:13:18 -07:00
Andrew Kelley 7bbd152dcc nobody likes my std.process.cleanExit idea
it's appropriate for the self-hosted compiler though, so this commit
moves it from std lib to stage2 src code.
2020-09-23 20:52:33 -07:00
Andrew Kelley b08fd0e8fc stage2: building musl libc from source 2020-09-23 20:48:47 -07:00
Andrew Kelley 64deb46859 stage2: capture LLD stderr into a buffer 2020-09-23 15:21:40 -07:00
Andrew Kelley 90b320d0e9 use ascii range for the --watch REPL prompt 2020-09-23 14:50:52 -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 c0b774fbc6 stage2: support passing extra C flags to C source files
closes #3508
2020-09-23 10:22:44 -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 800a4a6ceb eliminate dependency of libzigcpp.a on libzigstage1.a
This allows us to create a build of self-hosted with LLVM extensions
enabled but without the stage1 backend.
2020-09-23 00:00:24 -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 0638a020cf stage2: implement --pkg-begin and --pkg-end CLI args 2020-09-22 23:00:33 -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 bf9a16a037 stage2: implement `zig init-lib` and `zig init-exe` 2020-09-21 23:28:34 -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 0c70bb4fce Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-21 21:16:46 -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
Andrew Kelley b9f61d4015 stage1: resolve builtin.zig path when bootstrapping 2020-09-21 18:26:24 -07:00
Andrew Kelley 2ef68631cb stage2 now supports using stage1 as a backend for compiling zig code
* move stage2.cpp code into zig0.cpp for simplicity
 * add -ftime-report and some more CLI options to stage2
 * stage2 compites the llvm cpu features string
 * classifyFileExt understands more file extensions
 * correction to generateBuiltinZigSource using the wrong allocator
   (thanks dbandstra!)
 * stage2 is now able to build hello.zig into hello.o using stage1 as a
   library however it fails linking due to missing compiler-rt
 * remove dead code
 * simplify zig0 builtin.zig source
 * fix not resolving builtin.zig source path causing duplicate imports
 * fix stage1.h not being valid C code
 * fix stage2.h not being valid C code
2020-09-18 22:48:28 -07:00
LemonBoy f92d01c8a8 stage1: Fix edge case in casting between optional types
Closes #6370
2020-09-18 22:12:22 -04: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
Tadeo Kondrak 2962be8135 stage1: fix @Type(.Union) not resolving its tag type
Fixes https://github.com/ziglang/zig/issues/6339
2020-09-16 20:34:01 +03:00
Andrew Kelley 5d8fec3d4c Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-14 21:57:01 -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 af4cc20ce2 Merge remote-tracking branch 'origin/master' into stage2-zig-cc
Master branch added in the concept of library versioning being optional
to main.cpp. It will need to be re-added into this branch before merging
back into master.
2020-09-12 10:48:38 -07:00
Andrew Kelley c903dad915 fix zig_llvm.h not complying with C 2020-09-12 00:50:17 -07:00
Isaac Freund 0a76a9bd73
std, stage1: make shared library versioning optional
This commit changes the behavior of stage1 to emit libfoo.so instead
of libfoo.so.0.0.0 when none of the --ver-major, --ver-minor, or
--ver-patch flags are set.

It also makes it possible to create unversioned shared libraries
using the zig build system, changing the version parameter of
addSharedLibrary() to a tagged union.
2020-09-11 10:46:37 +02:00
Andrew Kelley 98583be6e1 stage1: fix crash with slice type 2020-09-10 22:22:42 -07:00
Andrew Kelley 2315331d23
Merge pull request #5527 from shawnanastasio/ppc64le
Implement support for powerpc64{,le}
2020-09-10 15:56:27 -04:00
Andrew Kelley 5746a8658e stage1: link: fix incorrect LDM option for mips64 2020-09-09 22:23:59 -07:00
Andrew Kelley 193ad413f0 stage2: compiling C objects with clang
* add target_util.zig which has ported code from src/target.cpp
 * Module gains an arena that owns memory used during initialization
   that has the same lifetime as the Module. Useful for constructing
   file paths and lists of strings that have mixed lifetimes.
   - The Module memory itself is allocated in this arena. init/deinit
     are modified to be create/destroy.
   - root_name moves to the arena and no longer needs manual free
 * implement the ability to invoke `zig clang` as a subprocess
   - there are lots of TODOs that should be solved before merging
 * Module now requires a Random object and zig_lib_dir
 * Module now requires a path to its own executable or any zig
   executable that can do `zig clang`.
 * Wire up more CLI options.
 * Module creates "zig-cache" directory and "tmp" and "o" subdirectories
   ("h" is created by the cache_hash)
 * stubbed out some of the things linker code needs to do with TODO
   prints
 * delete dead code for computing compiler id. the previous commit
   eliminated the need for it.
 * add `zig translate-c` CLI option but it's not fully hooked up yet.
   It should be possible for this to be fully wired up before merging
   this branch.
 * `zig targets` now uses canonical data for available_libcs
2020-09-09 09:28:05 -07:00
Andrew Kelley 503ba7b27c start moving `zig cc` to stage2
* build.zig: repair the ability to link against llvm, clang, and lld
 * move the zig cc arg parsing logic to stage2
   - the preprocessor flag is still TODO
   - the clang arg iterator code is improved to use slices instead of
     raw pointers because it no longer has to deal with an extern
     struct.
 * clean up error printing with a `fatal` function and use log API
   for messages rather than std.debug.print
 * add support for more CLI options to stage2 & update usage text
   - hooking up most of these new options is TODO
 * clean up the way libc and libc++ are detected via command line
   options. target information is used to determine if any of the libc
   candidate names are chosen.
 * add native library directory detection
 * implement the ability to invoke clang from stage2
 * introduce a build_options.have_llvm so we can comptime branch
   on whether LLVM is linked in or not.
2020-09-09 09:28:05 -07:00
Tadeo Kondrak acdf1f0bde
@Type for union fixes 2020-09-07 06:23:50 -06:00