Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile the minipal as an object and static library #107889

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Due to how we build the libraries native build as part of the CoreCLR build as well as standalone,
# we can end up coming to this file twice. Only run it once to simplify our build.
include_guard()

include(${CMAKE_CURRENT_LIST_DIR}/configuretools.cmake)

# Set initial flags for each configuration
Expand Down
2 changes: 1 addition & 1 deletion eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ endfunction()
function(add_sanitizer_runtime_support targetName)
# Add sanitizer support functions.
if (CLR_CMAKE_ENABLE_ASAN)
target_sources(${targetName} PRIVATE "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:${CLR_SRC_NATIVE_DIR}/minipal/asansupport.cpp>")
target_link_libraries(${targetName} PRIVATE $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:minipal_sanitizer_support>)
endif()
endfunction()

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ include (${CLR_SRC_NATIVE_DIR}/eventpipe/configure.cmake)

add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal)

if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(debug/debug-pal)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ else(CLR_CMAKE_HOST_WIN32)
datatarget.cpp
dumpwriter.cpp
crashreportwriter.cpp
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c
)

if(CLR_CMAKE_HOST_OSX)
Expand All @@ -88,6 +87,7 @@ else()
${CREATEDUMP_SOURCES}
)
endif(CLR_CMAKE_HOST_OSX)
target_link_libraries(createdump_static PRIVATE minipal)

