Skip to content

Commit

Permalink
Windows, Unix, MacOS and NativeAOT adjustments for successful build
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossanlop committed May 20, 2024
1 parent 9862ea1 commit c65dad0
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 142 deletions.
1 change: 1 addition & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if (MSVC)
#shrink pdb size
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /PDBCOMPRESS")

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUGTYPE:CV,FIXUP")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /IGNORE:4197,4013,4254,4070,4221")
Expand Down
4 changes: 2 additions & 2 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function(preprocess_file inputFilename outputFilename)
get_compile_definitions(PREPROCESS_DEFINITIONS)
get_include_directories(PREPROCESS_INCLUDE_DIRECTORIES)
get_source_file_property(SOURCE_FILE_DEFINITIONS ${inputFilename} COMPILE_DEFINITIONS)

foreach(DEFINITION IN LISTS SOURCE_FILE_DEFINITIONS)
list(APPEND PREPROCESS_DEFINITIONS -D${DEFINITION})
endforeach()
Expand Down Expand Up @@ -508,7 +508,7 @@ function(install_static_library targetName destination component)
if (WIN32)
set_target_properties(${targetName} PROPERTIES
COMPILE_PDB_NAME "${targetName}"
COMPILE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}"
COMPILE_PDB_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:${targetName}>"
)
install (FILES "$<TARGET_FILE_DIR:${targetName}>/${targetName}.pdb" DESTINATION ${destination} COMPONENT ${component})
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<NativeLibrary Condition="'$(_targetArchitecture)' == 'x64'" Include="$(IlcSdkPath)$(VxSortSupportName)$(LibrarySuffix)" />
<NativeLibrary Condition="'$(IlcMultiModule)' == 'true'" Include="$(SharedLibrary)" />
<NativeLibrary Include="$(IlcSdkPath)$(StandaloneGCSupportName)$(LibrarySuffix)" />
<NativeLibrary Include="$(IlcSdkPath)zlibstatic$(LibFileExt)" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 2 additions & 13 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "emscripten")
set(DISABLE_SHARED_LIBS 1)
# sys/random.h exists, but its not found
set(HAVE_SYS_RANDOM_H 1)
set(INTERNAL_ZLIB 1)
elseif(CLR_CMAKE_HOST_OS STREQUAL "wasi")
set(HOST_WASI 1)
add_definitions(-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -DHOST_WASI)
Expand All @@ -261,7 +260,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "wasi")
add_compile_options(-Wno-unused-but-set-variable)
set(ENABLE_PERFTRACING 0)
set(DISABLE_SHARED_LIBS 1)
set(INTERNAL_ZLIB 1)
set(DISABLE_EXECUTABLES 1)
set(STATIC_COMPONENTS 1)
elseif(CLR_CMAKE_HOST_OS STREQUAL "windows")
Expand All @@ -270,7 +268,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "windows")
set(HOST_NO_SYMLINKS 1)
set(MONO_KEYWORD_THREAD "__declspec (thread)")
set(MONO_ZERO_LEN_ARRAY 1)
set(INTERNAL_ZLIB 1)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") # statically link VC runtime library
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W4>) # set warning level 4
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors
Expand Down Expand Up @@ -511,17 +508,9 @@ if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64))
set(TARGET_APPLE_MOBILE 1)
endif()

# Decide if we need zlib, and if so whether we want the system zlib or the in-tree copy.
# Decide if we need zlib-ng.
if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ)
if(INTERNAL_ZLIB)
# defines ZLIB_SOURCES
include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake)
else()
# if we're not on a platform where we use the in-tree zlib, require system zlib
include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake)
set(Z_LIBS)
append_extra_compression_libs(Z_LIBS)
endif()
include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake)
endif()

######################################
Expand Down
3 changes: 0 additions & 3 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@
/* Define to 1 if you have the <unwind.h> header file. */
#cmakedefine HAVE_UNWIND_H 1

/* Use in-tree zlib */
#cmakedefine INTERNAL_ZLIB 1

/* Define to 1 if you have the <poll.h> header file. */
#cmakedefine HAVE_POLL_H 1

Expand Down
10 changes: 5 additions & 5 deletions src/mono/mono/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(metadata C)
#
if(DISABLE_ICALL_TABLES)
add_library(mono-icall-table STATIC "icall-table.c")
target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api)
target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api zlibstatic)
target_include_directories(mono-icall-table PRIVATE ${PROJECT_BINARY_DIR}/../..
${PROJECT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/..)
Expand Down Expand Up @@ -200,10 +200,10 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${
if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS)
add_library(metadata_objects_shared OBJECT ${metadata_sources})
target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions})
target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared)
target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlibstatic)
# note: metadata_objects is an object library, so this doesn't force linking with sgen,
# it just adds the relevant include directories - which we need even with Boehm
target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared)
target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared zlibstatic)
target_compile_definitions(metadata_objects_shared PRIVATE -DMONO_DLL_EXPORT)
target_include_directories(metadata_objects_shared PRIVATE ${PROJECT_BINARY_DIR}/../..
${PROJECT_SOURCE_DIR}/../..
Expand All @@ -212,10 +212,10 @@ endif()

add_library(metadata_objects OBJECT ${metadata_sources})
target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions})
target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects)
target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlibstatic)
# note: metadata_objects is an object library, so this doesn't force linking with sgen,
# it just adds the relevant include directories - which we need even with Boehm
target_link_libraries(metadata_objects PRIVATE sgen_objects)
target_link_libraries(metadata_objects PRIVATE sgen_objects zlibstatic)
if(NOT HOST_WIN32)
target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT)
endif()
Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono/metadata/debug-mono-ppdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
#include <mono/utils/mono-logger-internals.h>

