From 082ec55135969ca27f6849dbdc541a12cdffec91 Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Tue, 20 Sep 2022 11:02:03 +0100 Subject: [PATCH 1/2] Add CMake build system --- CMakeLists.txt | 32 +++ cmake/CMakeLists.txt | 112 ++++++++ cmake/dlmalloc/CMakeLists.txt | 10 + cmake/global-compiler-options.cmake | 39 +++ cmake/libc-bottom-half/CMakeLists.txt | 41 +++ cmake/libc-bottom-half/clocks/CMakeLists.txt | 16 ++ cmake/libc-bottom-half/crt1/CMakeLists.txt | 26 ++ cmake/libc-bottom-half/getpid/CMakeLists.txt | 17 ++ cmake/libc-bottom-half/mman/CMakeLists.txt | 12 + cmake/libc-bottom-half/signal/CMakeLists.txt | 10 + cmake/libc-imports.cmake | 34 +++ cmake/libc-top-half/CMakeLists.txt | 264 +++++++++++++++++++ cmake/libc-top-half/musl/CMakeLists.txt | 69 +++++ cmake/local-sysroot.cmake | 146 ++++++++++ cmake/predefined-macros.cmake | 25 ++ tools/gen-imports.py | 85 ++++++ tools/gen-predefined-macros.py | 135 ++++++++++ 17 files changed, 1073 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/CMakeLists.txt create mode 100644 cmake/dlmalloc/CMakeLists.txt create mode 100644 cmake/global-compiler-options.cmake create mode 100644 cmake/libc-bottom-half/CMakeLists.txt create mode 100644 cmake/libc-bottom-half/clocks/CMakeLists.txt create mode 100644 cmake/libc-bottom-half/crt1/CMakeLists.txt create mode 100644 cmake/libc-bottom-half/getpid/CMakeLists.txt create mode 100644 cmake/libc-bottom-half/mman/CMakeLists.txt create mode 100644 cmake/libc-bottom-half/signal/CMakeLists.txt create mode 100644 cmake/libc-imports.cmake create mode 100644 cmake/libc-top-half/CMakeLists.txt create mode 100644 cmake/libc-top-half/musl/CMakeLists.txt create mode 100644 cmake/local-sysroot.cmake create mode 100644 cmake/predefined-macros.cmake create mode 100755 tools/gen-imports.py create mode 100644 tools/gen-predefined-macros.py diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..d2abb6753 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.16.3) + +project(wasi-libc LANGUAGES C) + +enable_testing() + +if("${CMAKE_C_COMPILER}" MATCHES "(.*)clang(-[0-9]+)?$") + set(CMAKE_NM "${CMAKE_MATCH_1}llvm-nm${CMAKE_MATCH_2}") +endif() + +find_package(Python COMPONENTS Interpreter REQUIRED) + +set(TARGET_TRIPLE wasm32-wasi) +set(MULTIARCH_TRIPLE wasm32-wasi) + +set(CMAKE_C_COMPILER_TARGET ${TARGET_TRIPLE} CACHE STRING "The target to compile for") + +# note that pthread support is still a work-in-progress. +set(THREAD_MODEL "single" CACHE STRING "single or posix") + +set(MALLOC_IMPL "dlmalloc" CACHE STRING "dlmalloc or none") + +option(BUILD_LIBC_TOP_HALF "Build libc top half" ON) + +# When the length is no larger than this threshold, we consider the +# overhead of bulk memory opcodes to outweigh the performance benefit, +# and fall back to the original musl implementation. See +# https://github.com/WebAssembly/wasi-libc/pull/263 for relevant +# discussion +set(BULK_MEMORY_THRESHOLD "32" CACHE STRING "bulk memory threshold") + +add_subdirectory(cmake) \ No newline at end of file diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 000000000..426d46165 --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1,112 @@ +set(LIBC_BOTTOM_HALF_HEADERS_PUBLIC_DIR ${PROJECT_SOURCE_DIR}/libc-bottom-half/headers/public) +set(LIBC_TOP_HALF_MUSL_DIR ${PROJECT_SOURCE_DIR}/libc-top-half/musl) +set(LIBC_TOP_HALF_MUSL_SRC_DIR ${LIBC_TOP_HALF_MUSL_DIR}/src) +set(LIBC_BOTTOM_HALF_DIR ${PROJECT_SOURCE_DIR}/libc-bottom-half) +set(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR ${LIBC_BOTTOM_HALF_DIR}/cloudlibc/src) + +set(INSTALL_LIB_DIR lib/${MULTIARCH_TRIPLE}) +set(INSTALL_SHARE_DIR share/${MULTIARCH_TRIPLE}) + +include(global-compiler-options.cmake) +include(local-sysroot.cmake) +include(predefined-macros.cmake) +include(libc-imports.cmake) + +add_subdirectory(libc-bottom-half) +add_subdirectory(libc-top-half) + +if(${MALLOC_IMPL} STREQUAL "dlmalloc") + add_subdirectory(dlmalloc) +endif() + +add_library(wasi-emulated-signal) +target_link_libraries(wasi-emulated-signal + wasi-emulated-signal-musl-objs + wasi-emulated-signal-objs +) +add_custom_command(TARGET wasi-emulated-signal POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) + +add_library(c) + +set (LIBC_LINK_LIBRARIES + libc-bottom-half +) + +if(${BUILD_LIBC_TOP_HALF} STREQUAL "ON") + list(APPEND LIBC_LINK_LIBRARIES + libc-top-half + ) +endif() + +if(${MALLOC_IMPL} STREQUAL "dlmalloc") + list(APPEND LIBC_LINK_LIBRARIES + dlmalloc) +elseif(${MALLOC_IMPL} STREQUAL "none") + # nothing to do here +else() + message(FATAL_ERROR "unknown malloc implementation ${MALLOC_IMPL}") +endif() + +target_link_libraries(c + PRIVATE + ${LIBC_LINK_LIBRARIES} +) + +add_custom_command(TARGET c POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) + +add_dependencies(c sysroot-headers) + +# Create empty placeholder libraries. +foreach(stub m rt pthread crypt util xnet resolve dl) + set(lib_path ${SYSROOT_LIB_DIR}/lib${stub}.a) + add_custom_command(OUTPUT ${lib_path} + COMMAND ${CMAKE_COMMAND} -E make_directory ${SYSROOT_LIB_DIR} + COMMAND ${CMAKE_C_COMPILER_AR} crs ${lib_path}) + add_custom_target(${stub} ALL + DEPENDS ${lib_path}) +endforeach() + +install( + TARGETS + c + c-printscan-long-double + c-printscan-no-floating-point + wasi-emulated-mman + wasi-emulated-process-clocks + wasi-emulated-getpid + wasi-emulated-signal + ARCHIVE DESTINATION ${INSTALL_LIB_DIR} + LIBRARY DESTINATION ${INSTALL_LIB_DIR} +) + +install( + DIRECTORY ${SYSROOT_INC_DIR} + DESTINATION . +) + +install( + DIRECTORY ${SYSROOT_SHARE_DIR} + DESTINATION share +) + +install( + DIRECTORY ${SYSROOT_LIB_DIR} + DESTINATION lib +) + +add_test(NAME check-metadata + COMMAND diff -wur + ${PROJECT_SOURCE_DIR}/expected/${MULTIARCH_TRIPLE}/${THREAD_MODEL}/predefined-macros.txt + ${CMAKE_BINARY_DIR}/sysroot/share/${MULTIARCH_TRIPLE}/predefined-macros.txt) + +add_test(NAME check-headers + COMMAND ${CMAKE_C_COMPILER} + -target ${CMAKE_C_COMPILER_TARGET} + --sysroot=${CMAKE_BINARY_DIR}/sysroot + -fsyntax-only + "-Wno#warnings" + ${CMAKE_BINARY_DIR}/sysroot/share/${MULTIARCH_TRIPLE}/include-all.c) diff --git a/cmake/dlmalloc/CMakeLists.txt b/cmake/dlmalloc/CMakeLists.txt new file mode 100644 index 000000000..04c139d26 --- /dev/null +++ b/cmake/dlmalloc/CMakeLists.txt @@ -0,0 +1,10 @@ +set(DLMALLOC_DIR ${PROJECT_SOURCE_DIR}/dlmalloc) + +add_library(dlmalloc OBJECT + ${DLMALLOC_DIR}/src/dlmalloc.c) + +target_include_directories(dlmalloc + PRIVATE + ${DLMALLOC_DIR}/include) + +add_dependencies(dlmalloc sysroot-headers) \ No newline at end of file diff --git a/cmake/global-compiler-options.cmake b/cmake/global-compiler-options.cmake new file mode 100644 index 000000000..05804d430 --- /dev/null +++ b/cmake/global-compiler-options.cmake @@ -0,0 +1,39 @@ +# WebAssembly floating-point match doesn't trap. +# TODO: Add -fno-signaling-nans when the compiler supports it. +add_compile_options(-fno-trapping-math) + +# Add all warnings, but disable a few which occur in third-party code. +add_compile_options( + -Wall -Wextra -Werror + -Wno-null-pointer-arithmetic + -Wno-unused-parameter + -Wno-sign-compare + -Wno-unused-variable + -Wno-unused-function + -Wno-ignored-attributes + -Wno-missing-braces + -Wno-ignored-pragmas + -Wno-unused-but-set-variable + -Wno-unknown-warning-option +) + +# Configure support for threads +if("${THREAD_MODEL}" STREQUAL "single") + add_compile_options(-mthread-model single) +elseif("${THREAD_MODEL}" STREQUAL "posix") + add_compile_options(-mthread-model posix -pthread -ftls-model=local-exec) +endif() + +# Expose the public headers to the implementation. We use `-isystem` for +# purpose for two reasons: +# +# 1. It only does `<...>` not `"...."` lookup. We are making a libc, +# which is a system library, so all public headers should be +# accessible via `<...>` and never also need `"..."`. `-isystem` main +# purpose is to only effect `<...>` lookup. +# +# 2. The `-I` for private headers added for specific C files below +# should come earlier in the search path, so they can "override" +# and/or `#include_next` the public headers. `-isystem` (like +# `-idirafter`) comes later in the search path than `-I`. +include_directories(SYSTEM ${CMAKE_BINARY_DIR}/sysroot/include) diff --git a/cmake/libc-bottom-half/CMakeLists.txt b/cmake/libc-bottom-half/CMakeLists.txt new file mode 100644 index 000000000..88c731c79 --- /dev/null +++ b/cmake/libc-bottom-half/CMakeLists.txt @@ -0,0 +1,41 @@ +set(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC_DIR ${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR}/include) +set(LIBC_BOTTOM_HALF_SRC_DIR ${LIBC_BOTTOM_HALF_DIR}/sources) +set(LIBC_BOTTOM_HALF_HEADERS_PRIVATE_DIR ${LIBC_BOTTOM_HALF_DIR}/headers/private) + +file(GLOB_RECURSE + LIBC_BOTTOM_HALF_ALL_SOURCES + CONFIGURE_DEPENDS + ${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR}/*.c + ${LIBC_BOTTOM_HALF_SRC_DIR}/*.c) + +set(LIBC_BOTTOM_HALF_INC_DIRS + ${LIBC_BOTTOM_HALF_HEADERS_PRIVATE_DIR} + ${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC_DIR} + ${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR} + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/include + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal +) + +# FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak +# references to a function defined in `chdir.c` only work if `chdir.c` is at the +# end of the archive, but once that LLD review lands and propagates into LLVM +# then we don't have to do this. +set(CHDIR_SRC "${LIBC_BOTTOM_HALF_SRC_DIR}/chdir.c") +list(REMOVE_ITEM LIBC_BOTTOM_HALF_ALL_SOURCES ${CHDIR_SRC}) +list(APPEND LIBC_BOTTOM_HALF_ALL_SOURCES ${CHDIR_SRC}) + +add_library(libc-bottom-half OBJECT + ${LIBC_BOTTOM_HALF_ALL_SOURCES}) +add_dependencies(libc-bottom-half sysroot-headers) +target_include_directories(libc-bottom-half + PRIVATE + ${LIBC_BOTTOM_HALF_INC_DIRS} + SYSTEM + ${SYSROOT_INC_DIR} +) + +add_subdirectory(clocks) +add_subdirectory(getpid) +add_subdirectory(mman) +add_subdirectory(signal) +add_subdirectory(crt1) \ No newline at end of file diff --git a/cmake/libc-bottom-half/clocks/CMakeLists.txt b/cmake/libc-bottom-half/clocks/CMakeLists.txt new file mode 100644 index 000000000..2045cea92 --- /dev/null +++ b/cmake/libc-bottom-half/clocks/CMakeLists.txt @@ -0,0 +1,16 @@ +file(GLOB_RECURSE + CLOCKS_SOURCES + ${LIBC_BOTTOM_HALF_DIR}/clocks/*.c) + +add_library(wasi-emulated-process-clocks STATIC + ${CLOCKS_SOURCES}) + +target_include_directories(wasi-emulated-process-clocks + PRIVATE + ${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR}) + +add_dependencies(wasi-emulated-process-clocks sysroot-headers) + +add_custom_command(TARGET wasi-emulated-process-clocks POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) diff --git a/cmake/libc-bottom-half/crt1/CMakeLists.txt b/cmake/libc-bottom-half/crt1/CMakeLists.txt new file mode 100644 index 000000000..95a778bee --- /dev/null +++ b/cmake/libc-bottom-half/crt1/CMakeLists.txt @@ -0,0 +1,26 @@ +file(GLOB + LIBC_BOTTOM_HALF_CRT_SOURCES + CONFIGURE_DEPENDS + ${LIBC_BOTTOM_HALF_DIR}/crt/*.c) + +foreach(crt_path ${LIBC_BOTTOM_HALF_CRT_SOURCES}) + get_filename_component(crt_name ${crt_path} NAME_WLE) + add_library(${crt_name} OBJECT ${crt_path}) + + target_include_directories(${crt_name} + PRIVATE + ${LIBC_BOTTOM_HALF_INC_DIRS} + ) + + add_dependencies(${crt_name} sysroot-headers) + + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/sysroot/lib/${crt_name}.o + COMMAND ${CMAKE_COMMAND} -E make_directory ${SYSROOT_LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ ${SYSROOT_LIB_DIR}/${crt_name}.o + COMMAND_EXPAND_LISTS + ) + + add_custom_target(${crt_name}.o ALL + DEPENDS ${CMAKE_BINARY_DIR}/sysroot/lib/${crt_name}.o) + add_dependencies(${crt_name}.o ${crt_name}) +endforeach() diff --git a/cmake/libc-bottom-half/getpid/CMakeLists.txt b/cmake/libc-bottom-half/getpid/CMakeLists.txt new file mode 100644 index 000000000..313213efb --- /dev/null +++ b/cmake/libc-bottom-half/getpid/CMakeLists.txt @@ -0,0 +1,17 @@ +file(GLOB_RECURSE + GETPID_SOURCES + ${LIBC_BOTTOM_HALF_DIR}/getpid/*.c) + +add_library(wasi-emulated-getpid STATIC + ${GETPID_SOURCES}) + +set_target_properties(wasi-emulated-getpid + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/sysroot/lib +) + +add_dependencies(wasi-emulated-getpid sysroot-headers) + +add_custom_command(TARGET wasi-emulated-getpid POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) diff --git a/cmake/libc-bottom-half/mman/CMakeLists.txt b/cmake/libc-bottom-half/mman/CMakeLists.txt new file mode 100644 index 000000000..521746495 --- /dev/null +++ b/cmake/libc-bottom-half/mman/CMakeLists.txt @@ -0,0 +1,12 @@ +file(GLOB_RECURSE + MMAN_SOURCES + ${LIBC_BOTTOM_HALF_DIR}/mman/*.c) + +add_library(wasi-emulated-mman STATIC + ${MMAN_SOURCES}) + +add_dependencies(wasi-emulated-mman sysroot-headers) + +add_custom_command(TARGET wasi-emulated-mman POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) diff --git a/cmake/libc-bottom-half/signal/CMakeLists.txt b/cmake/libc-bottom-half/signal/CMakeLists.txt new file mode 100644 index 000000000..c8dcfbd0b --- /dev/null +++ b/cmake/libc-bottom-half/signal/CMakeLists.txt @@ -0,0 +1,10 @@ +file(GLOB_RECURSE + SIGNAL_SOURCES + ${LIBC_BOTTOM_HALF_DIR}/signal/*.c) + +add_library(wasi-emulated-signal-objs + OBJECT + ${SIGNAL_SOURCES} +) + +add_dependencies(wasi-emulated-signal-objs sysroot-headers) diff --git a/cmake/libc-imports.cmake b/cmake/libc-imports.cmake new file mode 100644 index 000000000..f0db9e971 --- /dev/null +++ b/cmake/libc-imports.cmake @@ -0,0 +1,34 @@ +add_custom_command(OUTPUT ${SYSROOT_LIB_DIR}/libc.imports + COMMAND + ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/gen-imports.py + --nm ${CMAKE_NM} + --libc-imports-output ${SYSROOT_LIB_DIR}/libc.imports + --defined-symbols-output ${SYSROOT_SHARE_DIR}/defined-symbols.txt + --undefined-symbols-output ${SYSROOT_SHARE_DIR}/undefined-symbols.txt + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + DEPENDS + ${PROJECT_SOURCE_DIR}/tools/gen-imports.py) + +add_custom_target(libc.imports ALL + DEPENDS ${SYSROOT_LIB_DIR}/libc.imports) +add_dependencies(libc.imports + c + c-printscan-long-double + c-printscan-no-floating-point + wasi-emulated-mman + wasi-emulated-process-clocks + wasi-emulated-getpid + wasi-emulated-signal + crt1 + crt1-command + crt1-reactor +) \ No newline at end of file diff --git a/cmake/libc-top-half/CMakeLists.txt b/cmake/libc-top-half/CMakeLists.txt new file mode 100644 index 000000000..7257de4ba --- /dev/null +++ b/cmake/libc-top-half/CMakeLists.txt @@ -0,0 +1,264 @@ +set(LIBC_TOP_HALF_DIR ${PROJECT_SOURCE_DIR}/libc-top-half) +set(LIBC_TOP_HALF_SOURCE_DIR ${LIBC_TOP_HALF_DIR}/sources) +set(LIBC_TOP_HALF_HEADERS_PRIVATE_DIR ${LIBC_TOP_HALF_DIR}/headers/private) + +set(LIBC_TOP_HALF_COMMON_COMPILE_OPTIONS + -Wno-parentheses + -Wno-shift-op-parentheses + -Wno-bitwise-op-parentheses + -Wno-logical-op-parentheses + -Wno-string-plus-int + -Wno-dangling-else + -Wno-unknown-pragmas +) + +set(LIBC_TOP_HALF_COMMON_INC_DIRS + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/include + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal + ${LIBC_TOP_HALF_MUSL_DIR}/arch/wasm32 + ${LIBC_TOP_HALF_MUSL_DIR}/arch/generic + ${LIBC_TOP_HALF_HEADERS_PRIVATE_DIR} +) + +file(GLOB_RECURSE LIBC_TOP_HALF_SOURCES + CONFIGURE_DEPENDS + ${LIBC_TOP_HALF_SOURCE_DIR}/*.c +) + + +file(GLOB LIBC_TOP_HALF_MUSL_SOURCES + CONFIGURE_DEPENDS + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/string/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/locale/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdlib/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/search/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/multibyte/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/regex/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/prng/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/conf/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/ctype/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/*.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/crypt/*.c +) + +list(APPEND LIBC_TOP_HALF_MUSL_SOURCES + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/a64l.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/basename.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/dirname.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/ffs.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/ffsl.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/ffsll.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/fmtmsg.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/getdomainname.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/gethostid.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/getopt.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/getopt_long.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/getsubopt.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/uname.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/misc/nftw.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/errno/strerror.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/htonl.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/htons.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/ntohl.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/ntohs.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/inet_ntop.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/inet_pton.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/inet_aton.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/in6addr_any.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/network/in6addr_loopback.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fenv/fenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fenv/fesetround.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fenv/feupdateenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fenv/fesetexceptflag.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fenv/fegetexceptflag.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fenv/feholdexcept.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/exit/exit.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/exit/atexit.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/exit/assert.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/exit/quick_exit.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/exit/at_quick_exit.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/strftime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/asctime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/asctime_r.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/ctime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/ctime_r.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/wcsftime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/strptime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/difftime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/timegm.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/ftime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/gmtime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/gmtime_r.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/timespec_get.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/getdate.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/localtime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/localtime_r.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/mktime.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/__tm_to_secs.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/__month_to_secs.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/__secs_to_tm.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/__year_to_secs.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/time/__tz.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/fcntl/creat.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/dirent/alphasort.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/dirent/versionsort.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/env/clearenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/env/getenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/env/putenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/env/setenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/env/unsetenv.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/unistd/posix_close.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stat/futimesat.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/legacy/getpagesize.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/thrd_sleep.c +) + +list(REMOVE_ITEM LIBC_TOP_HALF_MUSL_SOURCES + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/procfdname.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/syscall.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/syscall_ret.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/vdso.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/version.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/flockfile.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/funlockfile.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/__lockfile.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/ftrylockfile.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/rename.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/tmpnam.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/tmpfile.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/tempnam.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/popen.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/pclose.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/remove.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/gets.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/string/strsignal.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/locale/dcngettext.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/locale/textdomain.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/locale/bind_textdomain_codeset.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/__signbit.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/__signbitf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/__signbitl.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/__fpclassify.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/__fpclassifyf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/__fpclassifyl.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/ceilf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/ceil.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/floorf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/floor.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/truncf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/trunc.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/rintf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/rint.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/nearbyintf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/nearbyint.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/sqrtf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/sqrt.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/fabsf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/fabs.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/copysignf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/copysign.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/fminf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/fmaxf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/fmin.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/math/fmax.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/crealf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/creal.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/creall.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/cimagf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/cimag.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/complex/cimagl.c +) + +if("${THREAD_MODEL}" STREQUAL "posix") + list(APPEND LIBC_TOP_HALF_MUSL_SOURCES + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/__wait.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/__timedwait.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cleanup_push.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cond_broadcast.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cond_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cond_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cond_signal.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cond_timedwait.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_cond_wait.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_condattr_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_condattr_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_condattr_setclock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_condattr_setpshared.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_create.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_consistent.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_getprioceiling.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_lock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_timedlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_trylock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutex_unlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutexattr_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutexattr_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutexattr_setprotocol.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutexattr_setpshared.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutexattr_setrobust.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_mutexattr_settype.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_rdlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_timedrdlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_timedwrlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_tryrdlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_trywrlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_unlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlock_wrlock.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlockattr_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlockattr_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_rwlockattr_setpshared.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_setcancelstate.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/pthread_testcancel.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_destroy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_getvalue.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_init.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_post.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_timedwait.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_trywait.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/thread/sem_wait.c +) +endif() + +set_source_files_properties( + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/string/memcpy.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/string/memmove.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/string/memset.c + PROPERTIES + COMPILE_DEFINITIONS + BULK_MEMORY_THRESHOLD=${BULK_MEMORY_THRESHOLD} + COMPILE_FLAGS + -mbulk-memory +) + +if(${BUILD_LIBC_TOP_HALF} STREQUAL "ON") + add_library(libc-top-half + OBJECT + ${LIBC_TOP_HALF_SOURCES} + ${LIBC_TOP_HALF_MUSL_SOURCES} + ) + target_include_directories(libc-top-half + PRIVATE + ${LIBC_TOP_HALF_COMMON_INC_DIRS} + ) + + if("${THREAD_MODEL}" STREQUAL "posix") + target_include_directories(libc-top-half + PRIVATE + ${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR}) + endif() + target_compile_options(libc-top-half + PRIVATE + ${LIBC_TOP_HALF_COMMON_COMPILE_OPTIONS} + ) + add_dependencies(libc-top-half sysroot-headers) +endif() + + +add_subdirectory(musl) \ No newline at end of file diff --git a/cmake/libc-top-half/musl/CMakeLists.txt b/cmake/libc-top-half/musl/CMakeLists.txt new file mode 100644 index 000000000..3caa04de4 --- /dev/null +++ b/cmake/libc-top-half/musl/CMakeLists.txt @@ -0,0 +1,69 @@ +set(LIBC_TOP_HALF_MUSL_PRINTSCAN_SOURCES + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/internal/floatscan.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/vfprintf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/vfwprintf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdio/vfscanf.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdlib/strtod.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/stdlib/wcstod.c +) + +add_library(c-printscan-no-floating-point + ${LIBC_TOP_HALF_MUSL_PRINTSCAN_SOURCES} +) + +target_compile_definitions(c-printscan-no-floating-point PRIVATE + __wasilibc_printscan_no_floating_point + __wasilibc_printscan_floating_point_support_option="remove -lc-printscan-no-floating-point from the link command") +target_compile_options(c-printscan-no-floating-point + PRIVATE + ${LIBC_TOP_HALF_COMMON_COMPILE_OPTIONS} +) + +target_include_directories(c-printscan-no-floating-point PRIVATE + PRIVATE + ${LIBC_TOP_HALF_COMMON_INC_DIRS} +) + +add_dependencies(c-printscan-no-floating-point sysroot-headers) + +add_custom_command(TARGET c-printscan-no-floating-point POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) + +add_library(c-printscan-long-double + ${LIBC_TOP_HALF_MUSL_PRINTSCAN_SOURCES} +) +target_compile_options(c-printscan-long-double + PRIVATE + ${LIBC_TOP_HALF_COMMON_COMPILE_OPTIONS}) + +target_include_directories(c-printscan-long-double + PRIVATE + ${LIBC_TOP_HALF_COMMON_INC_DIRS} +) +add_dependencies(c-printscan-long-double sysroot-headers) + +add_custom_command(TARGET c-printscan-long-double POST_BUILD + COMMAND ${CMAKE_C_COMPILER_AR} crs $ +) + + +add_library(wasi-emulated-signal-musl-objs + OBJECT + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/signal/psignal.c + ${LIBC_TOP_HALF_MUSL_SRC_DIR}/string/strsignal.c +) +target_compile_definitions(wasi-emulated-signal-musl-objs + PRIVATE + _WASI_EMULATED_SIGNAL +) +target_compile_options(wasi-emulated-signal-musl-objs + PRIVATE + ${LIBC_TOP_HALF_COMMON_COMPILE_OPTIONS}) + +target_include_directories(wasi-emulated-signal-musl-objs + PRIVATE + ${LIBC_TOP_HALF_COMMON_INC_DIRS} +) + +add_dependencies(wasi-emulated-signal-musl-objs sysroot-headers) \ No newline at end of file diff --git a/cmake/local-sysroot.cmake b/cmake/local-sysroot.cmake new file mode 100644 index 000000000..5e3f2d5df --- /dev/null +++ b/cmake/local-sysroot.cmake @@ -0,0 +1,146 @@ +# "local" sysroot for files required for building libc +# (before install step) +set(SYSROOT_DIR ${CMAKE_BINARY_DIR}/sysroot) +set(SYSROOT_INC_DIR ${SYSROOT_DIR}/include) +set(SYSROOT_SHARE_DIR ${SYSROOT_DIR}/${INSTALL_SHARE_DIR}) +set(SYSROOT_LIB_DIR ${SYSROOT_DIR}/${INSTALL_LIB_DIR}) + + +# Files from musl's include directory that we don't want to install in the +# sysroot's include directory. +set(MUSL_OMIT_HEADERS + # Remove files which aren't headers (we generate alltypes.h below). + bits/syscall.h.in + bits/alltypes.h.in + alltypes.h.in + + # Use the compiler's version of these headers. + stdarg.h + stddef.h + + # Use the WASI errno definitions. + bits/errno.h + + # Remove headers that aren't supported yet or that aren't relevant for WASI. + sys/procfs.h + sys/user.h + sys/kd.h sys/vt.h sys/soundcard.h sys/sem.h + sys/shm.h sys/msg.h sys/ipc.h sys/ptrace.h + sys/statfs.h + bits/kd.h bits/vt.h bits/soundcard.h bits/sem.h + bits/shm.h bits/msg.h bits/ipc.h bits/ptrace.h + bits/statfs.h + sys/vfs.h + sys/statvfs.h + syslog.h sys/syslog.h + wait.h sys/wait.h + ucontext.h sys/ucontext.h + paths.h + utmp.h utmpx.h + lastlog.h + sys/acct.h + sys/cachectl.h + sys/epoll.h sys/reboot.h sys/swap.h + sys/sendfile.h sys/inotify.h + sys/quota.h + sys/klog.h + sys/fsuid.h + sys/io.h + sys/prctl.h + sys/mtio.h + sys/mount.h + sys/fanotify.h + sys/personality.h + elf.h link.h bits/link.h + scsi/scsi.h scsi/scsi_ioctl.h scsi/sg.h + sys/auxv.h + pwd.h shadow.h grp.h + mntent.h + netdb.h + resolv.h + pty.h + dlfcn.h + setjmp.h + ulimit.h + sys/xattr.h + wordexp.h + spawn.h + sys/membarrier.h + sys/signalfd.h + termios.h + sys/termios.h + bits/termios.h + net/if.h + net/if_arp.h + net/ethernet.h + net/route.h + netinet/if_ether.h + netinet/ether.h + sys/timerfd.h + libintl.h + sys/sysmacros.h + aio.h) + +if("${THREAD_MODEL}" STREQUAL "single") + # Remove headers not supported in single-threaded mode. + list(APPEND MUSL_OMIT_HEADERS "pthread.h") +endif() + +set(MUSL_REMOVE_HEADERS) +foreach(HEADER ${MUSL_OMIT_HEADERS}) + list(APPEND MUSL_REMOVE_HEADERS ${SYSROOT_INC_DIR}/${HEADER}) +endforeach() + +add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/alltypes.h.gen + COMMAND + sed -f ${LIBC_TOP_HALF_MUSL_DIR}/tools/mkalltypes.sed ${LIBC_TOP_HALF_MUSL_DIR}/arch/wasm32/bits/alltypes.h.in ${LIBC_TOP_HALF_MUSL_DIR}/include/alltypes.h.in > ${CMAKE_BINARY_DIR}/alltypes.h.gen + DEPENDS + ${LIBC_TOP_HALF_MUSL_DIR}/tools/mkalltypes.sed + ${LIBC_TOP_HALF_MUSL_DIR}/arch/wasm32/bits/alltypes.h.in + ${LIBC_TOP_HALF_MUSL_DIR}/include/alltypes.h.in +) + +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/sysroot + + COMMAND + ${CMAKE_COMMAND} -E make_directory + ${SYSROOT_INC_DIR} + ${SYSROOT_DIR}/share + + COMMAND + ${CMAKE_COMMAND} -E copy_directory + ${LIBC_BOTTOM_HALF_HEADERS_PUBLIC_DIR} + ${SYSROOT_INC_DIR} + + COMMAND + ${CMAKE_COMMAND} -E copy_directory + ${LIBC_TOP_HALF_MUSL_DIR}/include/ + ${SYSROOT_INC_DIR} + + COMMAND + ${CMAKE_COMMAND} -E copy_directory + ${LIBC_TOP_HALF_MUSL_DIR}/arch/generic/bits/ + ${SYSROOT_INC_DIR}/bits + + COMMAND + ${CMAKE_COMMAND} -E copy_directory + ${LIBC_TOP_HALF_MUSL_DIR}/arch/wasm32/bits/ + ${SYSROOT_INC_DIR}/bits + + COMMAND + ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_BINARY_DIR}/alltypes.h.gen + ${SYSROOT_INC_DIR}/bits/alltypes.h + + COMMAND + ${CMAKE_COMMAND} -E remove + ${MUSL_REMOVE_HEADERS} + + DEPENDS + ${CMAKE_BINARY_DIR}/alltypes.h.gen +) + +add_custom_target(sysroot-headers ALL + DEPENDS ${CMAKE_BINARY_DIR}/sysroot) \ No newline at end of file diff --git a/cmake/predefined-macros.cmake b/cmake/predefined-macros.cmake new file mode 100644 index 000000000..f364eb117 --- /dev/null +++ b/cmake/predefined-macros.cmake @@ -0,0 +1,25 @@ +get_directory_property(DIR_COMPILE_OPTIONS COMPILE_OPTIONS) + +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/sysroot/share/${MULTIARCH_TRIPLE}/include-all.c + + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/sysroot/share/${MULTIARCH_TRIPLE} + + COMMAND + ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/gen-predefined-macros.py + --cc ${CMAKE_C_COMPILER} + --output-directory ${SYSROOT_DIR}/share/${MULTIARCH_TRIPLE} + --sysroot ${SYSROOT_DIR} + -target ${CMAKE_C_COMPILER_TARGET} -O2 -DNDEBUG + ${DIR_COMPILE_OPTIONS} + + DEPENDS + ${PROJECT_SOURCE_DIR}/tools/gen-predefined-macros.py +) + +add_custom_target(predefined-macros ALL + DEPENDS + ${CMAKE_BINARY_DIR}/sysroot/share/${MULTIARCH_TRIPLE}/include-all.c +) +add_dependencies(predefined-macros sysroot-headers) \ No newline at end of file diff --git a/tools/gen-imports.py b/tools/gen-imports.py new file mode 100755 index 000000000..99ceea04f --- /dev/null +++ b/tools/gen-imports.py @@ -0,0 +1,85 @@ +# -*- encoding: utf-8 -*- +"""Generate import file for a target + +This utility scans a static library to identify the undefined symbols which are +externally visible which it expects to have provided. This is used to generate +the import file definitions for WASI. + +Example: + $ python gen-imports.py --nm llvm-nm --prefix __wasi_ libc.a +""" + +import argparse +import os +import re +import subprocess +import sys + +from subprocess import Popen +from typing import Iterator, List + + +class SymbolsProvider: + def __init__(self, nm: str, lib_files: List[str]) -> None: + self._nm = nm + self._lib_files = lib_files + + def _get_symbols(self, args: List[str]) -> List[str]: + process = Popen([self._nm] + args + ['--just-symbol-name', '--extern-only'] + self._lib_files, + stdout=subprocess.PIPE) + output, error = process.communicate() + + lines = output.decode('utf-8').splitlines() + return sorted(set([line for line in lines if not line.endswith(':') and line])) + + def get_libc_imports_symbols(self, prefix: str) -> Iterator[str]: + re_prefix = re.compile(prefix) + symbols = self._get_symbols([]) + return filter(lambda symbol: re_prefix.match(symbol), symbols) + + def get_defined_symbols(self) -> List[str]: + return self._get_symbols(['--defined-only']) + + def get_undefined_symbols(self) -> List[str]: + undefined_symbols = self._get_symbols(['--undefined-only']) + defined_symbols = set(self.get_defined_symbols()) + return [ + symbol for symbol in undefined_symbols + if symbol not in defined_symbols and not symbol.startswith('__mul') + ] + + +def write_symbols(file_path: str, symbols: List[str]) -> None: + with open(file_path, 'w') as f: + f.write('\n'.join(symbols)) + + +def main(argv) -> None: + parser = argparse.ArgumentParser('gen-imports') + parser.add_argument('--nm', default='nm') + parser.add_argument('--prefix', default='^_(.*?)imported_wasi_') + parser.add_argument('--libc-imports-output', required=True) + parser.add_argument('--defined-symbols-output', required=True) + parser.add_argument('--undefined-symbols-output', required=True) + + args, unparsed = parser.parse_known_args() + + args.nm = os.path.normpath(args.nm) + args.libc_imports_output = os.path.normpath(args.libc_imports_output) + args.defined_symbols_output = os.path.normpath(args.defined_symbols_output) + args.undefined_symbols_output = os.path.normpath( + args.undefined_symbols_output) + + lib_files = [os.path.normpath(path) for path in unparsed] + + provider = SymbolsProvider(args.nm, lib_files) + + write_symbols(args.libc_imports_output, + provider.get_libc_imports_symbols(args.prefix)) + write_symbols(args.defined_symbols_output, provider.get_defined_symbols()) + write_symbols(args.undefined_symbols_output, + provider.get_undefined_symbols()) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/tools/gen-predefined-macros.py b/tools/gen-predefined-macros.py new file mode 100644 index 000000000..5cc688727 --- /dev/null +++ b/tools/gen-predefined-macros.py @@ -0,0 +1,135 @@ +# -*- encoding: utf-8 -*- +"""Generate macro enumeration for WASI target + +This utility generates the full list of compiler macros defined during the WASI +builds. It writes out the `predefined-macros.txt` and `include-all.c` files +into the directory specificed. + +Examples: + $ python gen-predefined-macros.py --cc clang --sysroot sysroot --output-directory sysroot/share +""" + +import argparse +import os +import re +import subprocess +import sys + +from subprocess import Popen + +def _enumerate_headers(directory): + headers = set() + + for root, directories, files in os.walk(directory): + # ignore the bits directories as they are internal implementation + # details + directories[:] = [ d for d in directories if not d == 'bits' and not d == 'c++' ] + + # Compute the include relative path, however special case '.' to be + # ignored as a prefix. + path = os.path.relpath(root, directory) + if path == '.': + path = '' + + disabled_headers = ['mman.h', 'signal.h', 'times.h', 'resource.h'] + # ignore mman.h + # XXX(compnerd) document why mman.h is being ignored + for include in filter(lambda file: file not in disabled_headers, files): + headers.add(os.path.join(path, include)) + + return headers + +def _enumerate_defines(cc, sysroot, flags, include_all_c): + include = os.path.join(sysroot, 'include') + + # Collect all the predefined macros ... + process = Popen([ + cc, + include_all_c, + # ... marking the sysroot as a system include path as + # clang will include its resource directory include path + # earlier producing compiler-specific output + '-isystem', include, + '-std=gnu17', + '-E', '-dM', '-Wno-#warnings', + '-D_ALL_SOURCE', + '-U__llvm__', + '-U__clang__', + '-U__clang_major__', + '-U__clang_minor__', + '-U__clang_patchlevel__', + '-U__clang_version__', + '-U__clang_literal_encoding__', + '-U__clang_wide_literal_encoding__', + '-U__GNUC__', + '-U__GNUC_MINOR__', + '-U__GNUC_PATCHLEVEL__', + '-U__VERSION__', + '-U__FLOAT128__', + '-U__NO_MATH_ERRNO__', + '-U__BITINT_MAXWIDTH__', + '-U__FLT_EVAL_METHOD__', + '-Wno-builtin-macro-redefined', + ] + flags, + stdout = subprocess.PIPE, + stderr = sys.stderr) + output, error = process.communicate() + + if process.returncode: + sys.exit(process.returncode) + + defines = output.decode('utf-8').splitlines() + + # filter out + # - __FLT16_* for now as not all versions of clang have these + # - __FLOAT128__ as it is not in clang 8.0 + __FLT16_ = re.compile(r'\b__FLT16_') + __FLOAT128__ = re.compile(r'\b__FLOAT128__\b') + __WIDTH__ = re.compile(r'\b__(BOOL|INT_(LEAST|FAST)(8|16|32|64)|INT|LONG|LLONG|SHRT)_WIDTH__\b') + + defines = [ + define for define in defines if not ( + re.search(__FLT16_, define) or + re.search(__FLOAT128__, define) or + re.search(__WIDTH__, define) or + False + ) + ] + + # For the __*_ATOMIC_*_LOCK_FREE macros, squash individual compiler names to + # attempt to keep these files compiler-independent + defines = [ + re.sub(r'__[A-Z0-9]*_ATOMIC_([A-Z0-9_]*)_LOCK_FREE', + r'__compiler_ATOMIC_\1_LOCK_FREE', define) + for define in defines + ] + + return defines + +def main(argv): + parser = argparse.ArgumentParser('gen-predefined-macros') + parser.add_argument('--cc', default = 'clang') + parser.add_argument('--sysroot', required = True) + parser.add_argument('--output-directory', required = True, dest = 'output') + + args, unparsed = parser.parse_known_args() + args.output = os.path.normpath(args.output) + args.sysroot = os.path.normpath(args.sysroot) + + include = os.path.join(args.sysroot, 'include') + include_all_c = os.path.join(args.output, 'include-all.c') + predefined_macros_txt = os.path.join(args.output, 'predefined-macros.txt') + + with open(include_all_c, 'w') as source: + for header in sorted(_enumerate_headers(include)): + source.write('#include <{}>\n'.format(header)) + + with open(predefined_macros_txt, 'w') as macros: + for define in _enumerate_defines(args.cc, args.sysroot, unparsed, + include_all_c): + if define.startswith('#define __FLT16_'): + continue + macros.write('{}\n'.format(define)) + +if __name__ == '__main__': + main(sys.argv) From f64759d32bee4211ccaf272671c917f2194fc703 Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Mon, 10 Oct 2022 22:36:37 +0100 Subject: [PATCH 2/2] update github actions --- .github/workflows/main.yml | 12 +- Makefile | 1269 +++++++++++++++++------------------- cmake/libc-imports.cmake | 1 + 3 files changed, 611 insertions(+), 671 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bbb012eb..0bb4206ff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,13 +58,16 @@ jobs: - name: Build libc shell: bash - run: make -j4 + run: | + cmake -DCMAKE_INSTALL_PREFIX=install-sysroot . + cmake --build . --target install + ctest - uses: actions/upload-artifact@v1 with: # Upload the sysroot folder. Give it a name according to the OS it was built for. name: ${{ format( 'sysroot-{0}.tgz', matrix.os) }} - path: sysroot + path: install-sysroot - name: Build libc + threads # Only build the thread-capable wasi-libc in the latest supported Clang @@ -72,7 +75,10 @@ jobs: # (e.g., `__builtin_wasm_memory_atomic_notify`). if: matrix.clang_version != '10.0.0' shell: bash - run: make -j4 THREAD_MODEL=posix + run: | + cmake -DCMAKE_INSTALL_PREFIX=install-sysroot -DTHREAD_MODEL=posix . + cmake --build . --target install + ctest # Disable the headerstest job for now, while WASI transitions from the # witx snapshots to wit proposals, and we have a few manual edits to the diff --git a/Makefile b/Makefile index 7f71a3e23..c594165e4 100644 --- a/Makefile +++ b/Makefile @@ -1,671 +1,604 @@ -# These variables are specifically meant to be overridable via the make -# command-line. -# ?= doesn't work for CC and AR because make has a default value for them. -ifeq ($(origin CC), default) -CC := clang -endif -NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(CC))) -ifeq ($(origin AR), default) -AR = $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(CC))) -endif -EXTRA_CFLAGS ?= -O2 -DNDEBUG -# The directory where we build the sysroot. -SYSROOT ?= $(CURDIR)/sysroot -# A directory to install to for "make install". -INSTALL_DIR ?= /usr/local -# single or posix; note that pthread support is still a work-in-progress. -THREAD_MODEL ?= single -# dlmalloc or none -MALLOC_IMPL ?= dlmalloc -# yes or no -BUILD_LIBC_TOP_HALF ?= yes -# The directory where we're store intermediate artifacts. -OBJDIR ?= $(CURDIR)/build - -# When the length is no larger than this threshold, we consider the -# overhead of bulk memory opcodes to outweigh the performance benefit, -# and fall back to the original musl implementation. See -# https://github.com/WebAssembly/wasi-libc/pull/263 for relevant -# discussion -BULK_MEMORY_THRESHOLD ?= 32 - -# Variables from this point on are not meant to be overridable via the -# make command-line. - -# Set the target variables. Multiarch triples notably omit the vendor field, -# which happens to be what we do for the main target triple too. -TARGET_TRIPLE = wasm32-wasi -MULTIARCH_TRIPLE = wasm32-wasi - -# These variables describe the locations of various files and directories in -# the source tree. -DLMALLOC_DIR = $(CURDIR)/dlmalloc -DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src -DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/dlmalloc.c -DLMALLOC_INC = $(DLMALLOC_DIR)/include -LIBC_BOTTOM_HALF_DIR = $(CURDIR)/libc-bottom-half -LIBC_BOTTOM_HALF_CLOUDLIBC_SRC = $(LIBC_BOTTOM_HALF_DIR)/cloudlibc/src -LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC = $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/include -LIBC_BOTTOM_HALF_HEADERS_PUBLIC = $(LIBC_BOTTOM_HALF_DIR)/headers/public -LIBC_BOTTOM_HALF_HEADERS_PRIVATE = $(LIBC_BOTTOM_HALF_DIR)/headers/private -LIBC_BOTTOM_HALF_SOURCES = $(LIBC_BOTTOM_HALF_DIR)/sources -LIBC_BOTTOM_HALF_ALL_SOURCES = \ - $(sort \ - $(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \ - $(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c)) - -# FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak -# references to a function defined in `chdir.c` only work if `chdir.c` is at the -# end of the archive, but once that LLD review lands and propagates into LLVM -# then we don't have to do this. -LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_SOURCES)/chdir.c,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) -LIBC_BOTTOM_HALF_ALL_SOURCES := $(LIBC_BOTTOM_HALF_ALL_SOURCES) $(LIBC_BOTTOM_HALF_SOURCES)/chdir.c - -LIBWASI_EMULATED_MMAN_SOURCES = \ - $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/mman -name \*.c)) -LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES = \ - $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/clocks -name \*.c)) -LIBWASI_EMULATED_GETPID_SOURCES = \ - $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/getpid -name \*.c)) -LIBWASI_EMULATED_SIGNAL_SOURCES = \ - $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/signal -name \*.c)) -LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES = \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/signal/psignal.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/strsignal.c -LIBC_BOTTOM_HALF_CRT_SOURCES = $(wildcard $(LIBC_BOTTOM_HALF_DIR)/crt/*.c) -LIBC_TOP_HALF_DIR = $(CURDIR)/libc-top-half -LIBC_TOP_HALF_MUSL_DIR = $(LIBC_TOP_HALF_DIR)/musl -LIBC_TOP_HALF_MUSL_SRC_DIR = $(LIBC_TOP_HALF_MUSL_DIR)/src -LIBC_TOP_HALF_MUSL_INC = $(LIBC_TOP_HALF_MUSL_DIR)/include -LIBC_TOP_HALF_MUSL_SOURCES = \ - $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \ - misc/a64l.c \ - misc/basename.c \ - misc/dirname.c \ - misc/ffs.c \ - misc/ffsl.c \ - misc/ffsll.c \ - misc/fmtmsg.c \ - misc/getdomainname.c \ - misc/gethostid.c \ - misc/getopt.c \ - misc/getopt_long.c \ - misc/getsubopt.c \ - misc/uname.c \ - misc/nftw.c \ - errno/strerror.c \ - network/htonl.c \ - network/htons.c \ - network/ntohl.c \ - network/ntohs.c \ - network/inet_ntop.c \ - network/inet_pton.c \ - network/inet_aton.c \ - network/in6addr_any.c \ - network/in6addr_loopback.c \ - fenv/fenv.c \ - fenv/fesetround.c \ - fenv/feupdateenv.c \ - fenv/fesetexceptflag.c \ - fenv/fegetexceptflag.c \ - fenv/feholdexcept.c \ - exit/exit.c \ - exit/atexit.c \ - exit/assert.c \ - exit/quick_exit.c \ - exit/at_quick_exit.c \ - time/strftime.c \ - time/asctime.c \ - time/asctime_r.c \ - time/ctime.c \ - time/ctime_r.c \ - time/wcsftime.c \ - time/strptime.c \ - time/difftime.c \ - time/timegm.c \ - time/ftime.c \ - time/gmtime.c \ - time/gmtime_r.c \ - time/timespec_get.c \ - time/getdate.c \ - time/localtime.c \ - time/localtime_r.c \ - time/mktime.c \ - time/__tm_to_secs.c \ - time/__month_to_secs.c \ - time/__secs_to_tm.c \ - time/__year_to_secs.c \ - time/__tz.c \ - fcntl/creat.c \ - dirent/alphasort.c \ - dirent/versionsort.c \ - env/clearenv.c \ - env/getenv.c \ - env/putenv.c \ - env/setenv.c \ - env/unsetenv.c \ - unistd/posix_close.c \ - stat/futimesat.c \ - legacy/getpagesize.c \ - thread/thrd_sleep.c \ - ) \ - $(filter-out %/procfdname.c %/syscall.c %/syscall_ret.c %/vdso.c %/version.c, \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/*.c)) \ - $(filter-out %/flockfile.c %/funlockfile.c %/__lockfile.c %/ftrylockfile.c \ - %/rename.c \ - %/tmpnam.c %/tmpfile.c %/tempnam.c \ - %/popen.c %/pclose.c \ - %/remove.c \ - %/gets.c, \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/*.c)) \ - $(filter-out %/strsignal.c, \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/*.c)) \ - $(filter-out %/dcngettext.c %/textdomain.c %/bind_textdomain_codeset.c, \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/locale/*.c)) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/*.c) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/search/*.c) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/multibyte/*.c) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/regex/*.c) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/prng/*.c) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/conf/*.c) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/ctype/*.c) \ - $(filter-out %/__signbit.c %/__signbitf.c %/__signbitl.c \ - %/__fpclassify.c %/__fpclassifyf.c %/__fpclassifyl.c \ - %/ceilf.c %/ceil.c \ - %/floorf.c %/floor.c \ - %/truncf.c %/trunc.c \ - %/rintf.c %/rint.c \ - %/nearbyintf.c %/nearbyint.c \ - %/sqrtf.c %/sqrt.c \ - %/fabsf.c %/fabs.c \ - %/copysignf.c %/copysign.c \ - %/fminf.c %/fmaxf.c \ - %/fmin.c %/fmax.c, \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/math/*.c)) \ - $(filter-out %/crealf.c %/creal.c %creall.c \ - %/cimagf.c %/cimag.c %cimagl.c, \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/complex/*.c)) \ - $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/crypt/*.c) - -ifeq ($(THREAD_MODEL), posix) -LIBC_TOP_HALF_MUSL_SOURCES += \ - $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \ - thread/__wait.c \ - thread/__timedwait.c \ - thread/pthread_cleanup_push.c \ - thread/pthread_cond_broadcast.c \ - thread/pthread_cond_destroy.c \ - thread/pthread_cond_init.c \ - thread/pthread_cond_signal.c \ - thread/pthread_cond_timedwait.c \ - thread/pthread_cond_wait.c \ - thread/pthread_condattr_destroy.c \ - thread/pthread_condattr_init.c \ - thread/pthread_condattr_setclock.c \ - thread/pthread_condattr_setpshared.c \ - thread/pthread_create.c \ - thread/pthread_mutex_consistent.c \ - thread/pthread_mutex_destroy.c \ - thread/pthread_mutex_init.c \ - thread/pthread_mutex_getprioceiling.c \ - thread/pthread_mutex_lock.c \ - thread/pthread_mutex_timedlock.c \ - thread/pthread_mutex_trylock.c \ - thread/pthread_mutex_unlock.c \ - thread/pthread_mutexattr_destroy.c \ - thread/pthread_mutexattr_init.c \ - thread/pthread_mutexattr_setprotocol.c \ - thread/pthread_mutexattr_setpshared.c \ - thread/pthread_mutexattr_setrobust.c \ - thread/pthread_mutexattr_settype.c \ - thread/pthread_rwlock_destroy.c \ - thread/pthread_rwlock_init.c \ - thread/pthread_rwlock_rdlock.c \ - thread/pthread_rwlock_timedrdlock.c \ - thread/pthread_rwlock_timedwrlock.c \ - thread/pthread_rwlock_tryrdlock.c \ - thread/pthread_rwlock_trywrlock.c \ - thread/pthread_rwlock_unlock.c \ - thread/pthread_rwlock_wrlock.c \ - thread/pthread_rwlockattr_destroy.c \ - thread/pthread_rwlockattr_init.c \ - thread/pthread_rwlockattr_setpshared.c \ - thread/pthread_setcancelstate.c \ - thread/pthread_testcancel.c \ - thread/sem_destroy.c \ - thread/sem_getvalue.c \ - thread/sem_init.c \ - thread/sem_post.c \ - thread/sem_timedwait.c \ - thread/sem_trywait.c \ - thread/sem_wait.c \ - ) -endif - -MUSL_PRINTSCAN_SOURCES = \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/floatscan.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfprintf.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfwprintf.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfscanf.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/strtod.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/wcstod.c -BULK_MEMORY_SOURCES = \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/memcpy.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/memmove.c \ - $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/memset.c -LIBC_TOP_HALF_HEADERS_PRIVATE = $(LIBC_TOP_HALF_DIR)/headers/private -LIBC_TOP_HALF_SOURCES = $(LIBC_TOP_HALF_DIR)/sources -LIBC_TOP_HALF_ALL_SOURCES = \ - $(LIBC_TOP_HALF_MUSL_SOURCES) \ - $(sort $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.c)) - -# Add any extra flags -CFLAGS = $(EXTRA_CFLAGS) -# Set the target. -CFLAGS += --target=$(TARGET_TRIPLE) -# WebAssembly floating-point match doesn't trap. -# TODO: Add -fno-signaling-nans when the compiler supports it. -CFLAGS += -fno-trapping-math -# Add all warnings, but disable a few which occur in third-party code. -CFLAGS += -Wall -Wextra -Werror \ - -Wno-null-pointer-arithmetic \ - -Wno-unused-parameter \ - -Wno-sign-compare \ - -Wno-unused-variable \ - -Wno-unused-function \ - -Wno-ignored-attributes \ - -Wno-missing-braces \ - -Wno-ignored-pragmas \ - -Wno-unused-but-set-variable \ - -Wno-unknown-warning-option - -# Configure support for threads. -ifeq ($(THREAD_MODEL), single) -CFLAGS += -mthread-model single -endif -ifeq ($(THREAD_MODEL), posix) -# Specify the tls-model until LLVM 15 is released (which should contain -# https://reviews.llvm.org/D130053). -CFLAGS += -mthread-model posix -pthread -ftls-model=local-exec - -# Include cloudlib's directory to access the structure definition of clockid_t -CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -endif - -# Expose the public headers to the implementation. We use `-isystem` for -# purpose for two reasons: -# -# 1. It only does `<...>` not `"...."` lookup. We are making a libc, -# which is a system library, so all public headers should be -# accessible via `<...>` and never also need `"..."`. `-isystem` main -# purpose is to only effect `<...>` lookup. -# -# 2. The `-I` for private headers added for specific C files below -# should come earlier in the search path, so they can "override" -# and/or `#include_next` the public headers. `-isystem` (like -# `-idirafter`) comes later in the search path than `-I`. -CFLAGS += -isystem "$(SYSROOT_INC)" - -# These variables describe the locations of various files and directories in -# the build tree. -objs = $(patsubst $(CURDIR)/%.c,$(OBJDIR)/%.o,$(1)) -DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) -LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) -LIBC_TOP_HALF_ALL_OBJS = $(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)) -ifeq ($(MALLOC_IMPL),dlmalloc) -LIBC_OBJS += $(DLMALLOC_OBJS) -else ifeq ($(MALLOC_IMPL),none) -# No object files to add. -else -$(error unknown malloc implementation $(MALLOC_IMPL)) -endif -# Add libc-bottom-half's objects. -LIBC_OBJS += $(LIBC_BOTTOM_HALF_ALL_OBJS) -ifeq ($(BUILD_LIBC_TOP_HALF),yes) -# libc-top-half is musl. -LIBC_OBJS += $(LIBC_TOP_HALF_ALL_OBJS) -endif -MUSL_PRINTSCAN_OBJS = $(call objs,$(MUSL_PRINTSCAN_SOURCES)) -MUSL_PRINTSCAN_LONG_DOUBLE_OBJS = $(patsubst %.o,%.long-double.o,$(MUSL_PRINTSCAN_OBJS)) -MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS = $(patsubst %.o,%.no-floating-point.o,$(MUSL_PRINTSCAN_OBJS)) -BULK_MEMORY_OBJS = $(call objs,$(BULK_MEMORY_SOURCES)) -LIBWASI_EMULATED_MMAN_OBJS = $(call objs,$(LIBWASI_EMULATED_MMAN_SOURCES)) -LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS = $(call objs,$(LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES)) -LIBWASI_EMULATED_GETPID_OBJS = $(call objs,$(LIBWASI_EMULATED_GETPID_SOURCES)) -LIBWASI_EMULATED_SIGNAL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_SOURCES)) -LIBWASI_EMULATED_SIGNAL_MUSL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES)) - -# These variables describe the locations of various files and -# directories in the generated sysroot tree. -SYSROOT_LIB := $(SYSROOT)/lib/$(MULTIARCH_TRIPLE) -SYSROOT_INC = $(SYSROOT)/include -SYSROOT_SHARE = $(SYSROOT)/share/$(MULTIARCH_TRIPLE) - -# Files from musl's include directory that we don't want to install in the -# sysroot's include directory. -MUSL_OMIT_HEADERS := - -# Remove files which aren't headers (we generate alltypes.h below). -MUSL_OMIT_HEADERS += \ - "bits/syscall.h.in" \ - "bits/alltypes.h.in" \ - "alltypes.h.in" - -# Use the compiler's version of these headers. -MUSL_OMIT_HEADERS += \ - "stdarg.h" \ - "stddef.h" - -# Use the WASI errno definitions. -MUSL_OMIT_HEADERS += \ - "bits/errno.h" - -# Remove headers that aren't supported yet or that aren't relevant for WASI. -MUSL_OMIT_HEADERS += \ - "sys/procfs.h" \ - "sys/user.h" \ - "sys/kd.h" "sys/vt.h" "sys/soundcard.h" "sys/sem.h" \ - "sys/shm.h" "sys/msg.h" "sys/ipc.h" "sys/ptrace.h" \ - "sys/statfs.h" \ - "bits/kd.h" "bits/vt.h" "bits/soundcard.h" "bits/sem.h" \ - "bits/shm.h" "bits/msg.h" "bits/ipc.h" "bits/ptrace.h" \ - "bits/statfs.h" \ - "sys/vfs.h" \ - "sys/statvfs.h" \ - "syslog.h" "sys/syslog.h" \ - "wait.h" "sys/wait.h" \ - "ucontext.h" "sys/ucontext.h" \ - "paths.h" \ - "utmp.h" "utmpx.h" \ - "lastlog.h" \ - "sys/acct.h" \ - "sys/cachectl.h" \ - "sys/epoll.h" "sys/reboot.h" "sys/swap.h" \ - "sys/sendfile.h" "sys/inotify.h" \ - "sys/quota.h" \ - "sys/klog.h" \ - "sys/fsuid.h" \ - "sys/io.h" \ - "sys/prctl.h" \ - "sys/mtio.h" \ - "sys/mount.h" \ - "sys/fanotify.h" \ - "sys/personality.h" \ - "elf.h" "link.h" "bits/link.h" \ - "scsi/scsi.h" "scsi/scsi_ioctl.h" "scsi/sg.h" \ - "sys/auxv.h" \ - "pwd.h" "shadow.h" "grp.h" \ - "mntent.h" \ - "netdb.h" \ - "resolv.h" \ - "pty.h" \ - "dlfcn.h" \ - "setjmp.h" \ - "ulimit.h" \ - "sys/xattr.h" \ - "wordexp.h" \ - "spawn.h" \ - "sys/membarrier.h" \ - "sys/signalfd.h" \ - "termios.h" \ - "sys/termios.h" \ - "bits/termios.h" \ - "net/if.h" \ - "net/if_arp.h" \ - "net/ethernet.h" \ - "net/route.h" \ - "netinet/if_ether.h" \ - "netinet/ether.h" \ - "sys/timerfd.h" \ - "libintl.h" \ - "sys/sysmacros.h" \ - "aio.h" - -ifeq ($(THREAD_MODEL), single) -# Remove headers not supported in single-threaded mode. -MUSL_OMIT_HEADERS += "pthread.h" -endif - -default: finish - -$(SYSROOT_LIB)/libc.a: $(LIBC_OBJS) - -$(SYSROOT_LIB)/libc-printscan-long-double.a: $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) - -$(SYSROOT_LIB)/libc-printscan-no-floating-point.a: $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) - -$(SYSROOT_LIB)/libwasi-emulated-mman.a: $(LIBWASI_EMULATED_MMAN_OBJS) - -$(SYSROOT_LIB)/libwasi-emulated-process-clocks.a: $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) - -$(SYSROOT_LIB)/libwasi-emulated-getpid.a: $(LIBWASI_EMULATED_GETPID_OBJS) - -$(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS) - -%.a: - @mkdir -p "$(@D)" - # On Windows, the commandline for the ar invocation got too long, so it needs to be split up. - $(AR) crs $@ $(wordlist 1, 199, $^) - $(AR) crs $@ $(wordlist 200, 399, $^) - $(AR) crs $@ $(wordlist 400, 599, $^) - $(AR) crs $@ $(wordlist 600, 799, $^) - # This might eventually overflow again, but at least it'll do so in a loud way instead of - # silently dropping the tail. - $(AR) crs $@ $(wordlist 800, 100000, $^) - -$(MUSL_PRINTSCAN_OBJS): CFLAGS += \ - -D__wasilibc_printscan_no_long_double \ - -D__wasilibc_printscan_full_support_option="\"add -lc-printscan-long-double to the link command\"" - -$(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS): CFLAGS += \ - -D__wasilibc_printscan_no_floating_point \ - -D__wasilibc_printscan_floating_point_support_option="\"remove -lc-printscan-no-floating-point from the link command\"" - -# TODO: apply -mbulk-memory globally, once -# https://github.com/llvm/llvm-project/issues/52618 is resolved -$(BULK_MEMORY_OBJS): CFLAGS += \ - -mbulk-memory - -$(BULK_MEMORY_OBJS): CFLAGS += \ - -DBULK_MEMORY_THRESHOLD=$(BULK_MEMORY_THRESHOLD) - -$(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \ - -D_WASI_EMULATED_SIGNAL - -$(OBJDIR)/%.long-double.o: $(CURDIR)/%.c include_dirs - @mkdir -p "$(@D)" - $(CC) $(CFLAGS) -MD -MP -o $@ -c $< - -$(OBJDIR)/%.no-floating-point.o: $(CURDIR)/%.c include_dirs - @mkdir -p "$(@D)" - $(CC) $(CFLAGS) -MD -MP -o $@ -c $< - -$(OBJDIR)/%.o: $(CURDIR)/%.c include_dirs - @mkdir -p "$(@D)" - $(CC) $(CFLAGS) -MD -MP -o $@ -c $< - --include $(shell find $(OBJDIR) -name \*.d) - -$(DLMALLOC_OBJS): CFLAGS += \ - -I$(DLMALLOC_INC) - -startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS): CFLAGS += \ - -I$(LIBC_BOTTOM_HALF_HEADERS_PRIVATE) \ - -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC) \ - -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) \ - -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \ - -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal - -$(LIBC_TOP_HALF_ALL_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \ - -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \ - -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal \ - -I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32 \ - -I$(LIBC_TOP_HALF_MUSL_DIR)/arch/generic \ - -I$(LIBC_TOP_HALF_HEADERS_PRIVATE) \ - -Wno-parentheses \ - -Wno-shift-op-parentheses \ - -Wno-bitwise-op-parentheses \ - -Wno-logical-op-parentheses \ - -Wno-string-plus-int \ - -Wno-dangling-else \ - -Wno-unknown-pragmas - -$(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS): CFLAGS += \ - -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) - -include_dirs: - # - # Install the include files. - # - mkdir -p "$(SYSROOT_INC)" - cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)" - - # Generate musl's bits/alltypes.h header. - mkdir -p "$(SYSROOT_INC)/bits" - sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \ - $(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32/bits/alltypes.h.in \ - $(LIBC_TOP_HALF_MUSL_DIR)/include/alltypes.h.in \ - > "$(SYSROOT_INC)/bits/alltypes.h" - - # Copy in the bulk of musl's public header files. - cp -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)" - # Copy in the musl's "bits" header files. - cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits" - cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits" - - # Remove selected header files. - $(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS)) - -startup_files: include_dirs - # - # Build the startup files. - # - @mkdir -p "$(OBJDIR)" - cd "$(OBJDIR)" && \ - $(CC) $(CFLAGS) -c $(LIBC_BOTTOM_HALF_CRT_SOURCES) -MD -MP && \ - mkdir -p "$(SYSROOT_LIB)" && \ - mv *.o "$(SYSROOT_LIB)" - -libc: include_dirs \ - $(SYSROOT_LIB)/libc.a \ - $(SYSROOT_LIB)/libc-printscan-long-double.a \ - $(SYSROOT_LIB)/libc-printscan-no-floating-point.a \ - $(SYSROOT_LIB)/libwasi-emulated-mman.a \ - $(SYSROOT_LIB)/libwasi-emulated-process-clocks.a \ - $(SYSROOT_LIB)/libwasi-emulated-getpid.a \ - $(SYSROOT_LIB)/libwasi-emulated-signal.a - -finish: startup_files libc - # - # Create empty placeholder libraries. - # - for name in m rt pthread crypt util xnet resolv dl; do \ - $(AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \ - done - - # - # The build succeeded! The generated sysroot is in $(SYSROOT). - # - -# The check for defined and undefined symbols expects there to be a heap -# alloctor (providing malloc, calloc, free, etc). Skip this step if the build -# is done without a malloc implementation. -ifneq ($(MALLOC_IMPL),none) -finish: check-symbols -endif - -DEFINED_SYMBOLS = $(SYSROOT_SHARE)/defined-symbols.txt -UNDEFINED_SYMBOLS = $(SYSROOT_SHARE)/undefined-symbols.txt - -check-symbols: startup_files libc - # - # Collect metadata on the sysroot and perform sanity checks. - # - mkdir -p "$(SYSROOT_SHARE)" - - # - # Collect symbol information. - # - @# TODO: Use llvm-nm --extern-only instead of grep. This is blocked on - @# LLVM PR40497, which is fixed in 9.0, but not in 8.0. - @# Ignore certain llvm builtin symbols such as those starting with __mul - @# since these dependencies can vary between llvm versions. - "$(NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \ - |grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort |uniq > "$(DEFINED_SYMBOLS)" - for undef_sym in $$("$(NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \ - |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \ - grep -q '\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo $$undef_sym; \ - done | grep -v "^__mul" > "$(UNDEFINED_SYMBOLS)" - grep '^_*imported_wasi_' "$(UNDEFINED_SYMBOLS)" \ - > "$(SYSROOT_LIB)/libc.imports" - - # - # Generate a test file that includes all public C header files. - # - cd "$(SYSROOT_INC)" && \ - for header in $$(find . -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h |grep -v /bits/ |grep -v /c++/); do \ - echo '#include <'$$header'>' | sed 's/\.\///' ; \ - done |LC_ALL=C sort >$(SYSROOT_SHARE)/include-all.c ; \ - cd - >/dev/null - - # - # Test that it compiles. - # - $(CC) $(CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings - - # - # Collect all the predefined macros, except for compiler version macros - # which we don't need to track here. - # - @# - @# For the __*_ATOMIC_*_LOCK_FREE macros, squash individual compiler names - @# to attempt, toward keeping these files compiler-independent. - @# - @# We have to add `-isystem $(SYSROOT_INC)` because otherwise clang puts - @# its builtin include path first, which produces compiler-specific - @# output. - @# - @# TODO: Undefine __FLOAT128__ for now since it's not in clang 8.0. - @# TODO: Filter out __FLT16_* for now, as not all versions of clang have these. - @# TODO: Filter out __NO_MATH_ERRNO_ and a few __*WIDTH__ that are new to clang 14. - @# TODO: clang defined __FLT_EVAL_METHOD__ until clang 15, so we force-undefine it - @# for older versions. - $(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \ - -isystem $(SYSROOT_INC) \ - -std=gnu17 \ - -E -dM -Wno-\#warnings \ - -D_ALL_SOURCE \ - -U__llvm__ \ - -U__clang__ \ - -U__clang_major__ \ - -U__clang_minor__ \ - -U__clang_patchlevel__ \ - -U__clang_version__ \ - -U__clang_literal_encoding__ \ - -U__clang_wide_literal_encoding__ \ - -U__GNUC__ \ - -U__GNUC_MINOR__ \ - -U__GNUC_PATCHLEVEL__ \ - -U__VERSION__ \ - -U__FLOAT128__ \ - -U__NO_MATH_ERRNO__ \ - -U__BITINT_MAXWIDTH__ \ - -U__FLT_EVAL_METHOD__ -Wno-builtin-macro-redefined \ - | sed -e 's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \ - | grep -v '^#define __FLT16_' \ - | grep -v '^#define __\(BOOL\|INT_\(LEAST\|FAST\)\(8\|16\|32\|64\)\|INT\|LONG\|LLONG\|SHRT\)_WIDTH__' \ - > "$(SYSROOT_SHARE)/predefined-macros.txt" - - # Check that the computed metadata matches the expected metadata. - # This ignores whitespace because on Windows the output has CRLF line endings. - diff -wur "$(CURDIR)/expected/$(MULTIARCH_TRIPLE)/$(THREAD_MODEL)" "$(SYSROOT_SHARE)" - -install: finish - mkdir -p "$(INSTALL_DIR)" - cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)" +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 +# Default target executed when no arguments are given to make. +default_target: all + +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target install/strip +install/strip: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip + +# Special rule for the target install/strip +install/strip/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." + /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake +.PHONY : install/strip/fast + +# Special rule for the target install/local +install/local: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local + +# Special rule for the target install/local +install/local/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." + /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake +.PHONY : install/local/fast + +# Special rule for the target install +install: preinstall + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /usr/bin/cmake -P cmake_install.cmake +.PHONY : install + +# Special rule for the target install +install/fast: preinstall/fast + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." + /usr/bin/cmake -P cmake_install.cmake +.PHONY : install/fast + +# Special rule for the target list_install_components +list_install_components: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" +.PHONY : list_install_components + +# Special rule for the target list_install_components +list_install_components/fast: list_install_components + +.PHONY : list_install_components/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache + +.PHONY : rebuild_cache/fast + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." + /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache + +.PHONY : edit_cache/fast + +# Special rule for the target test +test: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..." + /usr/bin/ctest --force-new-ctest-process $(ARGS) +.PHONY : test + +# Special rule for the target test +test/fast: test + +.PHONY : test/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc/CMakeFiles /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc/CMakeFiles 0 +.PHONY : all + +# The main clean target clean: - $(RM) -r "$(OBJDIR)" - $(RM) -r "$(SYSROOT)" + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean + +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -P /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc/CMakeFiles/VerifyGlobs.cmake + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named sysroot-headers + +# Build rule for target. +sysroot-headers: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 sysroot-headers +.PHONY : sysroot-headers + +# fast build rule for target. +sysroot-headers/fast: + $(MAKE) -f cmake/CMakeFiles/sysroot-headers.dir/build.make cmake/CMakeFiles/sysroot-headers.dir/build +.PHONY : sysroot-headers/fast + +#============================================================================= +# Target rules for targets named wasi-emulated-signal + +# Build rule for target. +wasi-emulated-signal: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 wasi-emulated-signal +.PHONY : wasi-emulated-signal + +# fast build rule for target. +wasi-emulated-signal/fast: + $(MAKE) -f cmake/CMakeFiles/wasi-emulated-signal.dir/build.make cmake/CMakeFiles/wasi-emulated-signal.dir/build +.PHONY : wasi-emulated-signal/fast + +#============================================================================= +# Target rules for targets named util + +# Build rule for target. +util: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 util +.PHONY : util + +# fast build rule for target. +util/fast: + $(MAKE) -f cmake/CMakeFiles/util.dir/build.make cmake/CMakeFiles/util.dir/build +.PHONY : util/fast + +#============================================================================= +# Target rules for targets named predefined-macros + +# Build rule for target. +predefined-macros: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 predefined-macros +.PHONY : predefined-macros + +# fast build rule for target. +predefined-macros/fast: + $(MAKE) -f cmake/CMakeFiles/predefined-macros.dir/build.make cmake/CMakeFiles/predefined-macros.dir/build +.PHONY : predefined-macros/fast + +#============================================================================= +# Target rules for targets named libc.imports + +# Build rule for target. +libc.imports: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 libc.imports +.PHONY : libc.imports + +# fast build rule for target. +libc.imports/fast: + $(MAKE) -f cmake/CMakeFiles/libc.imports.dir/build.make cmake/CMakeFiles/libc.imports.dir/build +.PHONY : libc.imports/fast + +#============================================================================= +# Target rules for targets named pthread + +# Build rule for target. +pthread: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 pthread +.PHONY : pthread + +# fast build rule for target. +pthread/fast: + $(MAKE) -f cmake/CMakeFiles/pthread.dir/build.make cmake/CMakeFiles/pthread.dir/build +.PHONY : pthread/fast + +#============================================================================= +# Target rules for targets named c + +# Build rule for target. +c : cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 c +.PHONY : c + +# fast build rule for target. +c/fast: + $(MAKE) -f cmake/CMakeFiles/c.dir/build.make cmake/CMakeFiles/c.dir/build +.PHONY : c/fast + +#============================================================================= +# Target rules for targets named m + +# Build rule for target. +m : cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 m +.PHONY : m + +# fast build rule for target. +m/fast: + $(MAKE) -f cmake/CMakeFiles/m.dir/build.make cmake/CMakeFiles/m.dir/build +.PHONY : m/fast + +#============================================================================= +# Target rules for targets named rt + +# Build rule for target. +rt: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 rt +.PHONY : rt + +# fast build rule for target. +rt/fast: + $(MAKE) -f cmake/CMakeFiles/rt.dir/build.make cmake/CMakeFiles/rt.dir/build +.PHONY : rt/fast + +#============================================================================= +# Target rules for targets named crypt + +# Build rule for target. +crypt: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crypt +.PHONY : crypt + +# fast build rule for target. +crypt/fast: + $(MAKE) -f cmake/CMakeFiles/crypt.dir/build.make cmake/CMakeFiles/crypt.dir/build +.PHONY : crypt/fast + +#============================================================================= +# Target rules for targets named resolve + +# Build rule for target. +resolve: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 resolve +.PHONY : resolve + +# fast build rule for target. +resolve/fast: + $(MAKE) -f cmake/CMakeFiles/resolve.dir/build.make cmake/CMakeFiles/resolve.dir/build +.PHONY : resolve/fast + +#============================================================================= +# Target rules for targets named dl + +# Build rule for target. +dl: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 dl +.PHONY : dl + +# fast build rule for target. +dl/fast: + $(MAKE) -f cmake/CMakeFiles/dl.dir/build.make cmake/CMakeFiles/dl.dir/build +.PHONY : dl/fast + +#============================================================================= +# Target rules for targets named xnet + +# Build rule for target. +xnet: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 xnet +.PHONY : xnet + +# fast build rule for target. +xnet/fast: + $(MAKE) -f cmake/CMakeFiles/xnet.dir/build.make cmake/CMakeFiles/xnet.dir/build +.PHONY : xnet/fast + +#============================================================================= +# Target rules for targets named libc-bottom-half + +# Build rule for target. +libc-bottom-half: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 libc-bottom-half +.PHONY : libc-bottom-half + +# fast build rule for target. +libc-bottom-half/fast: + $(MAKE) -f cmake/libc-bottom-half/CMakeFiles/libc-bottom-half.dir/build.make cmake/libc-bottom-half/CMakeFiles/libc-bottom-half.dir/build +.PHONY : libc-bottom-half/fast + +#============================================================================= +# Target rules for targets named wasi-emulated-process-clocks + +# Build rule for target. +wasi-emulated-process-clocks: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 wasi-emulated-process-clocks +.PHONY : wasi-emulated-process-clocks + +# fast build rule for target. +wasi-emulated-process-clocks/fast: + $(MAKE) -f cmake/libc-bottom-half/clocks/CMakeFiles/wasi-emulated-process-clocks.dir/build.make cmake/libc-bottom-half/clocks/CMakeFiles/wasi-emulated-process-clocks.dir/build +.PHONY : wasi-emulated-process-clocks/fast + +#============================================================================= +# Target rules for targets named wasi-emulated-getpid + +# Build rule for target. +wasi-emulated-getpid: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 wasi-emulated-getpid +.PHONY : wasi-emulated-getpid + +# fast build rule for target. +wasi-emulated-getpid/fast: + $(MAKE) -f cmake/libc-bottom-half/getpid/CMakeFiles/wasi-emulated-getpid.dir/build.make cmake/libc-bottom-half/getpid/CMakeFiles/wasi-emulated-getpid.dir/build +.PHONY : wasi-emulated-getpid/fast + +#============================================================================= +# Target rules for targets named wasi-emulated-mman + +# Build rule for target. +wasi-emulated-mman: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 wasi-emulated-mman +.PHONY : wasi-emulated-mman + +# fast build rule for target. +wasi-emulated-mman/fast: + $(MAKE) -f cmake/libc-bottom-half/mman/CMakeFiles/wasi-emulated-mman.dir/build.make cmake/libc-bottom-half/mman/CMakeFiles/wasi-emulated-mman.dir/build +.PHONY : wasi-emulated-mman/fast + +#============================================================================= +# Target rules for targets named wasi-emulated-signal-objs + +# Build rule for target. +wasi-emulated-signal-objs: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 wasi-emulated-signal-objs +.PHONY : wasi-emulated-signal-objs + +# fast build rule for target. +wasi-emulated-signal-objs/fast: + $(MAKE) -f cmake/libc-bottom-half/signal/CMakeFiles/wasi-emulated-signal-objs.dir/build.make cmake/libc-bottom-half/signal/CMakeFiles/wasi-emulated-signal-objs.dir/build +.PHONY : wasi-emulated-signal-objs/fast + +#============================================================================= +# Target rules for targets named crt1.o + +# Build rule for target. +crt1.o: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crt1.o +.PHONY : crt1.o + +# fast build rule for target. +crt1.o/fast: + $(MAKE) -f cmake/libc-bottom-half/crt1/CMakeFiles/crt1.o.dir/build.make cmake/libc-bottom-half/crt1/CMakeFiles/crt1.o.dir/build +.PHONY : crt1.o/fast + +#============================================================================= +# Target rules for targets named crt1 + +# Build rule for target. +crt1: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crt1 +.PHONY : crt1 + +# fast build rule for target. +crt1/fast: + $(MAKE) -f cmake/libc-bottom-half/crt1/CMakeFiles/crt1.dir/build.make cmake/libc-bottom-half/crt1/CMakeFiles/crt1.dir/build +.PHONY : crt1/fast + +#============================================================================= +# Target rules for targets named crt1-reactor.o + +# Build rule for target. +crt1-reactor.o: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crt1-reactor.o +.PHONY : crt1-reactor.o + +# fast build rule for target. +crt1-reactor.o/fast: + $(MAKE) -f cmake/libc-bottom-half/crt1/CMakeFiles/crt1-reactor.o.dir/build.make cmake/libc-bottom-half/crt1/CMakeFiles/crt1-reactor.o.dir/build +.PHONY : crt1-reactor.o/fast + +#============================================================================= +# Target rules for targets named crt1-reactor + +# Build rule for target. +crt1-reactor: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crt1-reactor +.PHONY : crt1-reactor + +# fast build rule for target. +crt1-reactor/fast: + $(MAKE) -f cmake/libc-bottom-half/crt1/CMakeFiles/crt1-reactor.dir/build.make cmake/libc-bottom-half/crt1/CMakeFiles/crt1-reactor.dir/build +.PHONY : crt1-reactor/fast + +#============================================================================= +# Target rules for targets named crt1-command.o + +# Build rule for target. +crt1-command.o: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crt1-command.o +.PHONY : crt1-command.o + +# fast build rule for target. +crt1-command.o/fast: + $(MAKE) -f cmake/libc-bottom-half/crt1/CMakeFiles/crt1-command.o.dir/build.make cmake/libc-bottom-half/crt1/CMakeFiles/crt1-command.o.dir/build +.PHONY : crt1-command.o/fast + +#============================================================================= +# Target rules for targets named crt1-command + +# Build rule for target. +crt1-command: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 crt1-command +.PHONY : crt1-command + +# fast build rule for target. +crt1-command/fast: + $(MAKE) -f cmake/libc-bottom-half/crt1/CMakeFiles/crt1-command.dir/build.make cmake/libc-bottom-half/crt1/CMakeFiles/crt1-command.dir/build +.PHONY : crt1-command/fast + +#============================================================================= +# Target rules for targets named libc-top-half + +# Build rule for target. +libc-top-half: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 libc-top-half +.PHONY : libc-top-half + +# fast build rule for target. +libc-top-half/fast: + $(MAKE) -f cmake/libc-top-half/CMakeFiles/libc-top-half.dir/build.make cmake/libc-top-half/CMakeFiles/libc-top-half.dir/build +.PHONY : libc-top-half/fast + +#============================================================================= +# Target rules for targets named wasi-emulated-signal-musl-objs + +# Build rule for target. +wasi-emulated-signal-musl-objs: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 wasi-emulated-signal-musl-objs +.PHONY : wasi-emulated-signal-musl-objs + +# fast build rule for target. +wasi-emulated-signal-musl-objs/fast: + $(MAKE) -f cmake/libc-top-half/musl/CMakeFiles/wasi-emulated-signal-musl-objs.dir/build.make cmake/libc-top-half/musl/CMakeFiles/wasi-emulated-signal-musl-objs.dir/build +.PHONY : wasi-emulated-signal-musl-objs/fast + +#============================================================================= +# Target rules for targets named c-printscan-long-double + +# Build rule for target. +c-printscan-long-double: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 c-printscan-long-double +.PHONY : c-printscan-long-double + +# fast build rule for target. +c-printscan-long-double/fast: + $(MAKE) -f cmake/libc-top-half/musl/CMakeFiles/c-printscan-long-double.dir/build.make cmake/libc-top-half/musl/CMakeFiles/c-printscan-long-double.dir/build +.PHONY : c-printscan-long-double/fast + +#============================================================================= +# Target rules for targets named c-printscan-no-floating-point + +# Build rule for target. +c-printscan-no-floating-point: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 c-printscan-no-floating-point +.PHONY : c-printscan-no-floating-point + +# fast build rule for target. +c-printscan-no-floating-point/fast: + $(MAKE) -f cmake/libc-top-half/musl/CMakeFiles/c-printscan-no-floating-point.dir/build.make cmake/libc-top-half/musl/CMakeFiles/c-printscan-no-floating-point.dir/build +.PHONY : c-printscan-no-floating-point/fast + +#============================================================================= +# Target rules for targets named dlmalloc + +# Build rule for target. +dlmalloc: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 dlmalloc +.PHONY : dlmalloc + +# fast build rule for target. +dlmalloc/fast: + $(MAKE) -f cmake/dlmalloc/CMakeFiles/dlmalloc.dir/build.make cmake/dlmalloc/CMakeFiles/dlmalloc.dir/build +.PHONY : dlmalloc/fast + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... install/strip" + @echo "... install/local" + @echo "... install" + @echo "... list_install_components" + @echo "... rebuild_cache" + @echo "... edit_cache" + @echo "... test" + @echo "... sysroot-headers" + @echo "... wasi-emulated-signal" + @echo "... util" + @echo "... predefined-macros" + @echo "... libc.imports" + @echo "... pthread" + @echo "... c" + @echo "... m" + @echo "... rt" + @echo "... crypt" + @echo "... resolve" + @echo "... dl" + @echo "... xnet" + @echo "... libc-bottom-half" + @echo "... wasi-emulated-process-clocks" + @echo "... wasi-emulated-getpid" + @echo "... wasi-emulated-mman" + @echo "... wasi-emulated-signal-objs" + @echo "... crt1.o" + @echo "... crt1" + @echo "... crt1-reactor.o" + @echo "... crt1-reactor" + @echo "... crt1-command.o" + @echo "... crt1-command" + @echo "... libc-top-half" + @echo "... wasi-emulated-signal-musl-objs" + @echo "... c-printscan-long-double" + @echo "... c-printscan-no-floating-point" + @echo "... dlmalloc" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -P /home/ANT.AMAZON.COM/mkolny/wasm-threads/wasi-libc/CMakeFiles/VerifyGlobs.cmake + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system -.PHONY: default startup_files libc finish install include_dirs clean diff --git a/cmake/libc-imports.cmake b/cmake/libc-imports.cmake index f0db9e971..8fcb9fa50 100644 --- a/cmake/libc-imports.cmake +++ b/cmake/libc-imports.cmake @@ -1,4 +1,5 @@ add_custom_command(OUTPUT ${SYSROOT_LIB_DIR}/libc.imports + COMMAND ${CMAKE_COMMAND} -E make_directory ${SYSROOT_LIB_DIR} COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/gen-imports.py --nm ${CMAKE_NM}