Commit Graph

860 Commits

Author SHA1 Message Date
Andrew Kelley
efdc94c107 Merge remote-tracking branch 'origin/master' into llvm16 2023-02-18 09:33:27 -07:00
Andrew Kelley
9cb52ca6ce move the cache system from compiler to std lib 2023-02-13 06:42:25 -07:00
Andrew Kelley
fab9b7110e Merge remote-tracking branch 'origin/master' into llvm16 2023-02-03 12:49:40 -07:00
Andrew Kelley
873bb29c98 introduce ZON: Zig Object Notation
* std.zig.parse is moved to std.zig.Ast.parse
 * the new function has an additional parameter that requires passing
   Mode.zig or Mode.zon
 * moved parser.zig code to Parse.zig
 * added parseZon function next to parseRoot function
2023-02-03 00:06:11 -07:00
Andrew Kelley
97b1a9bb6b cmake: no -Werror on the C++ code we copy from llvm 2023-01-26 20:13:27 -05:00
Andrew Kelley
5994a5d18d update clang and ar to llvm 16 2023-01-25 20:56:23 -07:00
Andrew Kelley
9c3bd437e6 update cmake files to LLVM 16 2023-01-25 20:26:14 -07:00
Jakub Konka
835a60a34f zld: parse, synthesise and emit unwind records 2023-01-20 18:43:16 +01:00
Jakub Konka
069fe0d63f update CMakeLists.txt with new entries 2023-01-19 00:35:33 +01:00
kcbanner
3cacbea95b build: simplify llvm-config provided system library parsing
- Revert the addition of CLANG_SYSTEM_LIBARIES and LLVM_SYSTEM_LIBRARIES
- Change addCMakeLibraryList to parse non-absolute path .lib dependencies as system libraries
2023-01-04 21:45:06 -05:00
kcbanner
f5135f8e3b cmake: fix handling of transitive zstd dependency
- Remove ZIG_ENABLE_ZSTD in favour of allowing ZIG_STATIC_ZSTD to be toggled off explicitly when ZIG_STATIC is on
- Remove ZIG_ENABLE_LIBCPP (now unused)
2023-01-04 21:45:06 -05:00
kcbanner
88e442253b cmake: add /FORCE:MULTIPLE to handle fabsl being defined in compiler_rt as well as libcmpt 2023-01-04 21:45:06 -05:00
kcbanner
bd252c58bc cmake: /O0 -> /Od 2023-01-04 21:45:06 -05:00
kcbanner
701996083a cmake: /std:c99 isn't a valid cl option 2023-01-04 21:45:06 -05:00
kcbanner
b42442f5b4 windows: fixes to support using zig cc/c++ with CMake on Windows
Using zig cc with CMake on Windows was failing during compiler
detection. -nostdinc was causing the crt not to be linked, and Coff/lld.zig
assumed that wWinMainCRTStartup would be present in this case.

-nostdlib did not prevent the default behaviour of linking libc++ when
zig c++ was used. This caused libc++ to be built when CMake ran
ABI detection using zig c++, which fails as libcxxabi cannot compile
under MSVC.

