Commit Graph

306 Commits

Author SHA1 Message Date
Andrew Kelley
caddbbc315 build: avoid compiling self-hosted twice
build.zig: add a 'compile' step to compile the self-hosted compiler
without installing it.
Compilation: set cache mode to whole when using the LLVM backend and
--enable-cache is passed.

This makes `zig build` act the same as it does with stage1. Upside is
that a second invocation of `zig build` on an unmodified source tree
will avoid redoing the compilation again. Downside is that it will
proliferate more garbage in the project-local cache (same as stage1).

This can eventually be fixed when Zig's incremental compilation is more
robust; we can go back to having LLVM use CacheMode.incremental and rely
on it detecting no changes and avoiding doing the flush() step.
2022-10-18 16:52:43 -07:00
Andrew Kelley
1087e67762
Merge pull request #13108 from topolarity/llvm-lib-dir
build.zig: Forward LLVM lib/include dirs from CMake
2022-10-15 12:36:38 -04:00
Jacob Young
02d7292a8c build.zig: Forward LLVM lib/include dirs from CMake
Previously, you might obtain `-lLLVM-15` from the CMake configuration,
but we might not be able to locate the library if it's not in your
system library path.
2022-10-12 18:11:46 -04:00
Cody Tapscott
50a6dc8496 build.zig: Parse CMAKE_PREFIX_PATH with multiple entries
CMAKE_PREFIX_PATH is a semicolon separated list.
2022-10-12 12:01:44 -07:00
Ali Chraghi
d086b371f0 Compilation: strip debug info from ReleaseSmall by default 2022-10-11 17:51:25 +02:00
Cody Tapscott
350a88ddf4 build.zig: Forward LLVM lib/include dirs from CMake
Previously, you might obtain `-lLLVM-15` from the CMake configuration,
but we might not be able to locate the library if it's not in your
system library path.
2022-10-08 13:18:14 -07:00
Andrew Kelley
f374ea2cd1 build: add -Dsanitize-thread option 2022-10-05 03:22:10 -07:00
Andrew Kelley
85b10eb07c ZIG_EXE envirnoment variable instead of testing build options
No longer introduce build options for tests. Instead, ZIG_EXE
environment variable is added to any invocation of `zig run` or `zig
test`.

The end result of this branch is the same: there is no longer a
mandatory positional command line argument when invoking zig test
binaries directly.
2022-09-14 14:56:45 -07:00
Martin Wickham
5523e2061b Move std.testing.zig_exe_path into build options 2022-09-14 14:42:58 -07:00
Andrew Kelley
de7270028d Merge remote-tracking branch 'origin/master' into llvm15 2022-08-29 14:10:59 -07:00
Andrew Kelley
c4466496ff build: hook up -Dskip-stage2-tests and remove test-toolchain 2022-08-19 16:45:16 -07:00
Andrew Kelley
d75d40dfdf build: make docs a separate step than test 2022-08-19 16:45:15 -07:00
Andrew Kelley
507aae4a1a make self-hosted the default compiler
stage1 is available behind the -fstage1 flag.

closes #89
2022-08-19 16:45:15 -07:00
Andrew Kelley
73bbd1069a build: remove the option to omit stage2 2022-08-19 16:45:15 -07:00
Andrew Kelley
dfecd819ce build: add new clang libraries for LLVM 15 upgrade 2022-08-02 17:22:16 -07:00
Andrew Kelley
129bd4e9c3 update LLVM library list to LLVM 15 2022-08-02 16:57:32 -07:00
Andrew Kelley
3cf8f283d3
Merge pull request #12085 from topolarity/dyn-link-libcpp
Dynamically link `libc++` if integrating with system LLVM
2022-07-29 14:18:32 -07:00
Cody Tapscott
4fc2acdaa4 build.zig: Emit warning if "config.h" cannot be found
We now warn the user if config.h could not be located.

