Commit Graph

21551 Commits

Author SHA1 Message Date
Andrew Kelley
823d1e7087 add std.heap.wasm_allocator 2022-12-06 12:27:28 -07:00
Jacob Young
4a701490d4 zig.h: avoid using _Float16 when __builtin_inff16 isn't available 2022-12-06 12:15:05 -07:00
Jacob Young
5dbd28f171 wasm2c: support memory.copy with overlapping buffers 2022-12-06 12:15:05 -07:00
Andrew Kelley
a3fadd2813 stage2: revert change to handling of --color on
This change has been extracted to #13786 and can be solved separately
than this branch.
2022-12-06 12:15:05 -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
e73170f972 std: fix WASI regressions
This branch largely reverts 58f961f4cb. I
would like to revisit the proposal to modify the standard library in
this way and think more carefully about it before adding isAbsolute()
checks everywhere.
2022-12-06 12:15:05 -07:00
Andrew Kelley
cb012490ee translate-c: fix wrong logic adjustment
In ea9ad1e85dd5e2ba18e7d55f7a7f9694282159f1, I incorrectly applied
boolean logic to one of the pieces of logic, resulting in a regression
in translate-c.
2022-12-06 12:15:05 -07:00
Andrew Kelley
57995c2100 translate-c: remove stage1 conditions from tests 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
bd4a1f38fa zig.h: fix shlo breakage on smaller bitwidths 2022-12-06 12:15:05 -07:00
Jacob Young
c8541f0a12 cc: remove argument parsing from only-c builds 2022-12-06 12:15:04 -07:00
Jacob Young
fad2142ecf zig.h: fix shift ub for a shlo by 0 2022-12-06 12:15:04 -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
47a2a526e2 test: remove reference to stage1 2022-12-06 12:15:04 -07:00
Jacob Young
687ea31ef9 cmake: fix host target detection 2022-12-06 12:15:04 -07:00
Jacob Young
f421efbcc1 CBE: fix bad local reuse for volatile memset 2022-12-06 12:15:04 -07:00
Jacob Young
ce4e5fee63 wasm2c: avoid aliasing issues on memory access 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
e000db2782 wasi: implement file truncation
The way this is implemented destroys the contents of the file, so
revisit if this causes issues in the future.
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
7e151cb5e9 build: remove -Dwasi-bootstrap; add update-zig1 step
Now it is a single command tdo update zig1.wasm.zst.
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
9b8cf13c00 zig1.c: remove executable bit
This was set on accident.
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
7ef745db59 Sema: queue type resolution for result of @fieldParentPtr 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
Jacob Young
906120bc2c std.fmt: more descriptive names for impl functions
This is a workaround for a limitation of the C backend.
2022-12-06 12:15:04 -07:00
Andrew Kelley
9cb06f3b8b fix merge conflicts from master branch 2022-12-06 12:15:04 -07:00
Andrew Kelley
6337808e65 update zig1.c to latest zig-wasi 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
d1b3409df1 add zstd v1.5.2
only the decompression files
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
8c1c67bdd0 stage2: take advantage of the new WasmAllocator 2022-12-06 12:15:04 -07:00
Andrew Kelley
3dcdd5544f stage2: make --color override apply to std.Progress 2022-12-06 12:15:04 -07:00
Andrew Kelley
55ca43a04c std.wasm: add Opcode.prefixed and make PrefixedOpcode nonexhaustive 2022-12-06 12:15:04 -07:00
Andrew Kelley
6b0d773266 std: clean up imports in a couple files 2022-12-06 12:15:04 -07:00
Andrew Kelley
3a8117439d allow build-obj and build-exe in -Donly-c builds 2022-12-06 12:15:04 -07:00
Andrew Kelley
d5312d53a0 WASI: remove absolute path emulation from std lib
Instead of checking for absolute paths and current working directories
in various file system operations, there is one simple solution: allow
overriding `std.fs.cwd` on WASI.

os.realpath is back to causing a compile error when used on WASI. This
caused a compile error in the Sema handling of `@src()`. The compiler
should never call realpath, so the commit that made this change is
reverted (95ab942184). If this breaks
debug info, a different strategy is needed to solve it other than using
realpath.

I also removed the preopens code and replaced it with something much
simpler. There is no longer any global state in the standard library.

Additionally-
 * os.openat no longer does an unnecessary fstat on WASI when O.WRONLY
   is not provided.
 * os.chdir is back to causing a compile error on WASI.
2022-12-06 12:15:04 -07:00
Andrew Kelley
0a2fdfbdb9 build.zig: add bulk_memory to -Dwasi-bootstrap
In theory this will enhance the performance of interpreting a WASI build
of Zig.
2022-12-06 12:15:04 -07:00
Andrew Kelley
3ba916584d actually remove stage1 2022-12-06 12:15:04 -07:00
Andrew Kelley
4e2a960b52 std.fs: fix openDirAbsolute
These functions had a compile error since the introduction of
IterableDir.
2022-12-06 12:15:04 -07:00
Andrew Kelley
db023b98a4 build: introduce -Dwasi-bootstrap option
Also, make -Donly-c prevent Autodoc from being included in the binary.

This produces a 2.6 MiB zig.wasm file. 781 KB if piped through zstd.
2022-12-06 12:15:04 -07:00