Skip to content

Commit bf2fe0b

Browse files
committed
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.
1 parent b70e87a commit bf2fe0b

File tree

4 files changed

+486
-230
lines changed

4 files changed

+486
-230
lines changed

CMakeLists.txt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -702,29 +702,24 @@ if(MSVC)
702702
set(ZIG2_COMPILE_FLAGS "/std:c99")
703703
set(ZIG2_LINK_FLAGS "/STACK:16777216")
704704
else()
705-
#set(ZIG1_COMPILE_FLAGS "-std=c99 -O2 -march=native")
706-
set(ZIG1_COMPILE_FLAGS "-std=c99 -march=native")
705+
set(ZIG1_COMPILE_FLAGS "-std=c99 -O2 -march=native")
707706
set(ZIG2_COMPILE_FLAGS "-std=c99 -O2 -march=native")
708707
set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
709708
endif()
710709

711710
add_executable(zig1 ${STAGE1_SOURCES})
712711
set_target_properties(zig1 PROPERTIES COMPILE_FLAGS ${ZIG1_COMPILE_FLAGS})
713-
#target_include_directories(zig1 PUBLIC "${CMAKE_SOURCE_DIR}/lib")
714712
target_link_libraries(zig1 LINK_PUBLIC m)
715713

716714

717715
set(ZIG2_C_SOURCE "${CMAKE_BINARY_DIR}/zig2.c")
718716
set(BUILD_ZIG2_ARGS
719717
"${CMAKE_SOURCE_DIR}/lib"
720-
"${CMAKE_BINARY_DIR}/zig1-cache"
718+
"${CMAKE_BINARY_DIR}"
719+
zig2
721720
"${CMAKE_SOURCE_DIR}/stage1/zig1.wasm"
722721
build-exe src/main.zig -ofmt=c -lc
723-
--name zig2
724-
--pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
725-
--pkg-end
726722
-target x86_64-linux-musl # TODO: autodetect in zig1.c
727-
--color on # TODO: autodetect in zig1.c
728723
-OReleaseFast
729724
)
730725

@@ -739,12 +734,11 @@ add_custom_command(
739734
set(ZIG_COMPILER_RT_C_SOURCE "${CMAKE_BINARY_DIR}/compiler_rt.c")
740735
set(BUILD_COMPILER_RT_ARGS
741736
"${CMAKE_SOURCE_DIR}/lib"
742-
"${CMAKE_BINARY_DIR}/zig1-cache"
737+
"${CMAKE_BINARY_DIR}"
738+
compiler_rt
743739
"${CMAKE_SOURCE_DIR}/stage1/zig1.wasm"
744740
build-obj lib/compiler_rt.zig -ofmt=c
745-
--name compiler_rt
746741
-target x86_64-linux-musl # TODO: autodetect in zig1.c
747-
--color on # TODO: autodetect in zig1.c
748742
-OReleaseFast
749743
)
750744

@@ -757,13 +751,9 @@ add_custom_command(
757751
)
758752

759753

760-
add_executable(zig2 ${ZIG2_C_SOURCE})
754+
add_executable(zig2 ${ZIG2_C_SOURCE} ${ZIG_COMPILER_RT_C_SOURCE})
761755
set_target_properties(zig2 PROPERTIES
762756
COMPILE_FLAGS ${ZIG2_COMPILE_FLAGS}
763757
LINK_FLAGS ${ZIG2_LINK_FLAGS}
764758
)
765-
766-
767-
768-
769-
759+
target_include_directories(zig2 PUBLIC "${CMAKE_SOURCE_DIR}/lib")

lib/compiler_rt.zig

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
pub const panic = @import("compiler_rt/common.zig").panic;
22

33
comptime {
4-
_ = @import("compiler_rt/atomics.zig");
5-
64
_ = @import("compiler_rt/addf3.zig");
75
_ = @import("compiler_rt/addhf3.zig");
86
_ = @import("compiler_rt/addsf3.zig");
@@ -209,9 +207,13 @@ comptime {
209207
_ = @import("compiler_rt/aullrem.zig");
210208
_ = @import("compiler_rt/clear_cache.zig");
211209

212-
_ = @import("compiler_rt/memcpy.zig");
213-
_ = @import("compiler_rt/memset.zig");
214-
_ = @import("compiler_rt/memmove.zig");
215-
_ = @import("compiler_rt/memcmp.zig");
216-
_ = @import("compiler_rt/bcmp.zig");
210+
if (@import("builtin").object_format != .c) {
211+
_ = @import("compiler_rt/atomics.zig");
212+
213+
_ = @import("compiler_rt/memcpy.zig");
214+
_ = @import("compiler_rt/memset.zig");
215+
_ = @import("compiler_rt/memmove.zig");
216+
_ = @import("compiler_rt/memcmp.zig");
217+
_ = @import("compiler_rt/bcmp.zig");
218+
}
217219
}

stage1/config.zig.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ pub const value_tracing = false;
1111
pub const have_stage1 = false;
1212
pub const skip_non_native = false;
1313
pub const only_c = true;
14+
pub const force_gpa = false;

0 commit comments

Comments
 (0)