- Change the behaviour of COFF -nostdinc to set /entry to the function that the
default CRT method for the specified subsystem would have called.
- Fix -ENTRY being passed twice if it was specified explicitly and -nostdlib was present.
- Add support for /pdb, /version, /implib, and /subsystem as linker args (passed by CMake)
- Remove -Ddisable-zstd, no longer needed
- Add -Ddisable-libcpp for use when bootstrapping on msvc
2023-01-04 21:45:06 -05:00
kcbanner
0471eea0e2 build: first pass on geting stage3 building under x64_64-windows-msvc 2023-01-04 21:45:05 -05:00
kcbanner
c3945d9ede cmake: output binaries to the build directory (ie. instead of Release/Debug subfolders) 2023-01-04 21:45:05 -05:00
Michael Dusan
0cb8ed6b85
cmake: ignore case for TARGET ARCH/OS mapping
- first convert to lower-case then perform mappings
- effect: freebsd, netbsd and openbsd convert arch `amd64` to `x86_64`
- effect: convert `arm64` to `aarch64`
2023-01-02 19:18:32 -05:00
Kim SHrier
5bde627f9d map lower case amd64 to x86_64 2022-12-24 02:23:31 -05:00
Frank Denis
8d66aacb64
compiler-rt: implement __udivei4 and __umodei4 (#14023)
Allows dividing and formatting arbitrary-large unsigned integers.
2022-12-22 16:29:19 -05:00
Jakub Konka
585c21e54d macho: move parallel file hashing back to CodeSignature
I need to think some more how to calculate UUID in parallel, if
it is even possible, to preserve UUID's determinism.
2022-12-16 18:05:58 +01:00
Jakub Konka
660270b7a9 macho: calculate UUID excluding stabs and part of contributing strtab 2022-12-16 18:05:58 +01:00
Jakub Konka
79457fc76a macho: generalize parallel hasher; impl parallel MD5-like hash
By pulling out the parallel hashing setup from `CodeSignature.zig`,
we can now reuse it different places across MachO linker (for now;
I can totally see its usefulness beyond MachO, eg. in COFF or ELF too).
The parallel hasher is generic over actual hasher such as Sha256 or MD5.
The implementation is kept as it was.

For UUID calculation, depending on the linking mode:
* incremental - since it only supports debug mode, we don't bother with MD5
  hashing of the contents, and populate it with random data but only once
  per a sequence of in-place binary patches
* traditional - in debug, we use random string (for speed); in release,
  we calculate the hash, however we use LLVM/LLD's trick in that we
  calculate a series of MD5 hashes in parallel and then one an MD5 of MD5
  final hash to generate digest.
2022-12-16 00:01:04 +01:00
Jakub Konka
ec40c6b28f macho: calculate UUID as a streaming MD5 hash of the file contents 2022-12-16 00:01:04 +01:00
Jakub Konka
db2052bc35 macho: dedup LC emitting logic
Fix path written to `LC_ID_DYLIB` to include the current CWD (if any).
2022-12-16 00:01:04 +01:00
Andrew Kelley
c079d5b15d CMake: fix aarch64-windows target detection 2022-12-10 16:28:49 -07:00
Andrew Kelley
cacb962ba7 CMake: add workaround for CMAKE_AR not supporting spaces
This allows using `zig ar` for `CMAKE_AR`. Unfortunately, it requires a
patch to CMakeLists.txt and cannot be done merely with flags to the
cmake line.
2022-12-10 16:28:49 -07:00
Andrew Kelley
c51288f1f6 remove the zstd mechanism from the build process 2022-12-09 20:59:13 -07:00
h57624paen
b483c796c6 fix building wasm2c output with msvc
cmake tweaks to allow zig1 to compile successfully with msvc
2022-12-09 22:35:05 -05:00
Jacob Young
a0a2e75773 cmake: disable stack protector for zig2 to avoid link errors on windows
On windows we get:

    lld-link: error: undefined symbol: __stack_chk_fail
    >>> referenced by CMakeFiles/zig2.dir/zig2.c.obj:(main)
    >>> referenced by CMakeFiles/zig2.dir/zig2.c.obj:(main_main)
    >>> referenced by CMakeFiles/zig2.dir/zig2.c.obj:(log_scoped_28_default_29_err__anon_2764)
    >>> referenced 36192 more times

    lld-link: error: undefined symbol: __stack_chk_guard
    >>> referenced by CMakeFiles/zig2.dir/zig2.c.obj:(.refptr.__stack_chk_guard)
    >>> referenced by CMakeFiles/zig2.dir/compiler_rt.c.obj
2022-12-06 12:27:28 -07:00
Jacob Young
98338358ed cmake: fix bootstrap dependencies 2022-12-06 12:27:28 -07:00
Andrew Kelley
eef4348953 CMake: remove --color on for compiler_rt too
Missing change from bcd4ea9b28a7560a1c1ef28c6c7258c6126c80e5
2022-12-06 12:27:28 -07:00
Andrew Kelley
aaf95ce849 CMake: adjust apple clang compiler check
Before it was checking if the compiler was AppleClang, however, this did
not handle the case when using a compiled-from-source Clang on a macOS
computer, in which case the linker is still Apple ld64, and it is in
fact the linker that needs to have the different flag to communicate
stack size.
2022-12-06 12:15:05 -07:00
Andrew Kelley
ec1334d2d4 CMake: remove --color on
This flag makes CI servers print garbage to the terminal. I started
implementing detection in wasi.c, but it would have destroyed the
beautiful code that only touches the C stdlib, does not do any
conditional compilation based on the operating system, or rely on any
POSIX functions.

So instead, let's just do without this flag to retain simplicity in this
step of the build process.
2022-12-06 12:15:05 -07:00
Jacob Young
9f4ef4de23 wasm2c: remove unnecessary brackets to reduce max bracket depth
This avoids the need to pass `-fbracket-depth=512` to clang.
2022-12-06 12:15:04 -07:00
Jacob Young
fdb98c5ce1 cmake: fix stack size linker argument on mac 2022-12-06 12:15:04 -07:00
Jacob Young
687ea31ef9 cmake: fix host target detection 2022-12-06 12:15:04 -07:00
Andrew Kelley
54b960aa4d CMake: add the bracket-depth workaround for zig1 2022-12-06 12:15:04 -07:00
Andrew Kelley
1e638cb206 CMake adjustments 2022-12-06 12:15:04 -07:00
Jacob Young
1263346774 use zig-wasm2c for bootstrapping 2022-12-06 12:15:04 -07:00
Andrew Kelley
a63305bc50 CMake: use ReleaseSmall instead of ReleaseFast
When producing C source code. This enables strip, which should avoid
bloat and save compilation time.
2022-12-06 12:15:04 -07:00
Andrew Kelley
fd54a01499 CMake: rebuild when the wasm blob changes 2022-12-06 12:15:04 -07:00
Andrew Kelley
02456a32ad CI: make Windows build from source like everybody else
Now that OOM is no longer a problem, the Windows CI can do the same
process every other system does instead of building from a recent Zig
binary.
2022-12-06 12:15:04 -07:00
Andrew Kelley
ba8d5fc7f8 CMake: no optimization for zig1.c and zig2.c 2022-12-06 12:15:04 -07:00
Matt Knight
e9d9be2902 Some fixes for the wasi interpreter for macOS (#13587)
* Remove usage of O_PATH, ifdef for macos stat struct, and integer formatting
2022-12-06 12:15:04 -07:00
Andrew Kelley
eef780ebf2 CMake: use -O1 instead of -O2 for building generated .c code
Idea here is that this is a sweet spot of not wasting time waiting for
optimizations but also getting decent runime performance.
2022-12-06 12:15:04 -07:00
Andrew Kelley
33e3db11fe zig1.c: autodetect host target triple
instead of assuming x8_64-linux in CMake
2022-12-06 12:15:04 -07:00
Andrew Kelley
34e9bbb9d4 enable the LLVM backend in stage2
This takes a bit longer since the interpreted part has to do more work
but it saves a round trip through the compiler by allowing `zig2 build`
to be the final step. 1-2-3, done.

For me this is currently failing due to compilation errors generated by
GCC when compiling zig2.c but in theory if those are fixed, it should
work!
2022-12-06 12:15:04 -07:00
Andrew Kelley
fb9a6084e2 zig1.c: decompress zig1.wasm.zst with zstd 2022-12-06 12:15:04 -07:00
Andrew Kelley
39fd77bc16 interpret the WASI blob to produce zig2.c and compiler_rt.c
* synchronize zig1.c from zig-wasi external project
 * change the way argv works to avoid absolute paths
 * autodetect isatty
 * compiler_rt: disable some functions when object format is C
 * add missing flag from config.zig.in

The next problem is that compiling compiler_rt.c with gcc gives
"conflicting types" errors for `__eqhf2` and friends.
2022-12-06 12:15:04 -07:00
Andrew Kelley
ef447c3eca redo CMakeLists.txt to use WASI interpreter
current status is that it hits error: OutOfMemory for unknown reasons,
probably due to bugs in the C WASI interpreter port.
2022-12-06 12:15:04 -07:00
Andrew Kelley
28514476ef remove -fstage1 option
After this commit, the self-hosted compiler does not offer the option to
use stage1 as a backend anymore.
2022-12-06 12:15:04 -07:00
Andrew Kelley
e18d310afd CI: build from old zig on x86_64-linux debug
This is to work around OOM on the CI server. Once #13560 is complete,
we can avoid having to replace the tarballs so often.
2022-11-22 00:56:44 -07:00
Andrew Kelley
5ec9be0b03 CMake: choose native CPU instead of baseline by default 2022-11-21 20:16:08 -07:00
Cody Tapscott
b605cb2742 cmake: Mark <root>/.git/HEAD as a configure dependency
This ensures that the Zig version will be re-computed when jumping
through the source tree, which is especially important if bisecting
across AstGen- or other changes that must not use the old cache.
2022-11-10 19:34:56 -05:00
Andrew Kelley
841235b3fd start the 0.11.0 release cycle 2022-10-31 10:25:46 -07:00
Andrew Kelley
0b99e5e4c4 build: rename the "skip lib files" option
* Old cmake option: `-DZIG_SKIP_INSTALL_LIB_FILES=ON`
 * New cmake option: `-DZIG_NO_LIB=ON`
 * Old build.zig option: `-Dskip-install-lib-files`
 * New build.zig option: `-Dno-lib`

Motivation is making build commands easier to type.
2022-10-27 15:18:00 -07:00
Andrew Kelley
8fc7b4d140 CMake: handle zstd the same as zlib
This is a new dependency of LLVM 15.
2022-10-25 18:29:39 -07:00
Andrew Kelley
0ae60f7236 CMake: detect use of CMAKE_PREFIX_PATH env var
CMake recognizes the CMAKE_PREFIX_PATH environment variable for some
things, and also the CMAKE_PREFIX_PATH cache variable for other things.
However, it does not relate these two things, i.e. if the environment
variable is set, CMake does not populate the cache variable in a
corresponding manner. Some package systems, such as Homebrew, set the
environment variable but not the cache variable. Furthermore, the
environment variable follows the system path separator, such as ':' on
POSIX and ';' on Windows, but the cache variable follows CMake's array
behavior, i.e. always ';' for a separator.

Closes #13242
2022-10-22 20:30:08 -07:00
Jakub Konka
d57639a308 macho: upstream rewritten traditional linker, zld
kubkon/zld gitrev 5733ed87abe2f07e1330c3232a252e9defec638a
2022-10-22 07:59:23 +02:00
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
Eric Joldasov
1013212697 cmake: separate installing and building (again) 2022-10-18 16:52:43 -07:00
kcbanner
28b7fa1d13 msvc: fixup compiler arg generation, as /O2 is incompatible with /RTC1 2022-10-12 05:31:48 -04:00
Andrew Kelley
2434cb6f06 cmake: add -Dversion-string flag to zig build command 2022-09-12 20:13:00 -07:00
Andrew Kelley
1e21876de2 Merge remote-tracking branch 'origin/master' into llvm15 2022-08-30 13:02:43 -07:00
Jakub Konka
241e1ac030 cmake: add runaway Coff/Object.zig path 2022-08-30 10:42:21 +02:00
Jakub Konka
90b3599c68 coff: reorganize the linker 2022-08-30 10:42:21 +02:00
Andrew Kelley
de7270028d Merge remote-tracking branch 'origin/master' into llvm15 2022-08-29 14:10:59 -07:00
Andrew Kelley
532cfb65e0 CI: rework to account for new cmake behavior
* CMakeLists: pass `-Dstrip` for release zig builds
 * pass -target and -mcpu to zig1. works around llvm on freebsd
   incorrectly detecting "freestanding" instead of "freebsd" for the
   native OS.
 * ci.ziglang.org is now responsible for creating aarch64-macos tarballs
   rather than Azure.
2022-08-28 17:07:21 -07:00
Andrew Kelley
aee53e2ffd CMake: add dummy install command
This makes it so that `ninja install` will work as expected.
2022-08-28 17:07:21 -07:00
Andrew Kelley
56129d26eb cmake: build stage3 by default
This is a simplification of the cmake build script which introduces a
new "stage3" target that is built by default, which builds and installs
a stage3 zig.

It greatly simplifies the build instructions for Zig, making it conform
to the regular cmake routine, while still producing a stage3 artifact.
2022-08-28 17:07:21 -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
0f793840ae stage1: LLVM lowering to opaque pointers API 2022-08-01 18:16:52 -07:00
Andrew Kelley
d46446e4df Merge remote-tracking branch 'origin/master' into llvm15 2022-07-31 15:55:44 -07:00
Meghan Denny
b5861193e0 std: rename std.Target.systemz to .s390x 2022-07-28 23:22:44 -07:00
Andrew Kelley
adb4a95302 update to LLVM 15
release/15.x 37007475ca1b345b4c5d340e228bcd7a62732d81
2022-07-28 11:53:25 -07:00
Andrew Kelley
0527b441ae move zig.h to become an installation file
Now instead of zig.h being baked into the compiler binary, it is a
header file distributed along with all the other header files
distributed with Zig.

Closes #11643
2022-07-27 10:26:45 -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
Cody Tapscott
3f640ef3d2 CMake: Improve usage of llvm-config, esp. for consistent linking
This commit reworks the LLVM/Clang/LLD discovery process for CMake. The
biggest changes are that:
  1. We search for LLVM from most preferred directory to least, skipping
     any `llvm-config` that is the wrong version, or that doesn't
     support the requested link mode ("static" or "shared").
  2. `ZIG_PREFER_CLANG_CPP_DYLIB` has been renamed to `ZIG_SHARED_LLVM`,
     to better align with `ZIG_STATIC_LLVM`.
  3. We only search for LLVM in the same directory alongside LLVM.
  4. LLVM's link mode is forwarded to Clang, so that we can look for the
     appropriate shared/static libraries.
  5. We use `--link-static` when querying `--system-libs` from llvm-config,
     so that this will include libz and other dependencies for
     statically linking LLD
2022-07-23 08:52:30 -07:00
Jakub Konka
a8bfddfaea
Merge pull request #12140 from ziglang/macho-gc-sections
macho: add support for `-dead_strip` (GC sections) and simplify symbol resolution
2022-07-23 00:01:09 -07:00
Jakub Konka
ca74656685 macho: move GC code into dead_strip.zig module
Implement marking live atoms that reference other live atoms if
required by the compiler (via section attribute).
2022-07-22 16:58:21 +02:00
Andrew Kelley
7d636f0f9d delete the stage1 implementation of autodoc 2022-07-19 19:10:12 -07:00
Cody Tapscott
dd70336f3a CMake: Use NAMES_PER_DIR in all lookups
CMake has a surprising default behavior where looking up a library by
multiple names gives the name order higher priority than the directory
search order.

For example, if your system provides "llvm-config-14" and
CMAKE_PREFIX_PATH includes "llvm-config", CMake will always end up
choosing the system-provided llvm-config-14.

This change add NAMES_PER_DIR to request the more sensible behavior:
directory search order has higher priority than name order, so
CMAKE_PREFIX_PATH always wins over system-provided tools/libraries.
2022-07-14 22:18:10 -04:00
BratishkaErik
b9ed072278 CMakeLists.txt: set LLVM minimal version to 14 2022-07-10 15:43:01 -04:00
Andrew Kelley
41a0b81731 CMake: disable deprecated function warnings
LLVM 14 deprecated a bunch of C API functions in preparation for opaque
pointer changes. However, they did not actually implement opaque pointer
semantics, so the deprecations are largely masturbatory. I have nothing
against masturbation, I am just busy trying to get the self hosted
compiler done for 0.10.0, so we will come back to this later.
2022-07-01 19:17:09 -07:00
Andrew Kelley
6bc6e47b15 stage2: lower float negation explicitly
Rather than lowering float negation as `0.0 - x`.

 * Add AIR instruction for float negation.
 * Add compiler-rt functions for f128, f80 negation

closes #11853
2022-06-30 00:02:00 -07:00
Andrew Kelley
e4092d4442 stage2: rip out multi-compilation-unit compiler-rt
After doing performance testing, it seems that multi-compilation-unit
compiler-rt did not bring the performance improvements that we expected
it to. The idea is that it makes linking faster, however, it incurred a
cost in the frontend that was not offset by any gains in linking.

Furthermore, the single-object compiler-rt (with -ffunction-sections and
--gc-sections) ends up being fewer bytes on disk and so it's actually
the same or faster linking speed than the multi-compilation-unit
version.

So we are planning to keep using single-compilation-unit compiler-rt for
the foreseeable future, but may experiment with this again in the
future, in which case this commit can be reverted.
2022-06-17 18:34:11 -07:00
Andrew Kelley
2064d86298 update CMakeLists.txt source files 2022-06-17 18:24:57 -07:00
Andrew Kelley
b4f3e69342 update CMakeLists.txt source file list 2022-06-17 16:38:59 -07:00
Andrew Kelley
25671f5a97 compiler-rt: move SPARC functions into appropriate compilation units 2022-06-17 16:38:59 -07:00
Andrew Kelley
c99c085d70 compiler-rt: break up functions even more
The purpose of this branch is to switch to using an object file for each
independent function, in order to make linking simpler - instead of
relying on `-ffunction-sections` and `--gc-sections`, which involves the
linker doing the work of linking everything and then undoing work via
garbage collection, this will allow the linker to only include the
compilation units that are depended on in the first place.

This commit makes progress towards that goal.
2022-06-17 16:38:59 -07:00
Jakub Konka
2259d629d3 compiler_rt: use single cache for libcompiler_rt.a static lib 2022-06-17 16:38:59 -07:00
Koakuma
fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -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
615a983517 cmake: default install prefix to ./stage1 2022-05-01 14:05:01 -07:00
Andrew Kelley
41dd2beaac compiler-rt: math functions reorg
* unify the logic for exporting math functions from compiler-rt,
   with the appropriate suffixes and prefixes.
   - add all missing f128 and f80 exports. Functions with missing
     implementations call other functions and have TODO comments.
   - also add f16 functions
 * move math functions from freestanding libc to compiler-rt (#7265)
 * enable all the f128 and f80 code in the stage2 compiler and behavior
   tests (#11161).
 * update std lib to use builtins rather than `std.math`.
2022-04-27 12:20:44 -07:00
protty
18f3034629
std.Thread: ResetEvent improvements (#11523)
* std: start removing redundant ResetEvents

* src: fix other uses of std.Thread.ResetEvent

* src: add builtin.sanitize_thread for tsan detection

* atomic: add Atomic.fence for proper fencing with tsan

* Thread: remove the other ResetEvent's and rewrite the current one

* Thread: ResetEvent docs

* zig fmt + WaitGroup.reset() fix

* src: fix build issues for ResetEvent + tsan

* Thread: ResetEvent tests

* Thread: ResetEvent module doc

* Atomic: replace llvm *p memory constraint with *m

* panicking: handle spurious wakeups in futex.wait() when waiting for abort()

* zig fmt
2022-04-26 16:48:56 -05:00
kprotty
7284eb22dc treap: initial implementation 2022-04-15 15:26:51 -05:00
Cody Tapscott
b5d5685a4e compiler_rt: Implement floatXiYf/fixXfYi, incl f80
This change:
 - Adds  generic implementation of the float -> integer conversion
   functions floatXiYf, including support for f80
 - Updates the existing implementation of integer -> float conversion
   fixXiYf to support f16 and f80
 - Fixes the handling of the explicit integer bit in `__trunctfxf2`
 - Combines the test cases for fixXfYi/floatXiYf into a single file
 - Renames `fmodl` to `fmodq`, since it operates on 128-bit floats

The new implementation for floatXiYf has been benchmarked, and generally
provides equal or better performance versus the current implementations:

Throughput (MiB/s) - Before
     |    u32   |    i32   |    u64   |    i64   |   u128   |   i128   |
-----|----------|----------|----------|----------|----------|----------|
 f16 |     none |     none |     none |     none |     none |     none |
 f32 |  2231.67 |  2001.19 |  1745.66 |  1405.77 |  2173.99 |  1874.63 |
 f64 |  1407.17 |  1055.83 |  2911.68 |  2437.21 |  1676.05 |  1476.67 |
 f80 |     none |     none |     none |     none |     none |     none |
f128 |   327.56 |   321.25 |   645.92 |   654.52 |  1153.56 |  1096.27 |

Throughput (MiB/s) - After
     |    u32   |    i32   |    u64   |    i64   |   u128   |   i128   |
-----|----------|----------|----------|----------|----------|----------|
 f16 |  1407.61 |  1637.25 |  3555.03 |  2594.56 |  3680.60 |  3063.34 |
 f32 |  2101.36 |  2122.62 |  3225.46 |  3123.86 |  2860.05 |  1985.21 |
 f64 |  1395.57 |  1314.87 |  2409.24 |  2196.30 |  2384.95 |  1908.15 |
 f80 |   475.53 |   457.92 |   884.50 |   812.12 |  1475.27 |  1382.16 |
f128 |   359.60 |   350.91 |   723.08 |   706.80 |  1296.42 |  1198.87 |
2022-04-12 10:25:26 -07:00
viri
c5c6260534
std.math: generalise inf, even simpler isFinite 2022-04-07 02:38:31 -06:00
Andrew Kelley
916a65cb7b
Merge pull request #11224 from koachan/sparc64-codegen
stage2 sparcv9: Add instruction encoder and placeholder codegen impl
2022-03-21 18:21:31 -04:00
William Sengir
9f25c8140c cmake: add missing DWARF files to ZIG_STAGE2_SOURCES 2022-03-20 14:48:37 +01:00
fn ⌃ ⌥
d62b1c932e
translate-c: add missing builtins used by CRuby 2022-03-19 19:08:17 +02:00
Koakuma
93b16de4b4 stage2 sparcv9: Add placeholder files and generate() function
Add placeholder files for Codegen, Emit, and Mir stages, complete with
a placeholder implementation of generate() to make it able to be plugged in
to the frontend. At the moment the implementation just panics, it'll be
worked on incrementally later.

Also, this registers the sparcv9 backend files into CMakeLists.txt.
2022-03-19 06:09:46 +07:00
Jakub Konka
dd55b72949 std: introduce posix_spawn as an alt to fork-exec
Currently, the new API will only be available on macOS with
the intention of adding more POSIX systems to it incrementally
(such as Linux, etc.).

Changes:
* add `posix_spawn` wrappers in a separate container in
  `os/posix_spawn.zig`
* rewrite `ChildProcess.spawnPosix` using `posix_spawn` targeting macOS
  as `ChildProcess.spawnMacos`
* introduce a `posix_spawn` specific `std.c.waitpid` wrapper which
  does return an error in case the child process failed to exec - this
  is required for any process that was spawned using `posix_spawn`
  mechanism as, by definition, the errors returned by `posix_spawn`
  routine cover only the `fork`-equivalent; `pre-exec()` and `exec()`
  steps are covered by a catch-all error `ECHILD` returned by `waitpid`
  on unsuccessful execution, e.g., no such file error, etc.
2022-03-16 19:40:44 +01:00
Jakub Konka
633c4a2a60 macos: add Mach task abstraction
`std.os.darwin.MachTask` wraps `mach_port_t` and can be used to issue
kernel calls tied to the wrapped Mach kernel port/task.
2022-03-13 13:35:39 +01:00
joachimschmidt557
06058ed6f3
stage2 regalloc: replace Register.allocIndex with generic indexOfReg
* callee_preserved_regs and other ABI-specific information have been
moved to the respective abi.zig files
2022-03-11 13:29:16 +01:00
Hadrien Dorio
02902cc099
ci: azure: split build-and-test step (#10853)
replace the .bat script by a pwsh script
2022-02-16 22:33:08 -05:00
Andrew Kelley
d164865308 add missing source file to CMakeLists.txt 2022-02-14 12:26:15 -07:00
Andrew Kelley
1c23321d03 stage1: fix softfloat not getting correct endianness
needed to include platform.h in more places so that LITTLEENDIAN will be
defined appropriately.

closes #10860
2022-02-12 11:18:23 +01:00
Andrew Kelley
44b5fdf326 Revert "ci: azure: split build-and-test step"
This reverts commit 846eb70182.

This did not properly translate the upload portion of the CI script to
powershell which broke our CI pipeline.
2022-02-09 18:26:56 -07:00
Hadrien Dorio
846eb70182 ci: azure: split build-and-test step
replace the .bat script by a pwsh script
2022-02-08 19:47:46 -05:00
Andrew Kelley
fd6c351263 cmake: fix -DZIG_SINGLE_THREADED option
It was still passing --single-threaded instead of -fsingle-threaded.
2022-02-08 17:22:11 -07:00
Veikka Tuominen
a31a749c42 stage1: add f80 type 2022-01-28 11:45:04 -07:00
Jakub Konka
6315bcb32a stage2: rename Isel to Emit for x86_64
Clean up generated errors in Emit.
2022-01-15 18:36:13 +01:00
Jakub Konka
e7ac05e882 stage2: rename Emit to Isel for x86_64 2021-12-31 11:18:23 +01:00
Jan Philipp Hafer
17046674a7 compiler_rt: add __negvsi2, __negvdi2, __negvti2
- neg can only overflow, if a == MIN
- case `-0` is properly handled by hardware, so overflow check by comparing
  `a == MIN` is sufficient
- tests: MIN, MIN+1, MIN+4, -42, -7, -1, 0, 1, 7..

See #1290
2021-12-27 14:35:45 -08:00
Jan Philipp Hafer
405ff911da compiler_rt: add __absvsi2, __absvdi2, __absvti2
- abs can only overflow, if a == MIN
- comparing the sign change from wrapping addition is branchless
- tests: MIN, MIN+1,..MIN+4, -42, -7, -1, 0, 1, 7..

See #1290
2021-12-26 13:21:18 -08:00
Andrew Kelley
3763580e1e add missing files to CMakeLists 2021-12-23 17:48:58 -07:00
Andrew Kelley
e3e6516d08 start the 0.10.0 release cycle 2021-12-20 13:13:48 -07:00
Jan Philipp Hafer
20328e976f compiler_rt: add __cmpXi2 and __ucmpXi2
- adds __cmpsi2, __cmpdi2, __cmpti2
- adds __ucmpsi2, __ucmpdi2, __ucmpti2
- use 2 if statements with 2 temporaries and a constant
- tests: MIN, MIN+1, MIN/2, -1, 0, 1, MAX/2, MAX-1, MAX if applicable

See #1290
2021-12-14 14:21:30 -08:00
Jan Philipp Hafer
eb1e75b2b8 compiler_rt: refactor __mulodi2 and __muloti2 to get __mulosi2
- use comptime instead of 2 identical implementations
- tests: port missing tests and link to archived llvm-mirror release 80

See #1290
2021-12-14 14:16:24 -08:00
Jan Philipp Hafer
c56663dee8 compiler_rt: add __negsi2, __negdi2, __negti2
- use negXi2.zig to prevent confusion with negXf2.zig
- used for size optimized builds and machines without carry instruction
- tests: special cases 0, -INT_MIN
  * use divTrunc range and shift with constant offsets

See #1290
2021-12-14 14:14:31 -08:00
Jan Philipp Hafer
efdb94486b compiler_rt: add __bswapsi2, __bswapdi2 and __bswapti2
- each byte gets masked, shifted and combined
- use boring masks instead of comptime for readability
- tests: bit patterns with reverse operation, if applicable

See #1290
2021-12-11 01:43:37 -08:00
Jakub Konka
828f61e8df macho: move all helpers from commands.zig into std.macho
This way we will finally be able to share common parsing logic
between different Zig components and 3rd party packages.
2021-12-10 18:18:28 +01:00
Andrew Kelley
f3edff439e improve detection of how to execute binaries on the host
`getExternalExecutor` is moved from `std.zig.CrossTarget` to
`std.zig.system.NativeTargetInfo.getExternalExecutor`.

The function also now communicates a bit more information about *why*
the host is unable to execute a binary. The CLI is updated to report
this information in a useful manner.

`getExternalExecutor` is also improved to detect such patterns as:
 * x86_64 is able to execute x86 binaries
 * aarch64 is able to execute arm binaries
 * etc.

Added qemu-hexagon support to `getExternalExecutor`.

`std.Target.canExecBinaries` of is removed; callers should use the more
powerful `getExternalExecutor` instead.

Now that `zig test` tries to run the resulting binary no matter what,
this commit has a follow-up change to the build system and docgen to
utilize the `getExternalExecutor` function and pass `--test-no-exec`
in some cases to avoid getting the error.

Additionally:

 * refactor: extract NativePaths and NativeTargetInfo into their own
   files named after the structs.
 * small improvement to langref to reduce the complexity of the `callconv`
   expression in a couple examples.
2021-12-02 21:51:14 -07:00
Jan Philipp Hafer
e4c053f047 compiler_rt: add __paritysi2, __paritydi2, __parityti2
- use Bit Twiddling Hacks: Compute parity in parallel
- test cases derived from popcount.zig
- tests: compare naive approach 10_000 times with random numbers created
  from naive seed 42
- compiler_rt.zig: sort by LLVM builtin order and add comments to improve structure

See #1290
2021-12-01 13:35:19 -08:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Jan Philipp Hafer
1ea650bb75 compiler_rt: add __popcountsi2, __popcountdi2 and __popcountti2
- apply simpler approach than LLVM for __popcountdi2
  taken from The Art of Computer Programming and generalized
- rename popcountdi2.zig to popcount.zig
- test cases derived from popcountdi2_test.zig
- tests: compare naive approach 10_000 times with
  random numbers created from naive seed 42

    See #1290
2021-11-29 12:50:25 -08:00
Stephen Gutekanst
b613210140
compiler_rt: implement __isPlatformVersionAtLeast (Objective-C @available expressions) for Darwin (#10232) 2021-11-29 14:54:23 -05:00
Jakub Konka
2ca5a859e9 Force static libncurses in CMakeLists when static zig on macos
Add additional search paths pointing at homebrew prefixes as Apple
doesn't ship a static libncurses for linking - only a stub for dynamic
linking `libncurses.tbd`.
2021-11-28 21:10:33 -08:00
Luuk de Gram
d3135f7682
Stage2: wasm - Implement the MIR pass (#10153)
* wasm: Move wasm's codegen to arch/wasm/CodeGen.zig

* wasm: Define Wasm's Mir

This declares the initial most-used instructions for wasm as
well as the data that represents them.
TODO: Add binary operand opcodes.

By re-using the wasm opcode values, we can emit each opcode very easily
by simply using `@enumToInt()`. However, this poses a possible problem:
If we use all of wasm's opcodes, it leaves us no room to use synthetic opcodes such as debugging instructions.
We could use reserved opcodes, but the wasm spec may use them at some point.
TODO: Check if we should perhaps use a 16bit tag where the highest bits are used for synthetic opcodes.

* wasm: Define basic Emit structure

* wasm: Implement corresponding Emit functions for MIR

* wasm: Initial lowering to MIR

- This implements lowering to MIR from AIR for storing and loading of locals
as well as emitting immediates.
- Relocating function indexes has been simplified a lot as well as we no
longer need to patch offsets and we write a relocatable value instead.
- Locals are now emitted at the beginning of the function section entry
meaning all offsets we generate are stable.

* wasm: Lower all AIR instructions to MIR

* wasm: Implement remaining MIR instructions

* wasm: Fix function relocations

* wasm: Get all tests working

* wasm: Make `Data` 4 bytes instead of 8.

- 64bit immediates are now stored in 2 seperate u32's.
- 64bit floats are now stored in 2 seperate u32's.
- `mem_arg` is now stored as a seperate payload in extra.
2021-11-15 18:02:24 +01:00
Martin Hafskjold Thoresen
e04ab39036 Cmake: Specify LLVM versions
Systems with multiple LLVM toolchains installed (e.g. one globally and one
in $HOME/local) would get confused and fail to compile.  Being explicit
about the version required will force CMake to find the right version of LLVM.
2021-11-09 13:39:32 -05:00
joachimschmidt557
8f58e2d779 stage2 codegen: move bit definitions to src/arch 2021-09-24 13:47:59 -04:00
Andrew Kelley
f3147de7a2 stage2: extract ZIR printing code into print_zir.zig
also implement textual printing of the ZIR instruction `atomic_rmw`.
2021-09-20 14:45:40 -07:00
Jakub Konka
a38b636045 Merge remote-tracking branch 'origin/master' into zld-incr 2021-09-13 23:40:38 +02:00
Jakub Konka
aaacfc0d0a macho: init process of renaming TextBlock to Atom
Initially, internally within the linker.
2021-09-09 18:32:03 +02:00
Andrew Kelley
3940a1be18 rename std.zig.ast to std.zig.Ast; use top-level fields 2021-09-01 17:54:07 -07:00
Andrew Kelley
ca21cad2bf move syntax tests out of behavior tests
parser_test.zig is where the syntax tests go
2021-09-01 17:54:06 -07:00
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
3deda15e21 std.os reorganization, avoiding usingnamespace
The main purpose of this branch is to explore avoiding the
`usingnamespace` feature of the zig language, specifically with regards
to `std.os` and related functionality.

If this experiment is successful, it will provide a data point on
whether or not it would be practical to entirely remove `usingnamespace`
from the language.

In this commit, `usingnamespace` has been completely eliminated from
the Linux x86_64 compilation path, aside from io_uring.

The behavior tests pass, however that's as far as this branch goes. It is
very breaking, and a lot more work is needed before it could be
considered mergeable. I wanted to put a pull requset up early so that
zig programmers have time to provide feedback.

This is progress towards closing #6600 since it clarifies where the
actual "owner" of each declaration is, and reduces the number of
different ways to import the same declarations.

One of the main organizational strategies used here is to do namespacing
with real namespaces (e.g. structs) rather than by having declarations
share a common prefix (the C strategy). It's no coincidence that
`usingnamespace` has similar semantics to `#include` and becomes much
less necessary when using proper namespaces.
2021-09-01 17:54:06 -07:00
Jan Philipp Hafer
81e2034d4a compiler_rt: add __clzdi2 and __clzti2
- structure derived from shift.zig
- rename clzsi2.zig to count0bits.zig
- test cases derived from clzsi2_test.zig

See #1290
2021-09-01 16:15:21 -04:00
Andrew Kelley
a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
Jakub Konka
5533f77054 Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-23 17:06:19 +02:00
Andrew Kelley
7c25390c95 support -fcompiler-rt in conjunction with build-obj
When using `build-exe` or `build-lib -dynamic`, `-fcompiler-rt` means building
compiler-rt into a static library and then linking it into the executable.

When using `build-lib`, `-fcompiler-rt` means building compiler-rt into an
object file and then adding it into the static archive.

Before this commit, when using `build-obj`, zig would build compiler-rt
into an object file, and then on ELF, use `lld -r` to merge it into the
main object file. Other linker backends of LLD do not support `-r` to
merge objects, so this failed with error messages for those targets.

Now, `-fcompiler-rt` when used with `build-obj` acts as if the user puts
`_ = @import("compiler_rt");` inside their root source file. The symbols
of compiler-rt go into the same compilation unit as the root source file.

This is hooked up for stage1 only for now. Once stage2 is capable of
building compiler-rt, it should be hooked up there as well.
2021-07-22 19:51:32 -07:00
Jakub Konka
def1359187 Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-22 09:34:44 +02:00
Andrew Kelley
0ffc6b5cc3 cmake: fix Liveness.zig file path 2021-07-20 12:19:16 -07:00
Andrew Kelley
5d6f7b44c1 stage2: rework AIR memory layout
This commit changes the AIR file and the documentation of the memory
layout. The actual work of modifying the surrounding code (in Sema and
codegen) is not yet done.
2021-07-20 12:18:14 -07:00
Jakub Konka
f6d13e9d6f zld: move contents of Zld into MachO module 2021-07-18 17:48:00 +02:00
Jakub Konka
407745a5e9 zld: simplify and move Relocations into TextBlock
It makes sense to have them as a dependent type since they only ever
deal with TextBlocks. Simplify Relocations to rely on symbol indices
and symbol resolver rather than pointers.
2021-07-17 01:03:40 +02:00
Jakub Konka
54a403d4ff zld: replace parsed reloc with a simple wrapper around macho.relocation_info 2021-07-16 17:18:53 +02:00
Jakub Konka
f519e781c6 zld: move TextBlock into standalone file
which should make managing the logic of parsing and resolving relocs
that much simpler to parse.
2021-07-15 18:49:48 +02:00
Jakub Konka
0135b46659 zld: remove StringTable abstraction 2021-07-15 18:49:47 +02:00
Jakub Konka
dbd2eb7c7f zld: simplify relocation parsing 2021-07-15 18:49:47 +02:00
Jakub Konka
3622fe08db zld: abstract away string table with fewer allocs 2021-07-15 18:49:46 +02:00
Andrew Kelley
476faef97a plan9 cleanups
* rename files to adhere to conventions
 * remove unnecessary function / optionality
 * fix merge conflict
 * better panic message
 * remove unnecessary TODO comment
 * proper namespacing of declarations
 * clean up documentation comments
 * no copyright header needed for a brand new zig file that is not
   copied from anywhere
2021-07-08 14:24:16 -07:00
jacob gw
34c21affa2 initial plan9 boilerplate
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-08 14:10:49 -07:00
Jakub Konka
3cb6b6bd90 zld: merge Stub with Dylib struct
After giving it more thought, it doesn't make sense to separate
the two structurally. Instead, there should be two constructors
for a Dylib struct: one from binary file, and the other from a stub
file. This cleans up a lot of code and opens the way for recursive
parsing of re-exports from a dylib which are a hard requirement for
native feel when linking frameworks.
2021-06-24 18:57:04 +02:00
Jakub Konka
bc78b02c04 zld: introduce Stub.zig which represents parsed stub file
Instead of trying to fit a stub file into the frame of a Dylib struct,
I think it makes more sense to keep them as separate entities with
possibly shared interface (which would be added in the future).

This cleaned up a lot of logic in Dylib as well as Stub. Also, while
here I've made creating actual *Symbols lazy in the sense Dylib and
Stub only store hash maps of symbol names that they expose but we
defer create and referencing given dylib/stub until link time when
a symbol is actually referenced. This should reduce memory usage
and speed things up a bit.
2021-06-24 14:45:45 +02:00
Jakub Konka
fbdc515418 link: add basic TAPI parser for linkers
Parser uses kubkon/zig-yaml gitrev c3eae1e40a02aedd44ad1171e5c8b259896cbda0
2021-06-24 14:45:45 +02:00
Andrew Kelley
c3f637a54c cmake: debug builds of zig enable logging by default
when logging is enabled, the --debug-log flag is available.
2021-06-23 10:44:46 -07:00
Andrew Kelley
193c529b8c CLI: rename --override-lib-dir to --zig-lib-dir
This breaking change disambiguates between overriding the lib dir when
performing an installation with the Zig Build System, and overriding the
lib dir that the Zig installation itself uses.
2021-06-14 11:33:27 -07:00
protty
2ba68f9f4c
std.Thread.Futex addition (#9070)
* std.Thread.Futex: implementation + tests

* std.Thread.Futex: fix darwin compile errors

* std.Thread.Futex: fix wait() documentation typo

* std.Thread.Futex: fix darwin version check

* std.Thread.Futex: remove unnecessary comptime keyword
2021-06-12 08:51:37 -05:00
Andrew Kelley
b755c46d70 start the 0.9.0 release cycle 2021-06-04 11:29:01 -07:00
Andrew Kelley
87dae0ce98
Merge pull request #8932 from ziglang/llvm-needs-zlib
cmake: LLVM needs to link against zlib
2021-06-03 02:13:37 -04:00
protty
eb6975f088
std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
2021-05-31 11:11:30 -05:00
Andrew Kelley
f8bc5294f2 cmake: LLVM needs to link against zlib
For more details on why this dependency is needed, see
https://github.com/ziglang/zig-bootstrap/issues/57
2021-05-29 17:22:27 -07:00
Andrew Kelley
0afb5b2ec6 stage2: add zig ar subcommand
The same entrypoint supports the following commands:

 * ar
 * ranlib
 * dlltool
 * lib

For now, our strategy is to bundle the (renamed) `main()` function of
llvm-ar, same as our strategy for `zig clang`. However, as Zig matures,
a goal will be to replace the dependency on LLVM  with our own
implementation of this tool, so that it is available in builds of zig
that do not have LLVM extensions enabled.

This commit also categorizes the subcommands into categories in the
--help menu.
2021-05-28 20:54:11 -07:00
Andrew Kelley
2a990d6966 stage1: rework tokenizer to match stage2
* Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the
   largest file of stage1 from 33,551 lines to 25,510.
 * tokenizer: rework it completely to match the stage2 tokenizer logic.
   They can now be maintained together; when one is changed, the other
   can be changed in the same way.
   - Each token now takes up 13 bytes instead of 64 bytes. The tokenizer
     does not parse char literals, string literals, integer literals,
     etc into meaningful data. Instead, that happens during parsing or
     astgen.
   - no longer store line offsets. Error messages scan source
     files to find the line/column as needed (same as stage2).
   - main loop: instead of checking the loop, handle a null byte
     explicitly in the switch statements. This is a nice improvement
     that we may want to backport to stage2.
   - delete some dead tokens, artifacts of past syntax that no longer
     exists.
 * Parser: fix a TODO by parsing builtin functions as tokens rather than
   `@` as a separate token. This is how stage2 does it.
 * Remove some debugging infrastructure. These will need to be redone,
   if at all, as the code migrates to match stage2.
   - remove the ast_render code.
   - remove the IR debugging stuff
   - remove teh token printing code
2021-05-28 12:58:40 -07:00
Andrew Kelley
79dee75b1c stage2: rename ir.zig to air.zig
We've settled on the nomenclature for the artifacts the compiler
pipeline produces:

1. Tokens
2. AST (Abstract Syntax Tree)
3. ZIR (Zig Intermediate Representation)
4. AIR (Analyzed Intermediate Representation)
5. Machine Code

Renaming `ir` identifiers to `air` will come with the inevitable
air-memory-layout branch that I plan to start after the 0.8.0 release.
2021-05-22 14:29:16 -07:00
Jakub Konka
7b74de7d71 wasi,cc: fix naming and add stubs for building
Rename include dir to match the convention:
  from `wasm32-wasi` to `wasm-wasi-musl`

Add building stubs which will be used to build and cache WASI
libc sysroot.
2021-05-20 16:54:00 +02:00
Andrew Kelley
a9cd9b021b Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
I want the updated Drone CI stuff to get the CI green.
2021-05-18 12:37:03 -07:00
Jakub Konka
138cecc028 zld: add prelim way of linking dylibs
The support is minimalistic in the sense that we only support actual
dylib files and not stubs/tbds yet, and we also don't support re-exports
just yet.
2021-05-18 09:28:00 +02:00
Andrew Kelley
9a95478c62 cmake: remove deleted file
This should have been part of 07606d12da
2021-05-15 21:46:36 -07:00
Andrew Kelley
f37451a63a stage2: fix zir.zig => Zir.zig in CMakeLists.txt 2021-04-15 19:12:05 -07:00
Jakub Konka
1119970d22 zld: add x86_64 relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
6a866f1a96 zld: preprocess relocs on arm64 2021-04-13 10:56:03 +02:00
Jakub Konka
988b184d03 zld: redo symbol resolution in objects
Store only globals and undefs at the linker level, while all locals
stay scoped to the actual object file they were defined in. This is
fine since the relocations referencing locals will always be resolved
first using the local symbol table before checking for the reference
within the linker's global symbol table.

This also paves the way for proper symbol resolution from within static
and dynamic libraries.
2021-04-13 10:56:03 +02:00
Andrew Kelley
281a7baaea Merge remote-tracking branch 'origin/master' into zir-memory-layout
Wanted to make sure those new test cases still pass.

Also grab that CI fix so we can get those green check marks.
2021-03-28 19:42:43 -07:00
Isaac Freund
402f87a213
stage2: rename WipZirCode => AstGen, astgen.zig => AstGen.zig 2021-03-28 19:10:10 +02:00
Jakub Konka
ba8ac46e1f stage1: add cmake flag for enabling logging
Now that we ship our own linker for MachO by default in both stage1
and stage2, we need a way to enable logs for verbose debugging.
This commit adds `ZIG_ENABLE_LOGGING` cmake option which is equivalent
to stage2's `-Dlog` flag.

To enable it when building stage1 with cmake, add:

```
cmake .. -DZIG_ENABLE_LOGGING=on
```
2021-03-21 18:03:55 -07:00
Michael Dusan
e35f325dd1 azure: produce macos arm64 binaries
new pipeline `BuildMacOS_arm64`
  - `vmImage: 'macOS-10.15' `

new `macos_arm64_script`
  - switch from using `make` to `ninja`
  - select xcode 12.4
  - set zig-cache env variables
  - build host-zig binary with xcode, link against llvm for x86_64 (target macos 10.15)
  - build arm64-zig binary with xcode and host-zig, link against llvm for arm64 (target macos 11.0)
  - ad-hoc codesign arm64 binary with linker
  - use host-zig for docgen
  - use host-zig for experimental std lib docs
  - sync final `release/` hierarchy with `linux_script`
  - use gnu-tar for good-practices (set owner, set sort)

enhance `CMakeLists.txt`
  - do not build `zig0` when cross-compiling
  - disable `BYPRODUCTS` directive `zig1.o` to avoid `ninja` error

see #8265
2021-03-20 22:50:51 +01:00
Andrew Kelley
f5aca4a6a1 Merge remote-tracking branch 'origin/master' into zir-memory-layout
I need the enum arrays that were just merged into master.
2021-03-18 15:52:12 -07:00
Jakub Konka
7516dfff83 zld: use zld when linking aarch64 by default and cross-comp 2021-03-18 00:37:13 +01:00
Andrew Kelley
099af0e008 stage2: rename zir_sema.zig to Sema.zig 2021-03-16 00:04:17 -07:00
Andrew Kelley
4e9894cfc4 cmake build: allow overriding whether to use llvm-config
Previously, there was an option ZIG_PREFER_LLVM_CONFIG which would
override the default of not using llvm-config when cross compiling.

That option is now removed in favor of the more powerful
ZIG_USE_LLVM_CONFIG which defaults to OFF for cross compiling and ON for
native compilation. The option overrides the default.

This will be used in zig-bootstrap to improve support for native builds.
2021-03-13 14:30:56 -07:00
daurnimator
1f861ecc95 Bring back ZIG_SKIP_INSTALL_LIB_FILES 2021-03-01 16:23:10 -08:00
Andrew Kelley
38441b5eab MultiArrayList: use @memcpy as a workaround
Reverts bf642204b3 and uses a different
workaround, suggested by @LemonBoy.

There is either a compiler bug or a design flaw somewhere around here.
It does not have to block this branch, but I need to understand exactly
what's going on here and make it so that nobody ever has to run into
this problem again.
2021-02-24 12:49:12 -07:00
Andrew Kelley
f041425e48 translate-c: fix using wrong slice and AST tag 2021-02-23 13:55:12 -07:00
Veikka Tuominen
d672c20b8a
Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Isaac Freund
070e548acf
std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Veikka Tuominen
13a9db2085
translate-c: begin implementing ast.render 2021-02-16 16:40:06 +02:00
Andrew Kelley
a9667b5a85 organize std lib concurrency primitives and add RwLock
* move concurrency primitives that always operate on kernel threads to
   the std.Thread namespace
 * remove std.SpinLock. Nobody should use this in a non-freestanding
   environment; the other primitives are always preferable. In
   freestanding, it will be necessary to put custom spin logic in there,
   so there are no use cases for a std lib version.
 * move some std lib files to the top level fields convention
 * add std.Thread.spinLoopHint
 * add std.Thread.Condition
 * add std.Thread.Semaphore
 * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux
 * add std.Thread.RwLock

Implementations provided by @kprotty
2021-01-14 20:41:37 -07:00
Andrew Kelley
d68adc5382 std.EarlyEOFReader: rename to LimitedReader 2021-01-11 16:51:56 -07:00
daurnimator
e873668d38 std: add LimitedReader: reader that returns EOF early 2021-01-11 16:48:30 -07:00
Jay Petacat
e72472d953 io: FindByteOutStream to FindByteWriter
See #4917
2021-01-08 16:54:56 -05:00
Andrew Kelley
2f58efcc1f std.SpinLock: flatten and remove init/deinit
structs which are intended to be directly initialized and support static
initialization should not have init/deinit methods.
2021-01-06 17:36:06 -07:00
Andrew Kelley
76870a2265
Merge pull request #7700 from FireFox317/more-stage2-stuff-llvm
stage2: improvements to LLVM backend
2021-01-06 16:06:32 -08:00
Timon Kruiper
b1cfa923be stage2: rename and move files related to LLVM backend 2021-01-06 10:52:20 +01:00
Andrew Kelley
3e39d0c44f minor fixups from moving identifiers and files around 2021-01-05 17:41:22 -07:00