This also updates the search to stop early upon encountering a
`.git` directory, so that we avoid recursing outside of the zig
source if possible.
2022-07-29 11:38:58 -07:00
Cody Tapscott
f1feb1369b Dynamically link libc++, if integrating with system LLVM
This ensures that the zigcpp clang driver and LLVM are using the
same copy of libc++. See prior commit for more details.
2022-07-28 22:21:24 -07:00
Andrew Kelley
7a09bce232
Merge pull request #12136 from topolarity/llvm-config-rework
CMake: Improve usage of `llvm-config` (esp. for consistent static/shared linking)
2022-07-26 11:41:00 -07:00
r00ster
cff5d9c805
std.mem: add first method to SplitIterator and SplitBackwardsIterator 2022-07-25 22:04:30 +03:00
Luuk de Gram
a7417f7839
wasm: Enable C-ABI tests for self-hosted compiler 2022-07-25 06:34:00 +02:00
Cody Tapscott
5337934bcd CMake: Add ZIG_LLVM_LINK_MODE to config.h
This is currently unused, but it will be needed soon so that we can
avoid linking static libc++ if LLVM/Clang is configured as a shared
library.
2022-07-23 09:03:19 -07:00
Andrew Kelley
7502e490cb
Merge pull request #12173 from ziglang/autodocs-rebased
New Autodocs!
2022-07-22 20:56:59 -07:00
Andrew Kelley
b946934576 build.zig: 32 MiB stack size
This gives more headroom for comptime recursion, especially for debug
builds of Zig.
2022-07-21 12:23:33 -07:00
Andrew Kelley
08f3c7960a build.zig: remove deleted .cpp file 2022-07-20 11:10:46 -07:00
Luuk de Gram
8033767082
wasm-linker: Implement linker tests (#12006)
* test/link: initial wasm support

This adds basic parsing and dumping of wasm section so they
can be tested using the new linker-test infrastructure.

* test/link: all wasm sections parsing and dumping

We now parse and dump all sections for the wasm binary format.
Currently, this only dumps the name of a custom section.
Later this should also dump symbol table, name, linking metadata and relocations.
All of those live within the custom sections.

* Add wasm linker test

This also fixes a parser mistake in reading the flags.

* test/link: implement linker tests wasm & fixes

Adds several test cases to test the wasm self-hosted linker.
This also introduces fixes that were caught during the implementation
of those tests.

* test-runner: obey omit_stage2 for standalone

When a standalone test requires stage2, but stage2 is omit
from the compiler, such test case will not be included as part
of the test suite that is being ran. This is to support CI's
where we omit stage2 to lower the memory usage.
2022-07-12 14:36:33 +02:00
Andrew Kelley
15bdba410a update build scripts to LLD and LLVM 14 libraries 2022-07-03 18:41:43 -07:00
Jakub Konka
38edef35bf test: introduce link(er) tests - builds on standalone tests 2022-06-20 17:59:17 +02:00
Andrew Kelley
22690efcc2 multi-thread zig build test-cases
Instead of always using std.testing.allocator, the test harness now follows
the same logic as self-hosted for choosing an allocator - that is - it
uses C allocator when linking libc, std.testing.allocator otherwise, and
respects `-Dforce-gpa` to override the decision. I did this because
I found GeneralPurposeAllocator to be prohibitively slow when doing
multi-threading, even in the context of a debug build.

There is now a second thread pool which is used to spawn each
test case. The stage2 tests are passed the first thread pool. If it were
only multi-threading the stage1 tests then we could use the same thread
pool for everything. However, the problem with this strategy with stage2
is that stage2 wants to spawn tasks and then call wait() on the main
thread. If we use the same thread pool for everything, we get a deadlock
because all the threads end up all hanging at wait() and nothing is
getting done. So we use our second thread pool to simulate a "process pool"
of sorts.

I spent most of the time working on this commit scratching my head trying
to figure out why I was getting ETXTBSY when spawning the test cases.
Turns out it's a fundamental Unix design flaw, already a known, unsolved
issue by Go and Java maintainers:

https://github.com/golang/go/issues/22315
https://bugs.openjdk.org/browse/JDK-8068370

With this change, the following command, executed on my laptop, went from
6m24s to 1m44s:

```
stage1/bin/zig build test-cases -fqemu -fwasmtime -Denable-llvm
```

closes #11818
2022-06-14 17:15:13 -04:00
Andrew Kelley
2bf532fc23 stage2: use std.debug.Trace only when explicitly enabled
Because it bumps up the stack space requirements, which is making a test
case fail on aarch64 drone CI.
2022-06-09 20:00:59 -07:00
Andrew Kelley
b095aa6986 CI: skip single-threaded tests on Drone
sure would be nice if they would just give us another hour of CI run time.
2022-06-01 14:05:58 -07:00
Andrew Kelley
6d691d3540 build: include a build-id note only if explicitly requested 2022-05-31 13:51:59 -07:00
Andrew Kelley
59219e7e91 stage2: add support for -fbuild-id,-fno-build-id
closes #3047
2022-05-31 13:36:33 -07:00
Andrew Kelley
f6e9b6620d build.zig: rename a local variable 2022-05-13 14:30:43 -07:00
Andrew Kelley
66f3efb63b migrate runtime safety tests to the new test harness
* migrate runtime safety tests to the new test harness
   - this required adding compare output / execution support for stage1
     to the test harness.
 * rename `zig build test-stage2` to `zig build test-cases` since it now
   does quite a bit of stage1 testing actually. I named it this way
   since the main directory in the source tree associated with these
   tests is "test/cases/".
 * add some documentation for the test manifest format.
2022-05-13 14:03:20 -07:00
Andrew Kelley
e8c85450fe
Merge pull request #11592 from ziglang/stage3-macos-linker
Sema: solve a false positive "depends on itself"
2022-05-07 04:38:19 -04:00
Andrew Kelley
ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00
Andrew Kelley
496eb69273 CI: add non-LLVM backends to the test matrix
We can't yet run the behavior tests with stage3, but at least we can run
them with stage2, and we can use the proper test matrix.

This commit also adds use_llvm and ofmt to the zig build system.
2022-05-05 22:29:25 -07:00
Andrew Kelley
243afdcdf5 test harness improvements
* `-Dskip-compile-errors` is removed; `-Dskip-stage1` is added.
 * Use `std.testing.allocator` instead of a new instance of GPA.
   - Fix the memory leaks this revealed.
 * Show the file name when it is not parsed correctly such as when the
   manifest is missing.
   - Better error messages when test files are not parsed correctly.
 * Ignore unknown files such as swap files.
 * Move logic from declarative file to the test harness implementation.
 * Move stage1 tests to stage2 tests where appropriate.
2022-03-31 15:10:31 -07:00
Veikka Tuominen
7217148edf Value: hash lazy_align 2022-03-27 22:38:37 +03:00
Andrew Kelley
eee500c0b5 build.zig: restore the ability to bootstrap with zig0 via option 2022-02-17 23:49:13 -07:00
Andrew Kelley
6f42876e74 CLI: resolve system libs into static libraries
using the provided -L directories before checking if we need to integrate
with system library paths. This prevents false positive of invoking
system cc to find native paths when in fact all dependencies are
satisfied by -L (or --search-prefix to zig build).
2022-02-17 23:42:48 -07:00
Andrew Kelley
419074a81b CI: simplify linux script
* build.zig: remove detour through zig0. I'll add it back as an option
   later. This means you can build stage1 with a freshly built zig
   without detouring through zig0 again.
 * remove unused file windows_script.bat
 * drone.yml: remove unnecessary steps
 * ninja doesn't need a jobs parameter
 * build the release version of zig with zig build instead of cmake.
 * build stage2 with -Dstatic-llvm -Duse-zig-libcxx
2022-02-17 23:42:46 -07:00
Andrew Kelley
23567cdd98 build.zig: fix test-stage2 regression with -Denable-llvm
Regressed in cc9eb9e90f due to a merge
conflict.
2022-02-17 20:48:09 -07:00
Andrew Kelley
cc9eb9e90f build.zig: bootstrap stage1 with zig0
Instead of assuming that the zig version used with `zig build` is
appropriate for building the self-hosted compiler component, we follow
the same path as the cmake build script and build zig0, using that to
produce zig1.o, re-linking to produce stage1.

This allows an arbitrarily old Zig version and corresponding build.zig
script to build all future versions of Zig from source via the bootstrap
compiler. In other words, it allows us to use `zig build` as an
alternative to cmake when bootstrapping.
2022-02-16 14:12:15 -07:00
Cody Tapscott
5065830aa0 Avoid depending on child process execution when not supported by host OS
In accordance with the requesting issue (#10750):
- `zig test` skips any tests that it cannot spawn, returning success
- `zig run` and `zig build` exit with failure, reporting the command the cannot be run
- `zig clang`, `zig ar`, etc. already punt directly to the appropriate clang/lld main(), even before this change
- Native `libc` Detection is not supported

Additionally, `exec()` and related Builder functions error at run-time, reporting the command that cannot be run
2022-02-06 22:21:46 -07:00
Andrew Kelley
44b105a38d stage2: make --debug-log work by default for debug builds
can be disabled with `-Dlog=false`
2022-01-31 21:11:41 -07:00
Andrew Kelley
cd5b25c5ae build.zig: fix single-threaded option
Instead of defaulting to false, just keep the option as optional to
communicate default to the build system.

Fixes one problem with building the compiler for single-threaded
targets.
2022-01-28 17:17:31 -07:00
Andrew Kelley
0c1df96b17
Merge pull request #10552 from hdorio/deflate
compress: add a deflate compressor
2022-01-26 00:43:13 -05:00