2016-02-01 22:26:01 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.5)
|
2015-08-05 22:23:15 +00:00
|
|
|
|
2020-05-26 13:36:55 +00:00
|
|
|
# Use ccache if possible
|
|
|
|
FIND_PROGRAM(CCACHE_PROGRAM ccache)
|
|
|
|
IF(CCACHE_PROGRAM)
|
|
|
|
MESSAGE(STATUS "Found ccache ${CCACHE_PROGRAM}")
|
|
|
|
ENDIF()
|
|
|
|
|
2016-02-01 22:26:01 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
|
2020-02-05 13:24:50 +00:00
|
|
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
2016-02-01 22:26:01 +00:00
|
|
|
endif()
|
2015-08-05 22:23:15 +00:00
|
|
|
|
2018-04-11 00:57:37 +00:00
|
|
|
if(NOT CMAKE_INSTALL_PREFIX)
|
2019-06-23 01:21:48 +00:00
|
|
|
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE STRING
|
2018-04-11 00:57:37 +00:00
|
|
|
"Directory to install zig to" FORCE)
|
|
|
|
endif()
|
|
|
|
|
2019-10-10 20:44:52 +00:00
|
|
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)
|
|
|
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake)
|
|
|
|
|
2017-04-21 15:06:15 +00:00
|
|
|
project(zig C CXX)
|
2015-08-05 22:23:15 +00:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
|
|
|
|
2015-08-05 22:46:40 +00:00
|
|
|
set(ZIG_VERSION_MAJOR 0)
|
2020-11-08 19:02:09 +00:00
|
|
|
set(ZIG_VERSION_MINOR 7)
|
2018-03-15 13:15:05 +00:00
|
|
|
set(ZIG_VERSION_PATCH 0)
|
2020-10-04 11:41:05 +00:00
|
|
|
set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.")
|
|
|
|
|
|
|
|
if("${ZIG_VERSION}" STREQUAL "")
|
|
|
|
set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}")
|
|
|
|
find_program(GIT_EXE NAMES git)
|
|
|
|
if(GIT_EXE)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} name-rev HEAD --tags --name-only --no-undefined --always
|
|
|
|
RESULT_VARIABLE EXIT_STATUS
|
|
|
|
OUTPUT_VARIABLE ZIG_GIT_REV
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET)
|
|
|
|
if(EXIT_STATUS EQUAL "0")
|
|
|
|
if(ZIG_GIT_REV MATCHES "\\^0$")
|
|
|
|
if(NOT("${ZIG_GIT_REV}" STREQUAL "${ZIG_VERSION}^0"))
|
|
|
|
message("WARNING: Tag does not match configured Zig version")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(ZIG_VERSION "${ZIG_VERSION}+${ZIG_GIT_REV}")
|
2019-09-02 21:45:30 +00:00
|
|
|
endif()
|
2017-10-01 22:34:22 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
2015-08-05 22:23:15 +00:00
|
|
|
message("Configuring zig version ${ZIG_VERSION}")
|
|
|
|
|
2018-03-30 17:20:13 +00:00
|
|
|
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
|
2019-07-09 09:03:57 +00:00
|
|
|
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
|
2020-04-10 05:25:15 +00:00
|
|
|
set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
|
2020-05-26 13:36:55 +00:00
|
|
|
set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache if available")
|
|
|
|
|
|
|
|
if(CCACHE_PROGRAM AND ZIG_USE_CCACHE)
|
|
|
|
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
|
|
|
endif()
|
2019-07-09 09:03:57 +00:00
|
|
|
|
|
|
|
if(ZIG_STATIC)
|
|
|
|
set(ZIG_STATIC_LLVM "on")
|
2020-10-04 06:15:45 +00:00
|
|
|
set(ZIG_LINK_MODE "Static")
|
|
|
|
else()
|
|
|
|
set(ZIG_LINK_MODE "Dynamic")
|
2019-07-09 09:03:57 +00:00
|
|
|
endif()
|
2016-02-11 08:33:27 +00:00
|
|
|
|
2017-10-01 20:10:05 +00:00
|
|
|
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
|
|
|
|
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_STATIC_LIB_DIR_ESCAPED "${ZIG_LIBC_STATIC_LIB_DIR}")
|
|
|
|
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_INCLUDE_DIR_ESCAPED "${ZIG_LIBC_INCLUDE_DIR}")
|
2017-10-01 18:01:18 +00:00
|
|
|
|
2016-04-23 16:57:38 +00:00
|
|
|
option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF)
|
|
|
|
|
2020-03-28 03:43:21 +00:00
|
|
|
set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for")
|
2020-04-08 21:41:51 +00:00
|
|
|
set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries for")
|
2020-03-28 03:43:21 +00:00
|
|
|
set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
|
2020-09-20 21:55:43 +00:00
|
|
|
set(ZIG_PREFER_LLVM_CONFIG off CACHE BOOL "(when cross compiling) use llvm-config to find target llvm dependencies if needed")
|
2020-03-28 03:43:21 +00:00
|
|
|
|
2017-09-13 04:17:19 +00:00
|
|
|
find_package(llvm)
|
|
|
|
find_package(clang)
|
2020-01-16 18:09:45 +00:00
|
|
|
find_package(lld)
|
2016-01-19 04:28:54 +00:00
|
|
|
|
2018-09-30 20:45:33 +00:00
|
|
|
if(APPLE AND ZIG_STATIC)
|
|
|
|
list(REMOVE_ITEM LLVM_LIBRARIES "-lz")
|
2020-10-15 00:36:43 +00:00
|
|
|
find_library(ZLIB NAMES libz.a z zlib libz)
|
2019-03-18 22:36:35 +00:00
|
|
|
list(APPEND LLVM_LIBRARIES "${ZLIB}")
|
2020-10-15 00:36:43 +00:00
|
|
|
|
|
|
|
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
|
|
|
|
find_library(CURSES NAMES libcurses.a curses libcurses libncurses.a ncurses libncurses)
|
|
|
|
list(APPEND LLVM_LIBRARIES "${CURSES}")
|
2018-03-20 11:46:31 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-23 07:00:24 +00:00
|
|
|
set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zigcpp")
|
2017-12-27 00:44:08 +00:00
|
|
|
|
2019-04-18 06:58:12 +00:00
|
|
|
# Handle multi-config builds and place each into a common lib. The VS generator
|
|
|
|
# for example will append a Debug folder by default if not explicitly specified.
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ZIG_CPP_LIB_DIR})
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ZIG_CPP_LIB_DIR})
|
|
|
|
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
string(TOUPPER ${CONFIG_TYPE} CONFIG_TYPE)
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${ZIG_CPP_LIB_DIR})
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${ZIG_CPP_LIB_DIR})
|
|
|
|
endforeach(CONFIG_TYPE CMAKE_CONFIGURATION_TYPES)
|
|
|
|
|
2020-01-16 18:09:45 +00:00
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
include_directories(${LLD_INCLUDE_DIRS})
|
|
|
|
include_directories(${CLANG_INCLUDE_DIRS})
|
2017-03-13 15:54:56 +00:00
|
|
|
|
2018-03-09 20:06:06 +00:00
|
|
|
# No patches have been applied to SoftFloat-3e
|
2017-09-14 05:44:22 +00:00
|
|
|
set(EMBEDDED_SOFTFLOAT_SOURCES
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c"
|
2018-06-27 14:20:04 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c"
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c"
|
2018-06-27 14:20:04 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c"
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c"
|
2018-06-27 14:20:04 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c"
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_add.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_div.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_eq.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_eq_signaling.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_le.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_le_quiet.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_lt.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_lt_quiet.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_mul.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_mulAdd.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_rem.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_roundToInt.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_sqrt.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_sub.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_f16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_f32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_f64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i64_r_minMag.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c"
|
2018-06-27 14:20:04 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_add.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_div.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_eq.c"
|
2019-04-05 02:07:15 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_isSignalingNaN.c"
|
2018-06-27 14:20:04 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_lt.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_mul.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_rem.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_roundToInt.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_sqrt.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_sub.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_to_f128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_to_f64.c"
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f32_to_f128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_f128M.c"
|
2018-06-27 14:20:04 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_f16.c"
|
2019-03-22 18:56:03 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/i32_to_f128M.c"
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_add256M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addCarryM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addComplCarryM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addMagsF16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addMagsF32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addMagsF64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_approxRecip32_1.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_approxRecipSqrt32_1.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_approxRecipSqrt_1Ks.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_approxRecip_1Ks.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_compare128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_compare96M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros8.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_eq128.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_invalidF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_isNaNF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_le128.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_lt128.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mul128MTo256M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mul64To128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mulAddF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mulAddF16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mulAddF32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mulAddF64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_negXM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackToF16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackToF32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackToF64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normSubnormalF128SigM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normSubnormalF16Sig.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normSubnormalF32Sig.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normSubnormalF64Sig.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_remStepMBy32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundMToI64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundMToUI64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackMToF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackToF16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackToF32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackToF64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundToI32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundToI64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundToUI32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundToUI64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftLeftM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftNormSigF128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftRightJam256M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftRightJam32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftRightJam64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftRightJamM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shiftRightM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shortShiftLeft64To96M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shortShiftLeftM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shortShiftRightExtendM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shortShiftRightJam64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shortShiftRightJamM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_shortShiftRightM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_sub1XM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_sub256M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_subM.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_subMagsF16.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_subMagsF32.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_subMagsF64.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c"
|
2019-06-18 22:28:49 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_mulAdd.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_mulAdd.c"
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/softfloat_state.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/ui32_to_f128M.c"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/ui64_to_f128M.c"
|
2017-09-14 05:44:22 +00:00
|
|
|
)
|
2019-08-15 18:34:52 +00:00
|
|
|
add_library(embedded_softfloat STATIC ${EMBEDDED_SOFTFLOAT_SOURCES})
|
2017-09-14 05:44:22 +00:00
|
|
|
if(MSVC)
|
|
|
|
set_target_properties(embedded_softfloat PROPERTIES
|
2020-03-31 14:13:31 +00:00
|
|
|
COMPILE_FLAGS "/w /O2"
|
2017-09-14 05:44:22 +00:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
set_target_properties(embedded_softfloat PROPERTIES
|
2018-09-10 13:46:15 +00:00
|
|
|
COMPILE_FLAGS "-std=c99 -O3"
|
2017-09-14 05:44:22 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
target_include_directories(embedded_softfloat PUBLIC
|
2018-03-09 20:06:06 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e-prebuilt"
|
|
|
|
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086"
|
2015-08-05 22:46:40 +00:00
|
|
|
)
|
2018-03-09 20:06:06 +00:00
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/include")
|
2017-09-14 05:44:22 +00:00
|
|
|
set(SOFTFLOAT_LIBRARIES embedded_softfloat)
|
|
|
|
|
|
|
|
find_package(Threads)
|
2015-08-05 22:46:40 +00:00
|
|
|
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
# This is our shim which will be replaced by stage1.zig.
|
|
|
|
set(ZIG0_SOURCES
|
2020-09-22 01:38:55 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
)
|
2019-11-24 20:29:43 +00:00
|
|
|
|
2020-09-23 07:00:24 +00:00
|
|
|
set(STAGE1_SOURCES
|
2020-09-22 01:38:55 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/analyze.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/ast_render.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/bigfloat.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/bigint.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/buffer.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/codegen.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/dump_analysis.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/errmsg.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/error.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/heap.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/ir.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/ir_print.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/mem.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/os.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/parser.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/range_set.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/stage1.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/target.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/tokenizer.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/util.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/softfloat_ext.cpp"
|
2017-12-27 00:44:08 +00:00
|
|
|
)
|
2019-03-22 18:56:03 +00:00
|
|
|
set(OPTIMIZED_C_SOURCES
|
2020-09-22 01:38:55 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/parse_f128.c"
|
2018-09-10 13:46:15 +00:00
|
|
|
)
|
2017-12-27 00:44:08 +00:00
|
|
|
set(ZIG_CPP_SOURCES
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
# These are planned to stay even when we are self-hosted.
|
2015-11-24 20:00:38 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
|
2019-02-16 20:14:51 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/zig_clang.cpp"
|
2019-02-24 17:53:28 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/zig_clang_driver.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/zig_clang_cc1_main.cpp"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/zig_clang_cc1as_main.cpp"
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
# https://github.com/ziglang/zig/issues/6363
|
2018-07-21 03:37:37 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
|
2015-08-05 22:23:15 +00:00
|
|
|
)
|
2020-11-11 15:12:17 +00:00
|
|
|
# Needed because we use cmake, not the zig build system, to build zig1.o.
|
|
|
|
set(ZIG_STAGE2_SOURCES
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/main.zig"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/Module.zig"
|
|
|
|
)
|
2015-08-05 22:23:15 +00:00
|
|
|
|
2018-01-05 03:46:26 +00:00
|
|
|
if(MSVC)
|
|
|
|
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
|
2019-06-23 01:21:48 +00:00
|
|
|
if(IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
|
2018-01-05 03:46:26 +00:00
|
|
|
set(ZIG_DIA_GUIDS_LIB "${MSVC_DIA_SDK_DIR}/lib/amd64/diaguids.lib")
|
|
|
|
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_DIA_GUIDS_LIB_ESCAPED "${ZIG_DIA_GUIDS_LIB}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-10-01 22:29:50 +00:00
|
|
|
set(ZIG_LIB_DIR "lib/zig")
|
|
|
|
set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")
|
2019-03-05 03:15:53 +00:00
|
|
|
set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
|
2019-03-06 03:45:41 +00:00
|
|
|
set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
|
|
|
|
set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
|
2017-10-01 22:29:50 +00:00
|
|
|
set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
|
2020-04-06 17:07:19 +00:00
|
|
|
set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
|
2020-08-18 00:06:23 +00:00
|
|
|
set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")
|
2015-08-05 22:23:15 +00:00
|
|
|
configure_file (
|
2020-09-22 01:38:55 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1/config.h.in"
|
2020-04-06 17:07:19 +00:00
|
|
|
"${ZIG_CONFIG_H_OUT}"
|
2015-08-05 22:23:15 +00:00
|
|
|
)
|
2020-08-18 00:06:23 +00:00
|
|
|
configure_file (
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/config.zig.in"
|
|
|
|
"${ZIG_CONFIG_ZIG_OUT}"
|
|
|
|
)
|
2015-08-05 22:23:15 +00:00
|
|
|
|
2015-11-26 08:29:52 +00:00
|
|
|
include_directories(
|
|
|
|
${CMAKE_SOURCE_DIR}
|
|
|
|
${CMAKE_BINARY_DIR}
|
|
|
|
"${CMAKE_SOURCE_DIR}/src"
|
2020-09-22 01:38:55 +00:00
|
|
|
"${CMAKE_SOURCE_DIR}/src/stage1"
|
2015-11-26 08:29:52 +00:00
|
|
|
)
|
|
|
|
|
2018-09-05 16:10:53 +00:00
|
|
|
# These have to go before the -Wno- flags
|
2020-03-31 14:13:31 +00:00
|
|
|
if(MSVC)
|
|
|
|
set(EXE_CFLAGS "/std:c++14")
|
|
|
|
else(MSVC)
|
|
|
|
set(EXE_CFLAGS "-std=c++14")
|
|
|
|
endif(MSVC)
|
|
|
|
|
2018-09-05 14:18:12 +00:00
|
|
|
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
|
|
|
if(MSVC)
|
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS} /w")
|
|
|
|
else()
|
2020-05-17 08:31:19 +00:00
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall")
|
2020-05-17 20:38:26 +00:00
|
|
|
# fallthrough support was added in GCC 7.0
|
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0)
|
2020-05-17 08:31:19 +00:00
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS} -Werror=implicit-fallthrough")
|
|
|
|
endif()
|
2018-09-05 14:18:12 +00:00
|
|
|
endif()
|
2016-02-17 03:34:45 +00:00
|
|
|
endif()
|
|
|
|
|
2017-09-13 04:17:19 +00:00
|
|
|
if(MSVC)
|
2019-06-23 01:21:48 +00:00
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS}")
|
2017-09-13 04:17:19 +00:00
|
|
|
else()
|
2020-07-25 00:01:52 +00:00
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=type-limits -Wno-missing-braces -Wno-comment")
|
2019-06-23 01:21:48 +00:00
|
|
|
if(MINGW)
|
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-format")
|
|
|
|
endif()
|
2017-09-10 20:05:18 +00:00
|
|
|
endif()
|
2017-09-13 04:17:19 +00:00
|
|
|
|
2020-03-31 14:13:31 +00:00
|
|
|
if(MSVC)
|
|
|
|
set(OPTIMIZED_C_FLAGS "/O2")
|
|
|
|
else(MSVC)
|
|
|
|
set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
|
|
|
|
endif(MSVC)
|
2018-09-05 14:18:12 +00:00
|
|
|
|
2016-04-23 16:57:38 +00:00
|
|
|
set(EXE_LDFLAGS " ")
|
2019-03-27 05:54:46 +00:00
|
|
|
if(MSVC)
|
2019-07-26 21:26:01 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} /STACK:16777216")
|
2019-09-08 10:07:23 +00:00
|
|
|
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
|
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} /debug:fastlink")
|
|
|
|
endif()
|
2020-03-28 03:43:21 +00:00
|
|
|
elseif(MINGW)
|
2019-06-23 06:15:04 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} -Wl,--stack,16777216")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(ZIG_STATIC)
|
2018-09-27 19:07:51 +00:00
|
|
|
if(APPLE)
|
2019-07-26 21:26:01 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++")
|
2019-07-13 22:44:05 +00:00
|
|
|
elseif(MINGW)
|
2019-07-26 21:26:01 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic, -lwinpthread -lz3 -lz -lgomp")
|
2019-07-27 22:54:20 +00:00
|
|
|
elseif(NOT MSVC)
|
2019-07-26 21:26:01 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} -static")
|
2018-09-27 19:07:51 +00:00
|
|
|
endif()
|
2019-07-26 21:26:01 +00:00
|
|
|
else()
|
|
|
|
if(MINGW)
|
2020-04-06 19:42:04 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS}")
|
2020-03-28 03:43:21 +00:00
|
|
|
endif()
|
2017-09-23 22:46:03 +00:00
|
|
|
endif()
|
2019-06-23 06:15:04 +00:00
|
|
|
|
2016-04-23 16:57:38 +00:00
|
|
|
if(ZIG_TEST_COVERAGE)
|
|
|
|
set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")
|
2017-09-23 22:46:03 +00:00
|
|
|
set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage")
|
2016-04-23 16:57:38 +00:00
|
|
|
endif()
|
2015-08-05 22:23:15 +00:00
|
|
|
|
2020-09-23 07:00:24 +00:00
|
|
|
add_library(zigcpp STATIC ${ZIG_CPP_SOURCES})
|
|
|
|
set_target_properties(zigcpp PROPERTIES
|
2017-12-27 01:04:09 +00:00
|
|
|
COMPILE_FLAGS ${EXE_CFLAGS}
|
|
|
|
)
|
2020-04-18 00:22:00 +00:00
|
|
|
|
2020-09-23 07:00:24 +00:00
|
|
|
target_link_libraries(zigcpp LINK_PUBLIC
|
2020-02-04 08:39:20 +00:00
|
|
|
${CLANG_LIBRARIES}
|
|
|
|
${LLD_LIBRARIES}
|
|
|
|
${LLVM_LIBRARIES}
|
2020-09-18 08:33:32 +00:00
|
|
|
${CMAKE_THREAD_LIBS_INIT}
|
2020-02-04 08:39:20 +00:00
|
|
|
)
|
2017-12-27 00:44:08 +00:00
|
|
|
|
2019-03-22 18:56:03 +00:00
|
|
|
add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})
|
|
|
|
set_target_properties(opt_c_util PROPERTIES
|
|
|
|
COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"
|
2018-09-10 13:46:15 +00:00
|
|
|
)
|
|
|
|
|
2020-09-23 07:00:24 +00:00
|
|
|
add_library(zigstage1 STATIC ${STAGE1_SOURCES})
|
|
|
|
set_target_properties(zigstage1 PROPERTIES
|
2016-04-23 16:57:38 +00:00
|
|
|
COMPILE_FLAGS ${EXE_CFLAGS}
|
|
|
|
LINK_FLAGS ${EXE_LDFLAGS}
|
|
|
|
)
|
2020-09-23 07:00:24 +00:00
|
|
|
target_link_libraries(zigstage1 LINK_PUBLIC
|
2019-03-22 18:56:03 +00:00
|
|
|
opt_c_util
|
2017-09-14 05:44:22 +00:00
|
|
|
${SOFTFLOAT_LIBRARIES}
|
2020-09-23 07:00:24 +00:00
|
|
|
zigcpp
|
2015-08-05 22:23:15 +00:00
|
|
|
)
|
2018-03-10 23:23:08 +00:00
|
|
|
if(NOT MSVC)
|
2020-09-23 07:00:24 +00:00
|
|
|
target_link_libraries(zigstage1 LINK_PUBLIC ${LIBXML2})
|
2018-03-10 19:48:41 +00:00
|
|
|
endif()
|
2019-03-09 23:54:34 +00:00
|
|
|
|
2018-01-05 03:46:26 +00:00
|
|
|
if(ZIG_DIA_GUIDS_LIB)
|
2020-09-23 07:00:24 +00:00
|
|
|
target_link_libraries(zigstage1 LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
|
2018-01-05 03:46:26 +00:00
|
|
|
endif()
|
|
|
|
|
2017-09-14 05:44:22 +00:00
|
|
|
if(MSVC OR MINGW)
|
2020-09-23 07:00:24 +00:00
|
|
|
target_link_libraries(zigstage1 LINK_PUBLIC version)
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 20:47:47 +00:00
|
|
|
endif()
|
|
|
|
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
add_executable(zig0 ${ZIG0_SOURCES})
|
2019-04-17 18:09:18 +00:00
|
|
|
set_target_properties(zig0 PROPERTIES
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 20:47:47 +00:00
|
|
|
COMPILE_FLAGS ${EXE_CFLAGS}
|
|
|
|
LINK_FLAGS ${EXE_LDFLAGS}
|
|
|
|
)
|
2020-09-23 07:00:24 +00:00
|
|
|
target_link_libraries(zig0 zigstage1)
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 20:47:47 +00:00
|
|
|
|
2019-07-12 23:28:28 +00:00
|
|
|
if(MSVC)
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 20:47:47 +00:00
|
|
|
else()
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.o")
|
2017-09-10 20:05:18 +00:00
|
|
|
endif()
|
2019-09-09 13:33:33 +00:00
|
|
|
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
set(ZIG1_RELEASE_ARG "")
|
2019-09-09 13:33:33 +00:00
|
|
|
else()
|
2020-09-26 08:42:54 +00:00
|
|
|
set(ZIG1_RELEASE_ARG -OReleaseFast --strip)
|
2020-02-16 23:57:34 +00:00
|
|
|
endif()
|
2020-01-18 00:39:43 +00:00
|
|
|
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
set(BUILD_ZIG1_ARGS
|
2020-09-22 01:38:55 +00:00
|
|
|
"src/stage1.zig"
|
2020-03-28 03:43:21 +00:00
|
|
|
-target "${ZIG_TARGET_TRIPLE}"
|
2020-04-08 21:41:51 +00:00
|
|
|
"-mcpu=${ZIG_TARGET_MCPU}"
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
--name zig1
|
2020-01-18 00:39:43 +00:00
|
|
|
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
|
2020-09-26 08:42:54 +00:00
|
|
|
"-femit-bin=${ZIG1_OBJECT}"
|
|
|
|
"${ZIG1_RELEASE_ARG}"
|
2020-02-16 23:57:34 +00:00
|
|
|
-lc
|
2020-08-18 00:06:23 +00:00
|
|
|
--pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
|
|
|
|
--pkg-end
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
--pkg-begin compiler_rt "${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt.zig"
|
|
|
|
--pkg-end
|
2020-01-18 00:39:43 +00:00
|
|
|
)
|
|
|
|
|
2020-10-26 17:50:43 +00:00
|
|
|
if("${ZIG_EXECUTABLE}" STREQUAL "")
|
2020-11-11 15:12:17 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${ZIG1_OBJECT}"
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
COMMAND zig0 ${BUILD_ZIG1_ARGS}
|
2020-11-11 15:12:17 +00:00
|
|
|
DEPENDS zig0 "${ZIG_STAGE2_SOURCES}"
|
2020-09-21 23:32:56 +00:00
|
|
|
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
|
2020-03-28 03:43:21 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
set(ZIG_EXECUTABLE "${zig_BINARY_DIR}/zig")
|
2020-04-11 20:18:54 +00:00
|
|
|
if (WIN32)
|
|
|
|
set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe")
|
|
|
|
endif()
|
2020-03-28 03:43:21 +00:00
|
|
|
else()
|
2020-11-11 15:12:17 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${ZIG1_OBJECT}"
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
BYPRODUCTS "${ZIG1_OBJECT}"
|
2020-11-11 15:12:17 +00:00
|
|
|
COMMAND "${ZIG_EXECUTABLE}" "build-obj" ${BUILD_ZIG1_ARGS}
|
|
|
|
DEPENDS ${ZIG_STAGE2_SOURCES}
|
2020-09-21 23:32:56 +00:00
|
|
|
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
|
2020-03-28 03:43:21 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
* an implementation of blake hashing
* the cache hash system
* compiler.cpp
* all the linking code, and everything having to do with building
glibc, musl, and mingw-w64
* much of the stage1 compiler internals got slimmed down since it
now assumes it is always outputting an object file.
More stuff:
* stage1 is now built with a different strategy: we have a tiny
zig0.cpp which is a slimmed down version of what stage1 main.cpp used
to be. Its only purpose is to build stage2 zig code into an object
file, which is then linked by the host build system (cmake) into
stage1. zig0.cpp uses the same C API that stage2 now has access to,
so that stage2 zig code can call into stage1 c++ code.
- stage1.h is
- stage2.h is
- stage1.zig is the main entry point for the Zig/C++
hybrid compiler. It has the functions exported from Zig, called
in C++, and bindings for the functions exported from C++, called
from Zig.
* removed the memory profiling instrumentation from stage1.
Abandon ship!
* Re-added the sections to the README about how to build stage2 and
stage3.
* stage2 now knows as a comptime boolean whether it is being compiled
as part of stage1 or as stage2.
- TODO use this flag to call into stage1 for compiling zig code.
* introduce -fdll-export-fns and -fno-dll-export-fns and clarify
its relationship to link_mode (static/dynamic)
* implement depending on LLVM to detect native target cpu features when
LLVM extensions are enabled and zig lacks CPU feature detection for
that target architecture.
* C importing is broken, will need some stage2 support to function
again.
2020-09-18 01:29:38 +00:00
|
|
|
# cmake won't let us configure an executable without C sources.
|
2020-11-11 15:12:17 +00:00
|
|
|
add_executable(zig "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp" "${ZIG1_OBJECT}")
|
2019-07-12 23:28:28 +00:00
|
|
|
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 20:47:47 +00:00
|
|
|
set_target_properties(zig PROPERTIES
|
|
|
|
COMPILE_FLAGS ${EXE_CFLAGS}
|
|
|
|
LINK_FLAGS ${EXE_LDFLAGS}
|
|
|
|
)
|
2020-11-11 15:12:17 +00:00
|
|
|
target_link_libraries(zig zigstage1)
|
2019-10-21 23:17:33 +00:00
|
|
|
if(MSVC)
|
|
|
|
target_link_libraries(zig ntdll.lib)
|
2020-03-28 03:43:21 +00:00
|
|
|
elseif(MINGW)
|
2019-10-23 00:34:34 +00:00
|
|
|
target_link_libraries(zig ntdll)
|
2019-10-21 23:17:33 +00:00
|
|
|
endif()
|
2020-01-18 00:39:43 +00:00
|
|
|
|
2015-08-05 22:23:15 +00:00
|
|
|
install(TARGETS zig DESTINATION bin)
|
2020-01-18 00:39:43 +00:00
|
|
|
|
2020-02-16 23:57:34 +00:00
|
|
|
set(ZIG_INSTALL_ARGS "build"
|
|
|
|
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
|
|
|
|
"-Dlib-files-only"
|
|
|
|
--prefix "${CMAKE_INSTALL_PREFIX}"
|
2020-04-06 17:07:19 +00:00
|
|
|
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
|
2020-02-16 23:57:34 +00:00
|
|
|
install
|
|
|
|
)
|
|
|
|
|
|
|
|
# CODE has no effect with Visual Studio build system generator, therefore
|
|
|
|
# when using Visual Studio build system generator we resort to running
|
|
|
|
# `zig build install` during the build phase.
|
|
|
|
if(MSVC)
|
|
|
|
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL
|
|
|
|
"Windows-only: Disable copying lib/ files to install prefix during the build phase")
|
|
|
|
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
|
|
|
|
add_custom_target(zig_install_lib_files ALL
|
|
|
|
COMMAND zig ${ZIG_INSTALL_ARGS}
|
|
|
|
DEPENDS zig
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
get_target_property(zig_BINARY_DIR zig BINARY_DIR)
|
2020-03-28 03:43:21 +00:00
|
|
|
install(CODE "set(zig_EXE \"${ZIG_EXECUTABLE}\")")
|
2020-02-16 23:57:34 +00:00
|
|
|
install(CODE "set(ZIG_INSTALL_ARGS \"${ZIG_INSTALL_ARGS}\")")
|
2020-01-18 00:39:43 +00:00
|
|
|
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
|
|
|
|
install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
|
|
|
|
endif()
|