#ifndef DISABLE_EMBEDDED_PDB
#ifdef INTERNAL_ZLIB
#include <external/zlib/zlib.h>
#else
#include <zlib.h>
#endif
#endif

#include "debug-mono-ppdb.h"

Expand Down
27 changes: 12 additions & 15 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ endif()

if(ENABLE_INTERP_LIB)
add_library(mono-ee-interp STATIC "${interp_sources}")
target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api)
target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api zlibstatic)
target_include_directories(mono-ee-interp PRIVATE ${PROJECT_BINARY_DIR}/../..
${PROJECT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/..)
Expand Down Expand Up @@ -322,19 +322,16 @@ elseif(NOT HOST_BROWSER AND NOT HOST_WASI)
set(mini_sources "${mini_sources};${VERSION_FILE_PATH}") # this is generated by GenerateNativeVersionFile in Arcade
endif()

set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}")
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}")

set(monosgen-sources "${mini_sources};${ZLIB_SOURCES}")
set(monosgen-sources "${mini_sources}")

if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS)
add_library(monosgen-objects_shared OBJECT "${monosgen-sources}")
target_compile_definitions(monosgen-objects_shared PRIVATE -DMONO_DLL_EXPORT)
target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared)
target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared zlibstatic)
endif()

add_library(monosgen-objects OBJECT "${monosgen-sources}")
target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects)
target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects zlibstatic)
if(NOT HOST_WIN32)
target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT)
endif()
Expand All @@ -359,16 +356,16 @@ if(NOT DISABLE_SHARED_LIBS)
target_compile_definitions(monosgen-shared PRIVATE -DMONO_DLL_EXPORT)
# musl-libc implements ucontext in a different library on s390x
if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
target_link_libraries(monosgen-shared PRIVATE ucontext)
target_link_libraries(monosgen-shared PRIVATE ucontext zlibstatic)
endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME})
if(MONO_SET_RPATH_ORIGIN)
set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
if(HOST_WIN32)
target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared)
target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared zlibstatic)
else()
target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects)
target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects zlibstatic)
endif()
target_include_directories (monosgen-shared PRIVATE monoapi)
if(TARGET_WIN32)
Expand Down Expand Up @@ -402,7 +399,7 @@ if(NOT DISABLE_SHARED_LIBS)
install_with_stripped_symbols(monosgen-shared TARGETS lib)
if(HOST_WIN32 AND TARGET_AMD64)
add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c")
target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api)
target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api zlibstatic)
set_target_properties(monosgen-shared-dac PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}-dac)
endif()

Expand All @@ -424,7 +421,7 @@ if(NOT DISABLE_SHARED_LIBS)
endif()
add_library(${frameworkconfig} SHARED $<TARGET_OBJECTS:monosgen-objects>)
target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT)
target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects)
target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects zlibstatic)
target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS})

set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0")
Expand Down Expand Up @@ -541,14 +538,14 @@ if(NOT DISABLE_EXECUTABLES)
set_target_properties(mono-sgen PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
endif()
target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static)
target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static zlibstatic)
if (HOST_WASM)
target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd)
target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd zlibstatic)
endif()
target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS})
# musl-libc implements ucontext in a different library on s390x
if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
target_link_libraries(mono-sgen PRIVATE ucontext)
target_link_libraries(mono-sgen PRIVATE ucontex zlibstatic)
endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
if(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS AND NOT DISABLE_LINK_STATIC_COMPONENTS)
# if components are built statically, link them into runtime.
Expand Down
6 changes: 2 additions & 4 deletions src/mono/mono/profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ include_directories(
if(NOT DISABLE_LIBS)
if(HOST_ANDROID OR HOST_IOS OR HOST_TVOS OR HOST_S390X)
# Build the logging profiler only for certain platforms
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}")
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}")
add_library(mono-profiler-log SHARED helper.c log.c log-args.c ${ZLIB_SOURCES})
add_library(mono-profiler-log SHARED helper.c log.c log-args.c)
target_compile_definitions(mono-profiler-log PRIVATE -DMONO_DLL_EXPORT)
target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects)
target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects zlibstatic)
if(HOST_ANDROID)
target_link_libraries(mono-profiler-log PRIVATE log)
endif()
Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono/profiler/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@
#include <sys/socket.h>
#endif
#ifndef DISABLE_LOG_PROFILER_GZ
#ifdef INTERNAL_ZLIB
#include <external/zlib/zlib.h>
#else
#include <zlib.h>
#endif
#endif

