Commit Graph

175 Commits (3c7a49c4947b748c04e314dc89f2ce56562da29c)

Author SHA1 Message Date
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 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 528832bd3a rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -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 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 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
LemonBoy 9fe4c89230 std: Add a gzip decoder 2020-09-11 20:02:41 -04:00
Andrew Kelley c99e34a00e stage2: eliminate the "compiler id" concept
Instead, append a "dirty suffix" to the version string when there are
dirty git changes and use the version string as the compiler id.

This avoids a dependency on the cache hash system, and saves time on
first invocation of the compiler since it does not have to compute its
compiler id. It also saves time by not having to check the cache for a
saved compiler id.
2020-09-09 09:28:05 -07:00
Andrew Kelley 4056bb92e6 stage2: more progress moving `zig cc` to stage2
* std.cache_hash exposes Hasher type
 * std.cache_hash makes hasher_init a global const
 * std.cache_hash supports cloning so that clones can share the same
   open manifest dir handle as well as fork from shared hasher state
 * start to populate the cache_hash for stage2 builds
 * remove a footgun from std.cache_hash add function
 * get rid of std.Target.ObjectFormat.unknown
 * rework stage2 logic for resolving output artifact names by adding
   object_format as an optional parameter to std.zig.binNameAlloc
 * support -Denable-llvm in stage2 tests
 * Module supports the use case when there are no .zig files
 * introduce c_object_table and failed_c_objects to Module
 * propagate many new kinds of data from CLI into Module and into
   linker.Options
 * introduce -fLLVM, -fLLD, -fClang and their -fno- counterparts.
   closes #6251.
   - add logic for choosing when to use LLD or zig's self-hosted linker
 * stub code for implementing invoking Clang to build C objects
 * add -femit-h, -femit-h=foo, and -fno-emit-h CLI options
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
Andrew Kelley c15f39212e build.zig: ignore the compression test files 2020-09-07 15:15:48 -07:00
Andrew Kelley 26140678a5 ci: skip compile error tests on Windows
We're up against the 6 hour limit so this is a time-saving workaround.
Compile error tests are generally not OS-specific so the coverage from
the other platforms should be sufficient.
2020-08-31 14:54:05 -07:00
Andrew Kelley 237d9a105d stage2: support debug dumping zir as a build option
So that it's not needed to manually comment and uncomment the debug
code.
2020-08-25 22:44:18 -07:00
Andrew Kelley 1a4059ed88 allow running the stage2 tests in release mode 2020-08-20 13:16:04 -07:00
Andrew Kelley 5547abd2d1 build: -Dforce-link-libc now also applies to test-stage2 2020-08-18 15:08:43 -07:00
Andrew Kelley 8d8d568854 stage2: implement zig version 2020-08-15 20:04:08 -04:00
Andrew Kelley f23fb3087b zig build: fix addBuildOption for `[]const u8` and `?[]const u8` 2020-08-04 22:55:45 -07:00
Andrew Kelley c594f8dc26 stage2 tests: support the -Denable-qemu options and friends 2020-08-04 15:32:16 -07:00
Andrew Kelley edfede575c self-hosted: add build option for log scopes
Now you can enable a set of log scopes by passing -Dlog=<scope>
2020-08-03 21:56:21 -07:00
Vexu c29c79b17a
stage2: remove some dead code, fix build on aarch64 2020-07-21 22:34:14 +03:00
Vexu e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
pfg 65aac13257 don't try to find config_h if it's not needed 2020-07-04 12:50:37 +00:00
Andrew Kelley f69875d85c build: -Dlib-files-only prevents self-hosted compiler from being built
closes #5756
2020-07-01 21:57:04 +00:00
Andrew Kelley 6938245fcc Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-22 23:22:17 -04:00
Ryan Liptak b5f90244a4 temporary: Add test-cli step for only running cli tests 2020-06-20 22:02:56 -07:00
Andrew Kelley c9a0ec25e0 self-hosted: add Tracy integration
This tool helps give an intuitive picture of performance. This will help
us understand where to improve the code.
2020-06-18 21:55:37 -04:00
Jakub Konka 34f84c3608 Narrow down behaviour test cases; this removes wasmtime-enabled check in tests 2020-05-18 17:56:17 +02:00
Jakub Konka 40812063cc Disable tests requiring Wasmtime be default; require -Denable-wasmtime flag otherwise 2020-05-18 16:12:03 +02:00
Jakub Konka d43c08a3e5 Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.

Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.

The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
  to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
  in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
  fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-18 16:09:49 +02:00
