@@ -434,8 +434,8 @@ find_package(Threads)
434
434
# CMake doesn't let us create an empty executable, so we hang on to this one separately.
435
435
set (ZIG_MAIN_SRC "${CMAKE_SOURCE_DIR} /src/main.cpp" )
436
436
437
- # This is our shim which will be replaced by libuserland written in Zig.
438
- set (ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR} /src/userland .cpp" )
437
+ # This is our shim which will be replaced by libstage2 written in Zig.
438
+ set (ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR} /src/stage2 .cpp" )
439
439
440
440
if (ZIG_ENABLE_MEM_PROFILE)
441
441
set (ZIG_SOURCES_MEM_PROFILE "${CMAKE_SOURCE_DIR} /src/mem_profile.cpp" )
@@ -457,7 +457,6 @@ set(ZIG_SOURCES
457
457
"${CMAKE_SOURCE_DIR} /src/heap.cpp"
458
458
"${CMAKE_SOURCE_DIR} /src/ir.cpp"
459
459
"${CMAKE_SOURCE_DIR} /src/ir_print.cpp"
460
- "${CMAKE_SOURCE_DIR} /src/libc_installation.cpp"
461
460
"${CMAKE_SOURCE_DIR} /src/link.cpp"
462
461
"${CMAKE_SOURCE_DIR} /src/mem.cpp"
463
462
"${CMAKE_SOURCE_DIR} /src/os.cpp"
@@ -566,12 +565,12 @@ set_target_properties(opt_c_util PROPERTIES
566
565
COMPILE_FLAGS "${OPTIMIZED_C_FLAGS} "
567
566
)
568
567
569
- add_library (compiler STATIC ${ZIG_SOURCES} )
570
- set_target_properties (compiler PROPERTIES
568
+ add_library (zigcompiler STATIC ${ZIG_SOURCES} )
569
+ set_target_properties (zigcompiler PROPERTIES
571
570
COMPILE_FLAGS ${EXE_CFLAGS}
572
571
LINK_FLAGS ${EXE_LDFLAGS}
573
572
)
574
- target_link_libraries (compiler LINK_PUBLIC
573
+ target_link_libraries (zigcompiler LINK_PUBLIC
575
574
zig_cpp
576
575
opt_c_util
577
576
${SOFTFLOAT_LIBRARIES}
@@ -581,56 +580,58 @@ target_link_libraries(compiler LINK_PUBLIC
581
580
${CMAKE_THREAD_LIBS_INIT}
582
581
)
583
582
if (NOT MSVC )
584
- target_link_libraries (compiler LINK_PUBLIC ${LIBXML2} )
583
+ target_link_libraries (zigcompiler LINK_PUBLIC ${LIBXML2} )
585
584
endif ()
586
585
587
586
if (ZIG_DIA_GUIDS_LIB)
588
- target_link_libraries (compiler LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB} )
587
+ target_link_libraries (zigcompiler LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB} )
589
588
endif ()
590
589
591
590
if (MSVC OR MINGW)
592
- target_link_libraries (compiler LINK_PUBLIC version )
591
+ target_link_libraries (zigcompiler LINK_PUBLIC version )
593
592
endif ()
594
593
595
594
add_executable (zig0 "${ZIG_MAIN_SRC} " "${ZIG0_SHIM_SRC} " )
596
595
set_target_properties (zig0 PROPERTIES
597
596
COMPILE_FLAGS ${EXE_CFLAGS}
598
597
LINK_FLAGS ${EXE_LDFLAGS}
599
598
)
600
- target_link_libraries (zig0 compiler )
599
+ target_link_libraries (zig0 zigcompiler )
601
600
602
601
if (MSVC )
603
- set (LIBUSERLAND "${CMAKE_BINARY_DIR} /userland .lib" )
602
+ set (LIBSTAGE2 "${CMAKE_BINARY_DIR} /zigstage2 .lib" )
604
603
else ()
605
- set (LIBUSERLAND "${CMAKE_BINARY_DIR} /libuserland .a" )
604
+ set (LIBSTAGE2 "${CMAKE_BINARY_DIR} /libzigstage2 .a" )
606
605
endif ()
607
606
if ("${CMAKE_BUILD_TYPE} " STREQUAL "Debug" )
608
- set (LIBUSERLAND_RELEASE_MODE "false " )
607
+ set (LIBSTAGE2_RELEASE_ARG " " )
609
608
else ()
610
- set (LIBUSERLAND_RELEASE_MODE "true" )
609
+ set (LIBSTAGE2_RELEASE_ARG --release-fast --strip)
610
+ endif ()
611
+ if (WIN32 )
612
+ set (LIBSTAGE2_WINDOWS_ARGS "-lntdll" )
613
+ else ()
614
+ set (LIBSTAGE2_WINDOWS_ARGS "" )
611
615
endif ()
612
616
613
- set (BUILD_LIBUSERLAND_ARGS "build"
617
+ set (BUILD_LIBSTAGE2_ARGS "build-lib"
618
+ "src-self-hosted/stage2.zig"
619
+ --name zigstage2
614
620
--override-lib-dir "${CMAKE_SOURCE_DIR} /lib"
615
- "-Doutput-dir=${CMAKE_BINARY_DIR} "
616
- "-Drelease=${LIBUSERLAND_RELEASE_MODE} "
617
- "-Dlib-files-only"
618
- --prefix "${CMAKE_INSTALL_PREFIX} "
619
- libuserland
621
+ --cache on
622
+ --output -dir "${CMAKE_BINARY_DIR} "
623
+ ${LIBSTAGE2_RELEASE_ARG}
624
+ --disable-gen-h
625
+ --bundle -compiler-rt
626
+ -fPIC
627
+ -lc
628
+ ${LIBSTAGE2_WINDOWS_ARGS}
620
629
)
621
630
622
- # When using Visual Studio build system generator we default to libuserland install.
623
- if (MSVC )
624
- set (ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix" )
625
- if (NOT ZIG_SKIP_INSTALL_LIB_FILES)
626
- set (BUILD_LIBUSERLAND_ARGS ${BUILD_LIBUSERLAND_ARGS} install )
627
- endif ()
628
- endif ()
629
-
630
- add_custom_target (zig_build_libuserland ALL
631
- COMMAND zig0 ${BUILD_LIBUSERLAND_ARGS}
631
+ add_custom_target (zig_build_libstage2 ALL
632
+ COMMAND zig0 ${BUILD_LIBSTAGE2_ARGS}
632
633
DEPENDS zig0
633
- BYPRODUCTS "${LIBUSERLAND } "
634
+ BYPRODUCTS "${LIBSTAGE2 } "
634
635
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR} "
635
636
)
636
637
add_executable (zig "${ZIG_MAIN_SRC} " )
@@ -639,22 +640,40 @@ set_target_properties(zig PROPERTIES
639
640
COMPILE_FLAGS ${EXE_CFLAGS}
640
641
LINK_FLAGS ${EXE_LDFLAGS}
641
642
)
642
- target_link_libraries (zig compiler "${LIBUSERLAND } " )
643
+ target_link_libraries (zig zigcompiler "${LIBSTAGE2 } " )
643
644
if (MSVC )
644
645
target_link_libraries (zig ntdll.lib)
645
646
elseif (MINGW)
646
647
target_link_libraries (zig ntdll)
647
648
endif ()
648
- add_dependencies (zig zig_build_libuserland )
649
+ add_dependencies (zig zig_build_libstage2 )
649
650
650
651
install (TARGETS zig DESTINATION bin)
651
652
652
- # CODE has no effect with Visual Studio build system generator.
653
- if (NOT MSVC )
654
- get_target_property (zig0_BINARY_DIR zig0 BINARY_DIR)
655
- install (CODE "set(zig0_EXE \" ${zig0_BINARY_DIR} /zig0\" )" )
656
- install (CODE "set(INSTALL_LIBUSERLAND_ARGS \" ${BUILD_LIBUSERLAND_ARGS} \" install)" )
657
- install (CODE "set(BUILD_LIBUSERLAND_ARGS \" ${BUILD_LIBUSERLAND_ARGS} \" )" )
653
+ set (ZIG_INSTALL_ARGS "build"
654
+ --override-lib-dir "${CMAKE_SOURCE_DIR} /lib"
655
+ "-Dlib-files-only"
656
+ --prefix "${CMAKE_INSTALL_PREFIX} "
657
+ install
658
+ )
659
+
660
+ # CODE has no effect with Visual Studio build system generator, therefore
661
+ # when using Visual Studio build system generator we resort to running
662
+ # `zig build install` during the build phase.
663
+ if (MSVC )
664
+ set (ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL
665
+ "Windows-only: Disable copying lib/ files to install prefix during the build phase" )
666
+ if (NOT ZIG_SKIP_INSTALL_LIB_FILES)
667
+ add_custom_target (zig_install_lib_files ALL
668
+ COMMAND zig ${ZIG_INSTALL_ARGS}
669
+ DEPENDS zig
670
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR} "
671
+ )
672
+ endif ()
673
+ else ()
674
+ get_target_property (zig_BINARY_DIR zig BINARY_DIR)
675
+ install (CODE "set(zig_EXE \" ${zig_BINARY_DIR} /zig\" )" )
676
+ install (CODE "set(ZIG_INSTALL_ARGS \" ${ZIG_INSTALL_ARGS} \" )" )
658
677
install (CODE "set(CMAKE_SOURCE_DIR \" ${CMAKE_SOURCE_DIR} \" )" )
659
678
install (SCRIPT ${CMAKE_CURRENT_SOURCE_DIR} /cmake/install .cmake)
660
679
endif ()
0 commit comments