add_executable_clr(createdump
main.cpp
Expand All @@ -104,6 +104,8 @@ endif(CLR_CMAKE_HOST_OSX)

endif(CLR_CMAKE_HOST_WIN32)

target_link_libraries(createdump PRIVATE minipal)

if (CLR_CMAKE_HOST_APPLE)
adhoc_sign_with_entitlements(createdump "${CLR_ENG_NATIVE_DIR}/createdump-entitlements.plist")
endif()
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/minipal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ if (CLR_CMAKE_HOST_UNIX)
else (CLR_CMAKE_HOST_UNIX)
add_subdirectory(Windows)
endif (CLR_CMAKE_HOST_UNIX)

10 changes: 1 addition & 9 deletions src/coreclr/minipal/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
set(SOURCES
doublemapping.cpp
dn-u16.cpp
${CLR_SRC_NATIVE_DIR}/minipal/time.c
)

if(NOT CLR_CROSS_COMPONENTS_BUILD)
list(APPEND SOURCES
${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c
)
endif()

add_library(coreclrminipal
STATIC
${SOURCES}
)

include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(coreclrminipal PRIVATE minipal)
11 changes: 2 additions & 9 deletions src/coreclr/minipal/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
set(SOURCES
doublemapping.cpp
dn-u16.cpp
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c
${CLR_SRC_NATIVE_DIR}/minipal/time.c
)

if(NOT CLR_CROSS_COMPONENTS_BUILD)
list(APPEND SOURCES
${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c
)
endif()

add_library(coreclrminipal
STATIC
${SOURCES}
)

target_link_libraries(coreclrminipal PRIVATE minipal)
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int main(int argc, char* argv[])
// the linker can detect that we have ASAN components early enough in the build.
// Include our asan support sources for executable projects here to ensure they
// are compiled into the bootstrapper object.
#include "minipal/asansupport.cpp"
#include "minipal/sansupport.c"
#endif // HAS_ADDRESS_SANITIZER

#endif // !NATIVEAOT_DLL
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ set(COMMON_RUNTIME_SOURCES
${GC_DIR}/handletablescan.cpp
${GC_DIR}/objecthandle.cpp
${GC_DIR}/softwarewritewatch.cpp

${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c
${CLR_SRC_NATIVE_DIR}/minipal/time.c
)

set(SERVER_GC_SOURCES
Expand Down Expand Up @@ -276,7 +273,6 @@ else()
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
endif()

Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ endif (CLR_CMAKE_TARGET_WIN32)

add_library(Runtime.WorkstationGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${RUNTIME_ARCH_ASM_OBJECTS})
add_dependencies(Runtime.WorkstationGC aot_eventing_headers)
target_link_libraries(Runtime.WorkstationGC PRIVATE minipal_objects)
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

add_library(Runtime.ServerGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS})
add_dependencies(Runtime.ServerGC aot_eventing_headers)
target_link_libraries(Runtime.ServerGC PRIVATE minipal_objects)

add_library(standalonegc-disabled STATIC ${STANDALONEGC_DISABLED_SOURCES})
add_dependencies(standalonegc-disabled aot_eventing_headers)
Expand Down Expand Up @@ -60,6 +62,7 @@ if (CLR_CMAKE_TARGET_WIN32)
add_library(Runtime.ServerGC.GuardCF STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS})
target_compile_definitions(Runtime.ServerGC.GuardCF PRIVATE -DFEATURE_SVR_GC)
set_target_properties(Runtime.ServerGC.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON)
target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects.GuardCF)

if (CLR_CMAKE_TARGET_ARCH_AMD64)
add_library(Runtime.VxsortEnabled.GuardCF STATIC ${VXSORT_SOURCES})
Expand Down Expand Up @@ -127,4 +130,4 @@ if (CLR_CMAKE_TARGET_ARCH_AMD64)
if (CLR_CMAKE_TARGET_WIN32)
install_static_library(Runtime.VxsortEnabled.GuardCF aotsdk nativeaot)
endif (CLR_CMAKE_TARGET_WIN32)
endif (CLR_CMAKE_TARGET_ARCH_AMD64)
endif (CLR_CMAKE_TARGET_ARCH_AMD64)
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project(PortableRuntime)
add_definitions(-DUSE_PORTABLE_HELPERS)

add_library(PortableRuntime STATIC ${COMMON_RUNTIME_SOURCES} ${PORTABLE_RUNTIME_SOURCES})
target_link_libraries(PortableRuntime PRIVATE minipal_objects)

# Get the current list of definitions
get_compile_definitions(DEFINITIONS)
Expand Down
18 changes: 0 additions & 18 deletions src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,8 @@ endif()

set(AOT_EVENTPIPE_SHIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

set (MINIPAL_SOURCES "")
set (EVENTPIPE_SOURCES "")

set (SHARED_MINIPAL_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/minipal")

list(APPEND MINIPAL_SOURCES
utf8.c
)

if(CLR_CMAKE_HOST_UNIX)
include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake)
list(APPEND MINIPAL_SOURCES
random.c
)

endif(CLR_CMAKE_HOST_UNIX)

addprefix(MINIPAL_SOURCES ${SHARED_MINIPAL_SOURCE_PATH} "${MINIPAL_SOURCES}")

list(APPEND AOT_EVENTPIPE_SHIM_SOURCES
${AOT_EVENTPIPE_SHIM_DIR}/ep-rt-aot.cpp
${AOT_EVENTPIPE_SHIM_DIR}/ds-rt-aot.cpp
Expand Down Expand Up @@ -218,7 +201,6 @@ list(APPEND EVENTPIPE_SOURCES
${AOT_EVENTTRACE_SOURCES}
${GEN_EVENTPIPE_PROVIDER_SOURCES}
${GEN_EVENTPIPE_PLAT_AGNOSTIC_SOURCES}
${MINIPAL_SOURCES}
)

list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ set(SOURCES
init/sxs.cpp
loader/module.cpp
locale/unicode.cpp
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c
${CLR_SRC_NATIVE_DIR}/minipal/unicodedata.c
map/common.cpp
map/map.cpp
map/virtual.cpp
Expand Down Expand Up @@ -338,6 +336,9 @@ if(CLR_CMAKE_TARGET_SUNOS)
)
endif(CLR_CMAKE_TARGET_SUNOS)

target_link_libraries(coreclrpal
PRIVATE minipal)

if(FEATURE_EVENT_TRACE)
add_subdirectory(eventprovider)
endif(FEATURE_EVENT_TRACE)
Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/tools/aot/jitinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ set(NATIVE_SOURCES
jitinterface.cpp
jitwrapper.cpp
corinfoexception.cpp

${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c
)

if(CLR_CMAKE_TARGET_WIN32)
set(JITINTERFACE_RESOURCES Native.rc)
else()
include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
endif()

add_library_clr(jitinterface_${ARCH_HOST_NAME}
Expand All @@ -22,5 +17,7 @@ add_library_clr(jitinterface_${ARCH_HOST_NAME}
${JITINTERFACE_RESOURCES}
)

target_link_libraries(jitinterface_${ARCH_HOST_NAME} PRIVATE minipal)

install_clr(TARGETS jitinterface_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT jit)
install_clr(TARGETS jitinterface_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT alljits)
1 change: 1 addition & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ endif()
### End of OS specific checks

include_directories("${CLR_SRC_NATIVE_DIR}")
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal)

if(NOT DISABLE_LIBS)
set(INSTALL_MONO_API 1)
Expand Down
8 changes: 2 additions & 6 deletions src/mono/mono/eglib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ set(eglib_common_sources
gpath.c
gfile.c
gfile-posix.c
gutf8.c
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c)

if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN")
set_source_files_properties("${CLR_SRC_NATIVE_DIR}/minipal/utf8.c" PROPERTIES COMPILE_FLAGS "-DBIGENDIAN=1")
endif()
gutf8.c)

set(eglib_headers
glib.h
Expand All @@ -67,3 +62,4 @@ target_include_directories(eglib_objects PRIVATE
${PROJECT_BINARY_DIR}/../..
${PROJECT_SOURCE_DIR})
target_link_libraries (eglib_objects PUBLIC eglib_api)
target_link_libraries(eglib_objects PUBLIC minipal)
2 changes: 1 addition & 1 deletion src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ endif()

add_library(monosgen-static STATIC $<TARGET_OBJECTS:eglib_objects> $<TARGET_OBJECTS:utils_objects> $<TARGET_OBJECTS:sgen_objects> $<TARGET_OBJECTS:metadata_objects> $<TARGET_OBJECTS:monosgen-objects>)
set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME})
target_link_libraries(monosgen-static PRIVATE dn-containers)
target_link_libraries(monosgen-static PRIVATE dn-containers minipal)

if(DISABLE_COMPONENTS OR AOT_COMPONENTS)
# add component fallback stubs into static mono library when components have been disabled.
Expand Down
11 changes: 8 additions & 3 deletions src/native/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ cmake_minimum_required(VERSION 3.20)

include(CheckCCompilerFlag)

project(CoreFX C)
project(LibsNative C)

include(../../../eng/native/configurepaths.cmake)
include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake)
if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
# This is our root CMakeList.txt, so we need to set up some global settings and include the minipal here.
include(../../../eng/native/configurepaths.cmake)
include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake)

add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal)
endif()

