Skip to content

Commit 851a7a1

Browse files
committed
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!
1 parent 93da715 commit 851a7a1

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

CMakeLists.txt

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ set(ZIG_CPP_SOURCES
205205
)
206206
# Needed because we use cmake, not the zig build system, to build zig2.o.
207207
set(ZIG_STAGE2_SOURCES
208+
"${ZIG_CONFIG_ZIG_OUT}"
208209
"${CMAKE_SOURCE_DIR}/lib/std/array_hash_map.zig"
209210
"${CMAKE_SOURCE_DIR}/lib/std/array_list.zig"
210211
"${CMAKE_SOURCE_DIR}/lib/std/ascii.zig"
@@ -761,10 +762,83 @@ add_custom_command(
761762
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
762763
)
763764

764-
765765
add_executable(zig2 ${ZIG2_C_SOURCE} ${ZIG_COMPILER_RT_C_SOURCE})
766766
set_target_properties(zig2 PROPERTIES
767767
COMPILE_FLAGS ${ZIG2_COMPILE_FLAGS}
768768
LINK_FLAGS ${ZIG2_LINK_FLAGS}
769769
)
770770
target_include_directories(zig2 PUBLIC "${CMAKE_SOURCE_DIR}/lib")
771+
target_link_libraries(zig2 LINK_PUBLIC zigcpp)
772+
773+
if(MSVC)
774+
target_link_libraries(zig2 ntdll.lib)
775+
elseif(MINGW)
776+
target_link_libraries(zig2 ntdll)
777+
endif()
778+
779+
if(NOT MSVC)
780+
target_link_libraries(zig2 LINK_PUBLIC ${LIBXML2})
781+
endif()
782+
783+
if(ZIG_DIA_GUIDS_LIB)
784+
target_link_libraries(zig2 LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
785+
endif()
786+
787+
if(MSVC OR MINGW)
788+
target_link_libraries(zig2 LINK_PUBLIC version)
789+
endif()
790+
791+
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
792+
set(ZIG_RELEASE_ARG "")
793+
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
794+
set(ZIG_RELEASE_ARG -Drelease)
795+
else()
796+
set(ZIG_RELEASE_ARG -Drelease -Dstrip)
797+
endif()
798+
if(ZIG_NO_LIB)
799+
set(ZIG_NO_LIB_ARG "-Dno-lib")
800+
else()
801+
set(ZIG_NO_LIB_ARG "")
802+
endif()
803+
if(ZIG_SINGLE_THREADED)
804+
set(ZIG_SINGLE_THREADED_ARG "-fsingle-threaded")
805+
else()
806+
set(ZIG_SINGLE_THREADED_ARG "")
807+
endif()
808+
if(ZIG_STATIC)
809+
set(ZIG_STATIC_ARG "-Duse-zig-libcxx")
810+
else()
811+
set(ZIG_STATIC_ARG "")
812+
endif()
813+
814+
set(ZIG_BUILD_ARGS
815+
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
816+
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
817+
"-Denable-llvm"
818+
${ZIG_RELEASE_ARG}
819+
${ZIG_STATIC_ARG}
820+
${ZIG_NO_LIB_ARG}
821+
${ZIG_SINGLE_THREADED_ARG}
822+
"-Dtarget=${ZIG_TARGET_TRIPLE}"
823+
"-Dcpu=${ZIG_TARGET_MCPU}"
824+
"-Dversion-string=${RESOLVED_ZIG_VERSION}"
825+
)
826+
827+
add_custom_target(stage3 ALL
828+
COMMAND zig2 build compile ${ZIG_BUILD_ARGS}
829+
DEPENDS zig2
830+
COMMENT STATUS "Building stage3"
831+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
832+
)
833+
834+
if(WIN32)
835+
set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2.exe")
836+
else()
837+
set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2")
838+
endif()
839+
840+
install(CODE "set(ZIG_EXECUTABLE \"${ZIG_EXECUTABLE}\")")
841+
install(CODE "set(ZIG_BUILD_ARGS \"${ZIG_BUILD_ARGS}\")")
842+
install(CODE "set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")")
843+
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
844+
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/install.cmake")

stage1/config.zig.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub const have_llvm = false;
1+
pub const have_llvm = true;
22
pub const llvm_has_m68k = false;
33
pub const llvm_has_csky = false;
44
pub const llvm_has_arc = false;
@@ -10,5 +10,5 @@ pub const enable_tracy = false;
1010
pub const value_tracing = false;
1111
pub const have_stage1 = false;
1212
pub const skip_non_native = false;
13-
pub const only_c = true;
13+
pub const only_c = false;
1414
pub const force_gpa = false;

0 commit comments

Comments
 (0)