Andrew Kelley a286b5de38 build.zig: -Dlib-files-only skips installing self-hosted 2020-05-16 01:22:56 -04:00
Andrew Kelley e1d4b59c5b self-hosted: update main.zig
After this commit there are no more bit rotted files.
The testing program that was in ir.zig has been moved to main.zig
Unsupported command line options have been deleted, or error messages
added.

The compiler repl is available from the build-exe, build-lib,
build-obj commands with the --watch option.

The main zig build script now builds the self-hosted compiler
unconditionally. Linking against LLVM is behind a -Denable-llvm
flag that defaults to off.
2020-05-15 15:20:42 -04:00
Andrew Kelley 2bae942800 add ZIR compare output test case to test suite 2020-05-01 06:47:20 -04:00
xackus dbc00e2424 ArrayList: remove old (before span) API 2020-04-11 20:40:34 -04:00
Vexu ff0f97a1bc
fix missing compile error on assign to slice and array parameters 2020-04-08 00:27:14 +03:00
Andrew Kelley afa24ccd99 fix the build on Windows
Workaround for issue #2668

Zig std lib currently does not allow forward slashes in Windows path
names.
2020-04-06 18:35:49 -04:00
Andrew Kelley 96ed544665
build.zig supports specifying config.h location explicitly
also it does not try to run llvm-config executable when -Dlib-files-only

This fixes cross-compiling using the bootstrap repository.
2020-04-06 13:07:19 -04:00
xackus cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
Andrew Kelley dc7e8b2fdc
build.zig: better detection of using outside zig executable
As pointed out by gereeter, dirname("/") successfully returns "/" again.
So checking for null is not sufficient.
2020-04-04 14:05:49 -04:00
Andrew Kelley d73808f3ff
remove `zig BUILD_INFO` hack
Rather than stuffing configuration information into the Zig binary, the
build script reads it from config.h. This solves a problem for package
maintainers and improves the use case of deterministic builds.

closes #3758
2020-04-04 11:57:28 -04:00
Andrew Kelley 23c263776c
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 15:09:29 -04:00
Andrew Kelley 3a2c490889 "generate .h files" feature is no longer supported in stage1 2020-03-20 18:33:36 -04:00
Andrew Kelley 53b5aa812b
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-19 22:19:24 -04:00
Andrew Kelley dbde5df568
clean up some self-hosted bitrot + don't assume libstdc++
closes #4682

The self-hosted compiler is still bit rotted and still not compiling
successfully yet. I have a more serious rework of the code in a
different branch.
2020-03-17 23:03:45 -04:00
Andrew Kelley 96c07674fc
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00
daurnimator 1cbf352cfb
Remove unused std.Buffer imports 2020-03-06 18:49:13 -05:00
Andrew Kelley d1cb16aace
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-03 09:44:13 -05:00
Andrew Kelley 3418a332ab
Revert "work around LLVM 10 llvm-config giving absolute path to libz.so"
This reverts commit 73256dda91.

No longer needed with latest release/10.x branch.
2020-03-03 09:17:37 -05:00
Andrew Kelley dbe4d72bcf
separate std.Target and std.zig.CrossTarget
Zig now supports a more fine-grained sense of what is native and what is
not. Some examples:

This is now allowed:
-target native

Different OS but native CPU, default Windows C ABI:
-target native-windows
This could be useful for example when running in Wine.

Different CPU but native OS, native C ABI.
-target x86_64-native -mcpu=skylake

Different C ABI but otherwise native target:
-target native-native-musl
-target native-native-gnu

Lots of breaking changes to related std lib APIs.
Calls to getOs() will need to be changed to getOsTag().
Calls to getArch() will need to be changed to getCpuArch().

Usage of Target.Cross and Target.Native need to be updated to use
CrossTarget API.

`std.build.Builder.standardTargetOptions` is changed to accept its
parameters as a struct with default values. It now has the ability to
specify a whitelist of targets allowed, as well as the default target.
Rather than two different ways of collecting the target, it's now always
a string that is validated, and prints helpful diagnostics for invalid
targets. This feature should now be actually useful, and contributions
welcome to further improve the user experience.

`std.build.LibExeObjStep.setTheTarget` is removed.
`std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget
parameter.

`std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are
handled in the CrossTarget API and can be specified with the `-target`
triple.

`std.builtin.Version` gains a `format` method.
2020-02-28 14:51:54 -05:00
Andrew Kelley f33bf48af7
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-25 16:30:40 -05:00
Andrew Kelley 7eb0a3edce
remove libc dependency of zig0 building libstage2
Rather than `zig0 build ...` the build now does
`zig0 build-lib ...`, avoiding the requirement of linking the build
script, and thus avoiding the requirement of finding native libc,
for systems where libc is the system ABI.
2020-02-16 18:57:34 -05:00