Skip to content

Commit c51288f

Browse files
committed
remove the zstd mechanism from the build process
1 parent 9d93b2c commit c51288f

36 files changed

+14
-20644
lines changed

CMakeLists.txt

+4-18
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,6 @@ set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")
181181

182182
set(ZIG_WASM2C_SOURCES
183183
"${CMAKE_SOURCE_DIR}/stage1/wasm2c.c"
184-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/huf_decompress.c"
185-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/zstd_ddict.c"
186-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/zstd_decompress.c"
187-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/decompress/zstd_decompress_block.c"
188-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/entropy_common.c"
189-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/error_private.c"
190-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/fse_decompress.c"
191-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/pool.c"
192-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/xxhash.c"
193-
"${CMAKE_SOURCE_DIR}/stage1/zstd/lib/common/zstd_common.c"
194184
)
195185
set(ZIG_CPP_SOURCES
196186
# These are planned to stay even when we are self-hosted.
@@ -738,21 +728,19 @@ else()
738728
endif()
739729
endif()
740730

741-
set(ZIG1_WASM_ZST_SOURCE "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst")
731+
set(ZIG1_WASM_MODULE "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm")
742732
set(ZIG1_C_SOURCE "${CMAKE_BINARY_DIR}/zig1.c")
743733
set(ZIG2_C_SOURCE "${CMAKE_BINARY_DIR}/zig2.c")
744734
set(ZIG_COMPILER_RT_C_SOURCE "${CMAKE_BINARY_DIR}/compiler_rt.c")
745735

746736
add_executable(zig-wasm2c ${ZIG_WASM2C_SOURCES})
747737
set_target_properties(zig-wasm2c PROPERTIES COMPILE_FLAGS "${ZIG_WASM2C_COMPILE_FLAGS}")
748-
target_include_directories(zig-wasm2c PUBLIC "${CMAKE_SOURCE_DIR}/stage1/zstd/lib")
749-
target_compile_definitions(zig-wasm2c PRIVATE ZSTD_DISABLE_ASM)
750738

751739
add_custom_command(
752740
OUTPUT "${ZIG1_C_SOURCE}"
753-
COMMAND zig-wasm2c "${ZIG1_WASM_ZST_SOURCE}" "${ZIG1_C_SOURCE}"
754-
DEPENDS zig-wasm2c "${ZIG1_WASM_ZST_SOURCE}"
755-
COMMENT STATUS "Converting ${ZIG1_WASM_ZST_SOURCE} to ${ZIG1_C_SOURCE}"
741+
COMMAND zig-wasm2c "${ZIG1_WASM_MODULE}" "${ZIG1_C_SOURCE}"
742+
DEPENDS zig-wasm2c "${ZIG1_WASM_MODULE}"
743+
COMMENT STATUS "Converting ${ZIG1_WASM_MODULE} to ${ZIG1_C_SOURCE}"
756744
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
757745
)
758746

@@ -764,8 +752,6 @@ if(MSVC)
764752
else()
765753
target_link_libraries(zig1 LINK_PUBLIC m)
766754
endif()
767-
target_include_directories(zig1 PUBLIC "${CMAKE_SOURCE_DIR}/stage1/zstd/lib")
768-
target_compile_definitions(zig1 PRIVATE ZSTD_DISABLE_ASM)
769755

770756
set(BUILD_ZIG2_ARGS
771757
"${CMAKE_SOURCE_DIR}/lib"

build.zig

+2-11
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,8 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void {
502502
run_opt.addArg("-o");
503503
run_opt.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
504504

505-
const run_zstd = b.addSystemCommand(&.{ "zstd", "-19", "-f" });
506-
run_zstd.step.dependOn(&run_opt.step);
507-
run_zstd.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
508-
run_zstd.addArg("-o");
509-
run_zstd.addFileSourceArg(.{ .path = "stage1/zig1.wasm.zst" });
510-
511-
const cleanup = b.addRemoveDirTree("stage1/zig1.wasm");
512-
cleanup.step.dependOn(&run_zstd.step);
513-
514-
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm.zst");
515-
update_zig1_step.dependOn(&cleanup.step);
505+
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
506+
update_zig1_step.dependOn(&run_opt.step);
516507
}
517508

518509
fn addCompilerStep(b: *Builder) *std.build.LibExeObjStep {

stage1/InputStream.h

+8-53
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,35 @@
44
#include "panic.h"
55
#include "wasm.h"
66

7-
#include <zstd.h>
8-
97
#include <assert.h>
108
#include <stdbool.h>
119
#include <stdint.h>
1210
#include <stdio.h>
1311
#include <stdlib.h>
1412
#include <string.h>
13+
#include <stddef.h>
1514

1615
struct InputStream {
1716
FILE *stream;
18-
ZSTD_DStream *ds;
19-
ZSTD_outBuffer out;
20-
ZSTD_inBuffer in;
21-
size_t pos;
2217
};
2318

2419
static void InputStream_open(struct InputStream *self, const char *path) {
2520
self->stream = fopen(path, "rb");
2621
if (self->stream == NULL) panic("unable to open input file");
27-
self->ds = ZSTD_createDStream();
28-
if (self->ds == NULL) panic("unable to create zstd context");
29-
size_t in_size = ZSTD_initDStream(self->ds);
30-
if (ZSTD_isError(in_size)) panic(ZSTD_getErrorName(in_size));
31-
self->out.size = ZSTD_DStreamOutSize();
32-
self->out.dst = malloc(self->out.size + ZSTD_DStreamInSize());
33-
if (self->out.dst == NULL) panic("unable to allocate input buffers");
34-
self->out.pos = 0;
35-
self->in.src = (const char *)self->out.dst + self->out.size;
36-
self->in.size = fread((void *)self->in.src, 1, in_size, self->stream);
37-
self->in.pos = 0;
38-
self->pos = 0;
3922
}
4023

4124
static void InputStream_close(struct InputStream *self) {
42-
free(self->out.dst);
43-
ZSTD_freeDStream(self->ds);
4425
fclose(self->stream);
4526
}
4627

4728
static bool InputStream_atEnd(struct InputStream *self) {
48-
while (self->pos >= self->out.pos) {
49-
self->out.pos = 0;
50-
self->pos = 0;
51-
size_t in_size = ZSTD_decompressStream(self->ds, &self->out, &self->in);
52-
if (ZSTD_isError(in_size)) panic(ZSTD_getErrorName(in_size));
53-
if (self->in.pos >= self->in.size) {
54-
size_t max_in_size = ZSTD_DStreamInSize();
55-
if (in_size > max_in_size) in_size = max_in_size;
56-
self->in.size = fread((void *)self->in.src, 1, in_size, self->stream);
57-
self->in.pos = 0;
58-
if (self->in.pos >= self->in.size) return true;
59-
}
60-
}
61-
return false;
29+
return feof(self->stream) != 0;
6230
}
6331

6432
static uint8_t InputStream_readByte(struct InputStream *self) {
65-
if (InputStream_atEnd(self)) panic("unexpected end of input stream");
66-
uint8_t value = ((uint8_t *)self->out.dst)[self->pos];
67-
self->pos += 1;
33+
int value;
34+
value = fgetc(self->stream);
35+
if (value == EOF) panic("unexpected end of input stream");
6836
return value;
6937
}
7038

@@ -168,26 +136,13 @@ static char *InputStream_readName(struct InputStream *self) {
168136
uint32_t len = InputStream_readLeb128_u32(self);
169137
char *name = malloc(len + 1);
170138
if (name == NULL) panic("out of memory");
171-
for (uint32_t i = 0; i < len; ) {
172-
if (InputStream_atEnd(self)) panic("unexpected end of input stream");
173-
size_t remaining = self->out.pos - self->pos;
174-
if (remaining > len - i) remaining = len - i;
175-
memcpy(&name[i], &((char *)self->out.dst)[self->pos], remaining);
176-
i += remaining;
177-
self->pos += remaining;
178-
}
179-
name[len] = '\0';
139+
if (fread(name, 1, len, self->stream) != len) panic("unexpected end of input stream");
140+
name[len] = 0;
180141
return name;
181142
}
182143

183144
static void InputStream_skipBytes(struct InputStream *self, size_t len) {
184-
for (size_t i = 0; i < len; ) {
185-
if (InputStream_atEnd(self)) panic("unexpected end of input stream");
186-
size_t remaining = self->out.pos - self->pos;
187-
if (remaining > len - i) remaining = len - i;
188-
i += remaining;
189-
self->pos += remaining;
190-
}
145+
if (fseek(self->stream, len, SEEK_CUR) == -1) panic("unexpected end of input stream");
191146
}
192147

193148
static uint32_t InputStream_skipToSection(struct InputStream *self, uint8_t expected_id) {

stage1/zstd/LICENSE

-30
This file was deleted.

0 commit comments

Comments
 (0)