#ifdef HOST_WIN32
#include <winsock2.h>
Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono/profiler/mprof-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
#endif
#include <stdlib.h>
#ifndef DISABLE_LOG_PROFILER_GZ
#ifdef INTERNAL_ZLIB
#include <external/zlib/zlib.h>
#else
#include <zlib.h>
#endif
#endif
#include <glib.h>
#include <mono/metadata/profiler.h>
#include <mono/metadata/object.h>
Expand Down
22 changes: 22 additions & 0 deletions src/native/external/zlib-ng.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include(FetchContent)

FetchContent_Declare(
fetchzlibng
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/zlib-ng")

set(ZLIB_COMPAT ON)
set(ZLIB_ENABLE_TESTS OFF)
set(ZLIBNG_ENABLE_TESTS OFF)
set(Z_PREFIX ON)

add_compile_options(-Wno-error=unused-command-line-argument) # clang : error : argument unused during compilation: '-fno-semantic-interposition'

add_compile_options($<$<COMPILE_LANG_AND_ID:C,MSVC>:/wd4127>) # warning C4127: conditional expression is constant
add_compile_options($<$<COMPILE_LANG_AND_ID:C,MSVC>:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files
add_compile_options($<$<COMPILE_LANG_AND_ID:C,MSVC>:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files
# TODO: DO we still need to disable /wd4131 ?
# add_compile_options($<$<COMPILE_LANG_AND_ID:C,MSVC>:/wd9025>) # Caused by zlib-ng/CMakeLists.txt:186 Command line error D9025: overriding '/W4' with '/W3'

set(SKIP_INSTALL_ALL ON)
FetchContent_MakeAvailable(fetchzlibng)
set(SKIP_INSTALL_ALL OFF)
50 changes: 26 additions & 24 deletions src/native/external/zlib-ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ elseif(MSVC)
# (who'd use cmake from an IDE...) but checking for ICC before checking for MSVC should
# avoid mistakes.
# /Oi ?
set(WARNFLAGS /W3)
set(WARNFLAGS_MAINTAINER /W4)
# set(WARNFLAGS /W3)
#set(WARNFLAGS_MAINTAINER /W4)
set(WARNFLAGS_DISABLE)
if(BASEARCH_ARM_FOUND)
add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
Expand Down Expand Up @@ -462,29 +462,31 @@ endif()
#
# check for ptrdiff_t support
#
check_c_source_compiles(
"#include <stddef.h>
int main() {
ptrdiff_t *a;
(void)a;
return 0;
}"
HAVE_PTRDIFF_T
)
if(NOT HAVE_PTRDIFF_T)
set(NEED_PTRDIFF_T 1)

check_type_size("void *" SIZEOF_DATA_PTR)
message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes")

if(${SIZEOF_DATA_PTR} MATCHES "4")
set(PTRDIFF_TYPE "uint32_t")
elseif(${SIZEOF_DATA_PTR} MATCHES "8")
set(PTRDIFF_TYPE "uint64_t")
else()
message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit")
endif()
endif()
# TODO: SIZEOF_DATA_PTR is undefined when using MSVC because /INCREMENTAL:NO keeps getting overwritten to /INCREMENTAL by CMake.
# check_c_source_compiles(
# "#include <stddef.h>
# int main() {
# ptrdiff_t *a;
# (void)a;
# return 0;
# }"
# HAVE_PTRDIFF_T
# )
# if(NOT HAVE_PTRDIFF_T)
# set(NEED_PTRDIFF_T 1)

# check_type_size("void *" SIZEOF_DATA_PTR)
# message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes")

# if(${SIZEOF_DATA_PTR} MATCHES "4")
# set(PTRDIFF_TYPE "uint32_t")
# elseif(${SIZEOF_DATA_PTR} MATCHES "8")
# set(PTRDIFF_TYPE "uint64_t")
# else()
# message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit")
# endif()
# endif()

add_compile_options($<$<CONFIG:Debug>:-DZLIB_DEBUG>)

Expand Down
6 changes: 5 additions & 1 deletion src/native/libs/Common/pal_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <limits.h>

#include <minipal/utils.h>
Expand Down Expand Up @@ -69,6 +71,7 @@ inline static int ToFileDescriptorUnchecked(intptr_t fd)
return (int)fd;
}

#ifndef _WIN32
/**
* Converts an intptr_t to a file descriptor.
* intptr_t is the type used to marshal file descriptors so we can use SafeHandles effectively.
Expand All @@ -86,6 +89,7 @@ static inline bool CheckInterrupted(ssize_t result)
{
return result < 0 && errno == EINTR;
}
#endif

inline static uint32_t Int32ToUint32(int32_t value)
{
Expand Down
Loading

0 comments on commit c65dad0

Please sign in to comment.