include_directories(${CLR_SRC_NATIVE_DIR})

Expand Down
15 changes: 1 addition & 14 deletions src/native/libs/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ if (CLR_CMAKE_TARGET_OSX)
add_definitions(-D_DARWIN_C_SOURCE)
endif ()

set (MINIPAL_SOURCES "")
set (SHARED_MINIPAL_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/minipal")

include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake)
list(APPEND MINIPAL_SOURCES
random.c
)

addprefix(MINIPAL_SOURCES ${SHARED_MINIPAL_SOURCE_PATH} "${MINIPAL_SOURCES}")

set(NATIVE_SOURCES
pal_errno.c
pal_interfaceaddresses.c
Expand All @@ -35,10 +25,6 @@ set(NATIVE_SOURCES
pal_sysctl.c
)

list(APPEND NATIVE_SOURCES
${MINIPAL_SOURCES}
)

if (NOT CLR_CMAKE_TARGET_WASI)
list (APPEND NATIVE_SOURCES
pal_dynamicload.c
Expand Down Expand Up @@ -126,6 +112,7 @@ if (GEN_SHARED_LIB)

target_link_libraries(System.Native
PRIVATE
minipal
${NATIVE_LIBS_EXTRA}
)

Expand Down
30 changes: 30 additions & 0 deletions src/native/minipal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include(configure.cmake)

# Provide an object library for scenarios where we ship static libraries
add_library(minipal_objects OBJECT
cpufeatures.c
random.c
time.c
unicodedata.c
utf8.c)

add_library(minipal_objects.GuardCF OBJECT
cpufeatures.c
random.c
time.c
unicodedata.c
utf8.c)

target_include_directories(minipal_objects PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(minipal_objects.GuardCF PRIVATE ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(minipal_objects.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON)

# Provide a static library for our shared library and executable scenarios
# for easier usability.
add_library(minipal STATIC)
target_link_libraries(minipal PRIVATE minipal_objects.GuardCF)
set_target_properties(minipal PROPERTIES CLR_CONTROL_FLOW_GUARD ON)

add_library(minipal_sanitizer_support OBJECT
sansupport.c)
set_target_properties(minipal_sanitizer_support PROPERTIES CLR_CONTROL_FLOW_GUARD ON)
5 changes: 5 additions & 0 deletions src/native/minipal/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME)

check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF)
check_symbol_exists(O_CLOEXEC fcntl.h HAVE_O_CLOEXEC)
check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H)

check_symbol_exists(
clock_gettime_nsec_np
time.h
HAVE_CLOCK_GETTIME_NSEC_NP)

if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN")
set(BIGENDIAN 1)
endif()

configure_file(${CMAKE_CURRENT_LIST_DIR}/minipalconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/minipalconfig.h)
2 changes: 2 additions & 0 deletions src/native/minipal/minipalconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
#cmakedefine01 HAVE_O_CLOEXEC
#cmakedefine01 HAVE_SYSCTLBYNAME
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 BIGENDIAN
#cmakedefine01 HAVE_BCRYPT_H

#endif
Loading
Loading