From 663184e792bcb548ff13c13b8999eb85731f76ce Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 14 Feb 2024 14:55:01 -0500 Subject: [PATCH 01/84] wip: dotnet.sh build src/native/libhellomanaged/compile-native.proj works --- .../libhellomanaged/Directory.Build.props | 3 + .../libhellomanaged/compile-native.proj | 21 ++++++ src/native/libhellomanaged/src/Entrypoints.cs | 17 +++++ .../src/libhellomanaged.csproj | 42 +++++++++++ .../write-nativelib-cmake.targets | 69 +++++++++++++++++++ .../Directory.Build.props | 3 + .../src/Directory.Build.props | 3 + .../src/HelloManaged.cs | 13 ++++ .../src/Microsoft.DotNet.HelloManaged.csproj | 31 +++++++++ 9 files changed, 202 insertions(+) create mode 100644 src/native/libhellomanaged/Directory.Build.props create mode 100644 src/native/libhellomanaged/compile-native.proj create mode 100644 src/native/libhellomanaged/src/Entrypoints.cs create mode 100644 src/native/libhellomanaged/src/libhellomanaged.csproj create mode 100644 src/native/libhellomanaged/write-nativelib-cmake.targets create mode 100644 src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props create mode 100644 src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props create mode 100644 src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs create mode 100644 src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj diff --git a/src/native/libhellomanaged/Directory.Build.props b/src/native/libhellomanaged/Directory.Build.props new file mode 100644 index 0000000000000..3461462e54d14 --- /dev/null +++ b/src/native/libhellomanaged/Directory.Build.props @@ -0,0 +1,3 @@ + + + diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj new file mode 100644 index 0000000000000..672741451bfb6 --- /dev/null +++ b/src/native/libhellomanaged/compile-native.proj @@ -0,0 +1,21 @@ + + + + Release + + static + + + + + + + + + + + + + diff --git a/src/native/libhellomanaged/src/Entrypoints.cs b/src/native/libhellomanaged/src/Entrypoints.cs new file mode 100644 index 0000000000000..98e8e8b067fa3 --- /dev/null +++ b/src/native/libhellomanaged/src/Entrypoints.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.DotNet.HelloManaged; + +public static class Entrypoints +{ + [UnmanagedCallersOnly(EntryPoint="hellomanaged_Hello")] + public static void Hello() + { + HelloManaged o = new(); + Console.WriteLine ($"Hello {o.GetMagic()}"); + } +} diff --git a/src/native/libhellomanaged/src/libhellomanaged.csproj b/src/native/libhellomanaged/src/libhellomanaged.csproj new file mode 100644 index 0000000000000..d29d09fb51adc --- /dev/null +++ b/src/native/libhellomanaged/src/libhellomanaged.csproj @@ -0,0 +1,42 @@ + + + + $(NetCoreAppToolCurrent) + Example managed library that will be included in a NativeAOT compiled binary + true + enable + true + true + true + true + + false + + + + true + true + + + + + @rpath/$(MSBuildProjectName).dylib + + + + + + + + + + + + + + + + + + diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/libhellomanaged/write-nativelib-cmake.targets new file mode 100644 index 0000000000000..830e9392d1ac6 --- /dev/null +++ b/src/native/libhellomanaged/write-nativelib-cmake.targets @@ -0,0 +1,69 @@ + + + + + + + + + + $(TargetName.ToUpper()) + $(PublishDir)/$(MSBuildProjectName).cmake + $(TargetName) + $(NativeBinaryExt) + $(PublishDir)/ + + + + + + + + + + $(IlcFrameworkPath.TrimEnd('\\/')) + $(IlcSdkPath.TrimEnd('\\/')) + + + + $(NativeLibraryArtifactLibPath.Replace('\', '\\')) + $(NativeLibraryArtifactIlcFrameworkPath.Replace('\', '\\')) + $(NativeLibraryArtifactIlcSdkPath.Replace('\', '\\')) + + + + + + + + + + + + + + + $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(LibSuffix)')) + + + + $(NativeLibraryArtifactLibPath.Replace('\', '\\')) + $(NativeLibraryArtifactImpLibFullPath.Replace('\', '\\')) + + + + + + + + + + + diff --git a/src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props b/src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props new file mode 100644 index 0000000000000..aac96214a96d8 --- /dev/null +++ b/src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props @@ -0,0 +1,3 @@ + + + diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props b/src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props new file mode 100644 index 0000000000000..0a801022f17dd --- /dev/null +++ b/src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props @@ -0,0 +1,3 @@ + + + diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs b/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs new file mode 100644 index 0000000000000..f046936b1be77 --- /dev/null +++ b/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Microsoft.DotNet.HelloManaged; + +public class HelloManaged +{ + public HelloManaged() {} + + public ulong GetMagic() => 0x20240209L; +} diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj new file mode 100644 index 0000000000000..144edfaf7e3d3 --- /dev/null +++ b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj @@ -0,0 +1,31 @@ + + + + + $(NetCoreAppToolCurrent) + Example managed library that will be included in a NativeAOT compiled binary + true + enable + true + true + true + true + + false + + + + + + + + + + + + + + + + From d16749d42d8a9300099bb34bcfd1d3d7a87ad5f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 14 Feb 2024 20:59:55 -0500 Subject: [PATCH 02/84] hide unnecesary dependencies --- .../src/Microsoft.DotNet.HelloManaged.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj index 144edfaf7e3d3..a7643942a8eef 100644 --- a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj +++ b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj @@ -16,7 +16,7 @@ - + From ca01640646a6e15ebbccffcf74fab01d4c4a76c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 14 Feb 2024 21:00:10 -0500 Subject: [PATCH 03/84] add compile-native.proj to runtime-prereqs.proj --- src/coreclr/runtime-prereqs.proj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/runtime-prereqs.proj b/src/coreclr/runtime-prereqs.proj index b1d1cf8b041df..34c8077ce3c13 100644 --- a/src/coreclr/runtime-prereqs.proj +++ b/src/coreclr/runtime-prereqs.proj @@ -13,6 +13,10 @@ + + + + - + Date: Thu, 15 Feb 2024 16:16:45 -0500 Subject: [PATCH 05/84] add an include dir for libhellomanaged --- .../libhellomanaged/inc/libhellomanaged.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/native/libhellomanaged/inc/libhellomanaged.h diff --git a/src/native/libhellomanaged/inc/libhellomanaged.h b/src/native/libhellomanaged/inc/libhellomanaged.h new file mode 100644 index 0000000000000..bb9886051cfc8 --- /dev/null +++ b/src/native/libhellomanaged/inc/libhellomanaged.h @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef _LIBHELLOMANAGED_H +#define _LIBHELLOMANAGED_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +void +hellomanaged_Hello(void); + +#ifdef __cplusplus +} +#endif + +#endif From 6aad3556a3cc37e07a935ea00137c3d645fa8946 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 16:17:06 -0500 Subject: [PATCH 06/84] wire in static lib support; use to call libhellomanaged from daccess --- eng/native/import-nativeaot-library.cmake | 81 +++++++++++++++++++ src/coreclr/CMakeLists.txt | 2 + src/coreclr/debug/daccess/CMakeLists.txt | 7 ++ .../write-nativelib-cmake.targets | 6 +- 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 eng/native/import-nativeaot-library.cmake diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake new file mode 100644 index 0000000000000..e0800d08dd4fb --- /dev/null +++ b/eng/native/import-nativeaot-library.cmake @@ -0,0 +1,81 @@ + +# Infrastructure to import a native aot compiled library into a native build + +# If we're statically linking one or more NativeAOTed libraries, add a target that brings in the +# static library NativeAOT runtime components. This function can be called more than once. Each +# imported library should add its own dependency on the "nativeAotFramework" target +# +# This is only necessary if NativeAOT libraries are compiled to static native libraries (in which +# case they will share a single NativeAOT runtime). If all the NativeAOTed libraries are shared, +# they will each run in their own isolated NativeAOT runtime. +function(add_nativeAotFramework_targets_once) + get_property(targets_added GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED) + if (NOT "${targets_added}") + add_library(nativeAotFramework INTERFACE) + # FIXME: finish this + + set_property(GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED 1) + endif() +endfunction() + +# see add_imported_nativeaot_library_clr, below +function(add_imported_nativeaot_library targetName symbolPrefix) + message(STATUS "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") + if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED") + add_library(${targetName} IMPORTED SHARED) + # FIXME: finish this + elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") + add_nativeAotFramework_targets_once() + + set(libName "${${symbolPrefix}_NAME}") # typically same as targetName + set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish + set(libFilename "${libName}${${symbolPrefix}_EXT}") # targetName.a or targetName.lib + + # FIXME: annoyingly cmake doesn't treat changes at IMPORTED_LOCATION or target_link_libraries as + # a trigger to rebuild the downstream targets. we might need to use an add_custom_command that + # pretends the library is a BYPRODUCTS of the custom command. although that will cause the + # library to be deleted if we ever run "make clean". Maybe that's what we want. + + # what we're trying to achieve is that all the symbols from the static library are hidden in the + # final shared library or executable target. If we had object files, the normal GCC/Clang + # "-fvisibility=hidden" mechanism would hide all the non-exported symbols. Or if we had an + # exported symbols list we could use an LD version script or the apple -exported_symbols_list + # option. But we dont' have that, so instead we use the GNU LD `--exclude-libs=libtargetName.a` option, or the apple `-hidden-ltargetName` option + + if(${CLR_CMAKE_HOST_APPLE}) + message(STATUS creeating ${targetName}-static for apple) + # hack: -hidden-l wants the library name without a "lib" prefix + STRING(REGEX REPLACE "^lib" "" libBaseName ${libName}) + add_library(${targetName}-static INTERFACE IMPORTED) + target_link_directories(${targetName}-static INTERFACE "${libPath}") + target_link_libraries(${targetName}-static INTERFACE "-Wl,-hidden-l${libBaseName}") + elseif(${CLR_CMAKE_HOST_UNIX}) + add_library(${targetName}-static STATIC IMPORTED) + set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}/${libFilename}") + target_link_options(${targetName}-static INTERFACE "LINKER:--exclude-libs=${libFilename}") + elseif(${CLR_CMAKE_HOST_WIN32}) + add_library(${targetName}-static STATIC IMPORTED) + set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}\\${libFilename}") + endif() + + # TODO bake this into the cmake fragment? + target_include_directories(${targetName}-static INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") + target_link_libraries(${targetName}-static INTERFACE nativeAotFramework) + + add_library(${targetName} INTERFACE) + target_link_libraries(${targetName} INTERFACE ${targetName}-static) + else() + message(FATAL_ERROR "${symbolPrefix}_MODE must be one of SHARED or STATIC") + endif() +endfunction() + +# adds a target targetName that can be used to reference a NativeAOTed library. symbolPrefix should +# be the ALLCAPS prefix of the variables that define the mode and paths for the library. They are +# typically set in the artifacts/obj/targetName/targetName.cmake fragment which should be included +# before calling this function. +function(add_imported_nativeaot_library_clr targetName symbolPrefix) + add_imported_nativeaot_library(${ARGV}) + if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) + strip_symbols(${ARGV0} symbolFile) + endif() +endfunction() diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 1c314d9bf624e..1bbde5fac19f2 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -9,6 +9,8 @@ include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) include_directories("${CLR_SRC_NATIVE_DIR}") include_directories("${CLR_SRC_NATIVE_DIR}/inc") +include(${CLR_ENG_NATIVE_DIR}/import-nativeaot-library.cmake) + if(MSVC) set(CMAKE_CXX_STANDARD_LIBRARIES "") # do not link against standard win32 libs i.e. kernel32, uuid, user32, etc. endif (MSVC) diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index 5332e957c9eca..f7cbb8bd1eb56 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -1,5 +1,9 @@ add_definitions(-DFEATURE_NO_HOST) +include(${CLR_ARTIFACTS_OBJ_DIR}/libhellomanaged/libhellomanaged.cmake) + +message(STATUS "Using libhellomanaged in ${LIBHELLOMANAGED_MODE} mode") + include_directories(BEFORE ${VM_DIR}) include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR}) include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}) @@ -37,9 +41,12 @@ include_directories(${ARCH_SOURCES_DIR}) convert_to_absolute_path(DACCESS_SOURCES ${DACCESS_SOURCES}) +add_imported_nativeaot_library_clr(libhellomanagedTarget LIBHELLOMANAGED) + add_library_clr(daccess ${DACCESS_SOURCES}) set_target_properties(daccess PROPERTIES DAC_COMPONENT TRUE) target_precompile_headers(daccess PRIVATE [["stdafx.h"]]) +target_link_libraries(daccess PRIVATE libhellomanagedTarget) add_dependencies(daccess eventing_headers) diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/libhellomanaged/write-nativelib-cmake.targets index 830e9392d1ac6..33ec35d5c3bdd 100644 --- a/src/native/libhellomanaged/write-nativelib-cmake.targets +++ b/src/native/libhellomanaged/write-nativelib-cmake.targets @@ -12,7 +12,7 @@ $(TargetName.ToUpper()) - $(PublishDir)/$(MSBuildProjectName).cmake + $(ArtifactsObjDir)\$(TargetName)\$(TargetName).cmake $(TargetName) $(NativeBinaryExt) $(PublishDir)/ @@ -38,7 +38,7 @@ $(NativeLibraryArtifactIlcSdkPath.Replace('\', '\\')) - + @@ -58,7 +58,7 @@ $(NativeLibraryArtifactImpLibFullPath.Replace('\', '\\')) - + From eb56ef62bce5835230397cbb9e5ddc3d60c65ff6 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 16:19:16 -0500 Subject: [PATCH 07/84] call hellomanaged_Hello from DAC DllMain --- src/coreclr/debug/daccess/daccess.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index e79dab808def3..fd3f1f2017a84 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -33,6 +33,8 @@ extern "C" bool TryGetSymbol(ICorDebugDataTarget* dataTarget, uint64_t baseAddre #include "dwbucketmanager.hpp" #include "gcinterface.dac.h" +#include "libhellomanaged.h" + // To include definition of IsThrowableThreadAbortException // #include @@ -63,6 +65,8 @@ BOOL WINAPI DllMain(HANDLE instance, DWORD reason, LPVOID reserved) #endif } + hellomanaged_Hello(); + #ifdef HOST_UNIX int err = PAL_InitializeDLL(); if(err != 0) From 225d05bd21e48a805c28fe29cdc1ac69568b05bc Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 16:32:53 -0500 Subject: [PATCH 08/84] static linking of nativeAotFramework --- eng/native/import-nativeaot-library.cmake | 71 +++++++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index e0800d08dd4fb..fc2a36d1450fa 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -12,8 +12,71 @@ function(add_nativeAotFramework_targets_once) get_property(targets_added GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED) if (NOT "${targets_added}") add_library(nativeAotFramework INTERFACE) - # FIXME: finish this + # depends on NATIVEAOT_FRAMEWORK_PATH and NATIVEAOT_SDK_PATH to be set + # by the generated .cmake fragment during the managed build + + if ("${CLR_CMAKE_HOST_WIN32}") + set(NAOT_SDK_BASE_BOOTSTRAP bootstrapperdll${CMAKE_C_OUTPUT_EXTENSION}) + else() + set(NAOT_SDK_BASE_BOOTSTRAP libbootstrapperdll${CMAKE_C_OUTPUT_EXTENSION}) + endif() + + set(NAOT_SDK_BASE_LIBS + Runtime.WorkstationGC + eventpipe-disabled) + + if(NOT "${CLR_CMAKE_HOST_WIN32}") + list(APPEND NAOT_SDK_BASE_LIBS stdc++compat) + else() + list(APPEND NAOT_SDK_BASE_LIBS + Runtime.VxsortEnabled + System.Globalization.Native.Aot + System.IO.Compression.Native.Aot + ) + endif() + + addprefix(NAOT_SDK_BOOTSTRAP "${NATIVEAOT_SDK_PATH}" "${NAOT_SDK_BASE_BOOTSTRAP}") + addprefix(NAOT_SDK_LIBS "${NATIVEAOT_SDK_PATH}" "${NAOT_SDK_BASE_LIBS}") + + if("${CLR_CMAKE_HOST_WIN32}") + set(NAOT_FRAMEWORK_BASE_LIBS) + else() + set(NAOT_FRAMEWORK_BASE_LIBS + System.Native + System.Globalization.Native + System.IO.Compression.Native + System.Net.Security.Native + System.Security.Cryptography.Native.OpenSsl) + endif() + + addprefix(NAOT_FRAMEWORK_LIBS "${NATIVEAOT_FRAMEWORK_PATH}" "${NAOT_FRAMEWORK_BASE_LIBS}") + + if("${CLR_CMAKE_HOST_WIN32}") + list(TRANSFORM NAOT_FRAMEWORK_LIBS APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}") + list(TRANSFORM NAOT_SDK_LIBS APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + + if("${CLR_CMAKE_HOST_APPLE}") + list(TRANSFORM NAOT_SDK_BASE_LIBS PREPEND "-Wl,-hidden-l" OUTPUT_VARIABLE NAOT_SDK_HIDDEN_LIBS) + list(TRANSFORM NAOT_FRAMEWORK_BASE_LIBS PREPEND "-Wl,-hidden-l" OUTPUT_VARIABLE NAOT_FRAMEWORK_HIDDEN_LIBS) + target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") + target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_HIDDEN_LIBS}" "${NAOT_FRAMEWORK_HIDDEN_LIBS}" -lm) + elseif("${CLR_CMAKE_HOST_UNIX}") + target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") + list(TRANSFORM NAOT_SDK_BASE_LIBS PREPEND "lib" OUTPUT_VARIABLE NAOT_SDK_HIDDEN_LIBS) + list(TRANSFORM NAOT_FRAMEWORK_BASE_LIBS PREPEND "lib" OUTPUT_VARIABLE NAOT_FRAMEWORK_HIDDEN_LIBS) + string(REPLACE ";" ":" NAOT_SDK_EXCLUDE_ARG "${NAOT_SDK_HIDDEN_LIBS}") + string(REPLACE ";" ":" NAOT_FRAMEWORK_EXCLUDE_ARG "${NAOT_FRAMEWORK_HIDDEN_LIBS}") + target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_BASE_LIBS}" "${NAOT_FRAMEWORK_BASE_LIBS}" -lm) + target_link_options(nativeAotFramework INTERFACE "LINKER:--exclude-libs=${NAOT_SDK_EXCLUDE_ARG}:${NAOT_FRAMEWORK_EXCLUDE_ARG}") + target_link_options(nativeAotFramework INTERFACE "LINKER:--discard-all") + target_link_options(nativeAotFramework INTERFACE "LINKER:--gc-sections") + elseif("${CLR_CMAKE_HOST_WIN32}") + target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") + target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_LIBS}" "${NAOT_FRAMEWORK_LIBS}" BCrypt) + endif() + set_property(GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED 1) endif() endfunction() @@ -42,18 +105,18 @@ function(add_imported_nativeaot_library targetName symbolPrefix) # exported symbols list we could use an LD version script or the apple -exported_symbols_list # option. But we dont' have that, so instead we use the GNU LD `--exclude-libs=libtargetName.a` option, or the apple `-hidden-ltargetName` option - if(${CLR_CMAKE_HOST_APPLE}) + if("${CLR_CMAKE_HOST_APPLE}") message(STATUS creeating ${targetName}-static for apple) # hack: -hidden-l wants the library name without a "lib" prefix STRING(REGEX REPLACE "^lib" "" libBaseName ${libName}) add_library(${targetName}-static INTERFACE IMPORTED) target_link_directories(${targetName}-static INTERFACE "${libPath}") target_link_libraries(${targetName}-static INTERFACE "-Wl,-hidden-l${libBaseName}") - elseif(${CLR_CMAKE_HOST_UNIX}) + elseif("${CLR_CMAKE_HOST_UNIX}") add_library(${targetName}-static STATIC IMPORTED) set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}/${libFilename}") target_link_options(${targetName}-static INTERFACE "LINKER:--exclude-libs=${libFilename}") - elseif(${CLR_CMAKE_HOST_WIN32}) + elseif("${CLR_CMAKE_HOST_WIN32}") add_library(${targetName}-static STATIC IMPORTED) set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}\\${libFilename}") endif() From 19d17acf39b607b38b345560f277997bc21bf65a Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 19:40:24 -0500 Subject: [PATCH 09/84] support for importing NativeAOT compiled shared libs --- eng/native/import-nativeaot-library.cmake | 35 +++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index fc2a36d1450fa..d54957032b088 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -85,8 +85,26 @@ endfunction() function(add_imported_nativeaot_library targetName symbolPrefix) message(STATUS "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED") - add_library(${targetName} IMPORTED SHARED) - # FIXME: finish this + add_library(${targetName} INTERFACE) + + set(libName "${${symbolPrefix}_NAME}") # typically same as targetName + set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish + set(libFilename "${libName}${${symbolPrefix}_EXT}") # .dll, .so or .dylib + set(libFullPath "${libPath}/${libFilename}") + # windows import library + set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically \...\artifacts\bin\\\\native\.lib + + add_library(${targetName}-shared SHARED IMPORTED) + set_property(TARGET ${targetName}-shared PROPERTY IMPORTED_LOCATION "${libFullPath}") + + if("${CLR_CMAKE_HOST_WIN32}") + set_property(TARGET ${targetName}-shared PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") + endif() + + # TODO bake this into the cmake fragment? + target_include_directories(${targetName}-shared INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") + + target_link_libraries(${targetName} INTERFACE ${targetName}-shared) elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() @@ -138,7 +156,14 @@ endfunction() # before calling this function. function(add_imported_nativeaot_library_clr targetName symbolPrefix) add_imported_nativeaot_library(${ARGV}) - if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) - strip_symbols(${ARGV0} symbolFile) - endif() + # FIXME: target xyz-shared is imported and does not build here + #if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) + # strip_symbols("${ARGV0}-shared" symbolFile) + #endif() endfunction() + +# TODO: copy the shared lib to the correct output folder +#if("${LIBNAOTHELLO_MODE}" STREQUAL "shared") +# add_custom_command(TARGET helloLib POST_BUILD +# COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$" "$") +#endif() From c03b37e56c761668f2979df4cf11536797baa1c1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 19:40:45 -0500 Subject: [PATCH 10/84] build native libs as shared by default --- src/native/libhellomanaged/compile-native.proj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 4aa2acc581457..8801a060aedf7 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -2,8 +2,8 @@ Release - - static + + shared @@ -19,7 +19,7 @@ From 730dd07c138e1289aad300ed8ccc86d5b31ebbe1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 20:21:36 -0500 Subject: [PATCH 11/84] WIP: first try at installing the native lib --- eng/native/import-nativeaot-library.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index d54957032b088..0863091c829e4 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -105,6 +105,16 @@ function(add_imported_nativeaot_library targetName symbolPrefix) target_include_directories(${targetName}-shared INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") target_link_libraries(${targetName} INTERFACE ${targetName}-shared) + + # FIXME: this installs into artifacts/bin/coreclr//lib/ + # we instead need to add a IMPORTED_RUNTIME_ARTIFACTS mode for install_clr() so that it installs + # with the component + if("${CLR_CMAKE_HOST_WIN32}") + install(IMPORTED_RUNTIME_ARTIFACTS ${targetName}-shared RUNTIME) # dlls are "runtime" on Windows + else() + install(IMPORTED_RUNTIME_ARTIFACTS ${targetName}-shared LIBRARY) # .so/.dylib are "library" + endif() + elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() From 472ee21539a989ab941b8e6c1cc745cc2f41ce6e Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 15 Feb 2024 20:49:49 -0500 Subject: [PATCH 12/84] relocatable linking for static libs GNU ld and clang's lld support a '-r' options for linking a bunch of object files together into another one. Maybe we can use this together with the exclude-libs/hidden-lx options to combine just the native lib and the runtime support libs before doing the final link. unclear if there's anything similar on Windows. From 51f56b11941619d1e080f2a5347a7d9307035f0c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 12:40:59 -0500 Subject: [PATCH 13/84] cleanup shared lib version; add install_clr support --- eng/native/functions.cmake | 19 +++++++++++++++---- eng/native/import-nativeaot-library.cmake | 23 ++++++----------------- src/coreclr/debug/daccess/CMakeLists.txt | 3 +++ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 543722a9c0a59..c578d8deaf405 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -533,17 +533,28 @@ function(install_clr) endif() add_dependencies(${INSTALL_CLR_COMPONENT} ${targetName}) endif() + get_target_property(targetImportedNativeAotLib ${targetName} CLR_IMPORTED_NATIVEAOT_LIBRARY) get_target_property(targetType ${targetName} TYPE) - if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY") + if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY" AND NOT "${targetImportedNativeAotLib}") get_symbol_file_name(${targetName} symbolFile) endif() + # FIXME: make symbol files for native aot libs too foreach(destination ${destinations}) # We don't need to install the export libraries for our DLLs # since they won't be directly linked against. - install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - if (NOT "${symbolFile}" STREQUAL "") - install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + if (NOT "${targetImportedNativeAotLib}") + install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + if (NOT "${symbolFile}" STREQUAL "") + install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + endif() + elseif("${targetType}" STREQUAL "SHARED_LIBRARY") + #imported shared lib - install the imported artifacts + #imported static lib - nothing to install + install(IMPORTED_RUNTIME_ARTIFACTS ${targetName} DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + if (NOT "${symbolFile}" STREQUAL "") + install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + endif() endif() if(CLR_CMAKE_PGO_INSTRUMENT) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 0863091c829e4..ecdb2076ffab8 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -85,8 +85,6 @@ endfunction() function(add_imported_nativeaot_library targetName symbolPrefix) message(STATUS "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED") - add_library(${targetName} INTERFACE) - set(libName "${${symbolPrefix}_NAME}") # typically same as targetName set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish set(libFilename "${libName}${${symbolPrefix}_EXT}") # .dll, .so or .dylib @@ -94,26 +92,16 @@ function(add_imported_nativeaot_library targetName symbolPrefix) # windows import library set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically \...\artifacts\bin\\\\native\.lib - add_library(${targetName}-shared SHARED IMPORTED) - set_property(TARGET ${targetName}-shared PROPERTY IMPORTED_LOCATION "${libFullPath}") + add_library(${targetName} SHARED IMPORTED GLOBAL) + set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${libFullPath}") + set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) if("${CLR_CMAKE_HOST_WIN32}") - set_property(TARGET ${targetName}-shared PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") + set_property(TARGET ${targetName} PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") endif() # TODO bake this into the cmake fragment? - target_include_directories(${targetName}-shared INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") - - target_link_libraries(${targetName} INTERFACE ${targetName}-shared) - - # FIXME: this installs into artifacts/bin/coreclr//lib/ - # we instead need to add a IMPORTED_RUNTIME_ARTIFACTS mode for install_clr() so that it installs - # with the component - if("${CLR_CMAKE_HOST_WIN32}") - install(IMPORTED_RUNTIME_ARTIFACTS ${targetName}-shared RUNTIME) # dlls are "runtime" on Windows - else() - install(IMPORTED_RUNTIME_ARTIFACTS ${targetName}-shared LIBRARY) # .so/.dylib are "library" - endif() + target_include_directories(${targetName} INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() @@ -155,6 +143,7 @@ function(add_imported_nativeaot_library targetName symbolPrefix) add_library(${targetName} INTERFACE) target_link_libraries(${targetName} INTERFACE ${targetName}-static) + set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) else() message(FATAL_ERROR "${symbolPrefix}_MODE must be one of SHARED or STATIC") endif() diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index f7cbb8bd1eb56..6dde90fe8057b 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -48,6 +48,9 @@ set_target_properties(daccess PROPERTIES DAC_COMPONENT TRUE) target_precompile_headers(daccess PRIVATE [["stdafx.h"]]) target_link_libraries(daccess PRIVATE libhellomanagedTarget) +# FIXME: can we put this with mscordaccore instead? +install_clr(TARGETS libhellomanagedTarget DESTINATIONS . sharedFramework COMPONENT debug) + add_dependencies(daccess eventing_headers) if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) From b6c637ca2c593d1c032d45dc97697d2c3baf78d8 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 13:08:53 -0500 Subject: [PATCH 14/84] rm TODO --- eng/native/import-nativeaot-library.cmake | 6 ------ 1 file changed, 6 deletions(-) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index ecdb2076ffab8..ec233f151c77a 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -160,9 +160,3 @@ function(add_imported_nativeaot_library_clr targetName symbolPrefix) # strip_symbols("${ARGV0}-shared" symbolFile) #endif() endfunction() - -# TODO: copy the shared lib to the correct output folder -#if("${LIBNAOTHELLO_MODE}" STREQUAL "shared") -# add_custom_command(TARGET helloLib POST_BUILD -# COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$" "$") -#endif() From 80c706da82ec23fd120c29cca4f9dd5f2a67627f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 13:58:35 -0500 Subject: [PATCH 15/84] don't build hellomanaged on platforms without NativeAOT also don't build for Mono for now --- src/native/libhellomanaged/compile-native.proj | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 8801a060aedf7..5d010ba75bbb7 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -10,16 +10,23 @@ - + + + false + true + false + + + - + From 1f6a9f72649f17924c0e21ae94420cb93c487b2b Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 14:06:02 -0500 Subject: [PATCH 16/84] fixup windows build --- src/native/libhellomanaged/write-nativelib-cmake.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/libhellomanaged/write-nativelib-cmake.targets index 33ec35d5c3bdd..47b639d16214a 100644 --- a/src/native/libhellomanaged/write-nativelib-cmake.targets +++ b/src/native/libhellomanaged/write-nativelib-cmake.targets @@ -48,7 +48,7 @@ - + $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(LibSuffix)')) @@ -62,7 +62,7 @@ - + From 26c33ab34300254e181878a7db4ae687bb72b5af Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 14:14:04 -0500 Subject: [PATCH 17/84] fixup win implib --- src/native/libhellomanaged/write-nativelib-cmake.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/libhellomanaged/write-nativelib-cmake.targets index 47b639d16214a..9221195818a9a 100644 --- a/src/native/libhellomanaged/write-nativelib-cmake.targets +++ b/src/native/libhellomanaged/write-nativelib-cmake.targets @@ -50,7 +50,7 @@ - $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(LibSuffix)')) + $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(StaticLibSuffix)')) From f6dcfe8863b8945b52005a0e81ffe6602e0c4917 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 14:39:16 -0500 Subject: [PATCH 18/84] disable more configurations --- src/native/libhellomanaged/compile-native.proj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 5d010ba75bbb7..b8bc2a75fd259 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -13,7 +13,10 @@ false - true + + false + false + true false From b94c67a4899d9af2039304d938ae9510f44889fb Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 15:18:55 -0500 Subject: [PATCH 19/84] try to workaround dotnet/msbuild#2811 --- src/native/libhellomanaged/compile-native.proj | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index b8bc2a75fd259..48d73aa16502b 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -26,10 +26,17 @@ + + + + + + Properties="Configuration=$(NativeLibsPublishConfiguration);RuntimeConfiguration=$(RuntimeConfiguration);LibrariesConfiguration=$(LibrariesConfiguration);RuntimeIdentifier=$(OutputRID);NativeLib=$(NativeLibKind);_RandomOtherPropertyToPleaseMSBuild=BuildingAndPublishing" + Targets="Build;Publish" /> From 4c7793bef4185ee40ca84824af73aa96d805da83 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 16:23:17 -0500 Subject: [PATCH 20/84] allow daccess to keep building if hellomanaged is not present --- src/coreclr/debug/daccess/CMakeLists.txt | 16 ++++++++-------- src/coreclr/debug/daccess/daccess.cpp | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index 6dde90fe8057b..a09f02c4eed80 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -1,8 +1,6 @@ add_definitions(-DFEATURE_NO_HOST) -include(${CLR_ARTIFACTS_OBJ_DIR}/libhellomanaged/libhellomanaged.cmake) - -message(STATUS "Using libhellomanaged in ${LIBHELLOMANAGED_MODE} mode") +include(${CLR_ARTIFACTS_OBJ_DIR}/libhellomanaged/libhellomanaged.cmake OPTIONAL RESULT_VARIABLE INCLUDED_HELLOMANAGED) include_directories(BEFORE ${VM_DIR}) include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR}) @@ -41,15 +39,17 @@ include_directories(${ARCH_SOURCES_DIR}) convert_to_absolute_path(DACCESS_SOURCES ${DACCESS_SOURCES}) -add_imported_nativeaot_library_clr(libhellomanagedTarget LIBHELLOMANAGED) - add_library_clr(daccess ${DACCESS_SOURCES}) set_target_properties(daccess PROPERTIES DAC_COMPONENT TRUE) target_precompile_headers(daccess PRIVATE [["stdafx.h"]]) -target_link_libraries(daccess PRIVATE libhellomanagedTarget) -# FIXME: can we put this with mscordaccore instead? -install_clr(TARGETS libhellomanagedTarget DESTINATIONS . sharedFramework COMPONENT debug) +if(NOT "${INCLUDED_HELLOMANAGED}" STREQUAL "NOTFOUND") + add_imported_nativeaot_library_clr(libhellomanagedTarget LIBHELLOMANAGED) + target_link_libraries(daccess PRIVATE libhellomanagedTarget) + target_compile_definitions(daccess PRIVATE HAVE_LIBHELLOMANAGED) + # FIXME: can we put this with mscordaccore instead? + install_clr(TARGETS libhellomanagedTarget DESTINATIONS . sharedFramework COMPONENT debug) +endif() add_dependencies(daccess eventing_headers) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index fd3f1f2017a84..89c7f68729f23 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -33,7 +33,9 @@ extern "C" bool TryGetSymbol(ICorDebugDataTarget* dataTarget, uint64_t baseAddre #include "dwbucketmanager.hpp" #include "gcinterface.dac.h" +#ifdef HAVE_HELLOMANAGED #include "libhellomanaged.h" +#endif // To include definition of IsThrowableThreadAbortException // #include @@ -65,7 +67,9 @@ BOOL WINAPI DllMain(HANDLE instance, DWORD reason, LPVOID reserved) #endif } +#ifdef HAVE_HELLOMANAGED hellomanaged_Hello(); +#endif #ifdef HOST_UNIX int err = PAL_InitializeDLL(); From ce900f1e942acc837a6993e7cfb621c8d55e439d Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 16:40:42 -0500 Subject: [PATCH 21/84] always use lld on linux? --- src/native/libhellomanaged/src/libhellomanaged.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/native/libhellomanaged/src/libhellomanaged.csproj b/src/native/libhellomanaged/src/libhellomanaged.csproj index d29d09fb51adc..273c5c9f3fb0f 100644 --- a/src/native/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/libhellomanaged/src/libhellomanaged.csproj @@ -24,6 +24,11 @@ @rpath/$(MSBuildProjectName).dylib + + + lld + + From 37edeafc5c1960cb42f909fbda071baa6d18cdac Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 17:19:50 -0500 Subject: [PATCH 22/84] put AdditionalProperties on the ProjectReference same as msbuild publish make sure the same runtime identifier is passed down --- src/native/libhellomanaged/compile-native.proj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 48d73aa16502b..753c204170aa7 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -21,7 +21,9 @@ - + From a24dc466e537a105cceb58495fd0ab8aa21cad25 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 19:23:55 -0500 Subject: [PATCH 23/84] no x86 or riscv --- src/native/libhellomanaged/compile-native.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 753c204170aa7..e01aa12a0f1c2 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -15,7 +15,7 @@ false false - false + false true false From 748a84defcee8707b8a59a0eb1cee09dd55be363 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Feb 2024 19:24:12 -0500 Subject: [PATCH 24/84] linux-arm64 hack --- src/native/libhellomanaged/src/libhellomanaged.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/src/libhellomanaged.csproj b/src/native/libhellomanaged/src/libhellomanaged.csproj index 273c5c9f3fb0f..77f4ef32ba0a0 100644 --- a/src/native/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/libhellomanaged/src/libhellomanaged.csproj @@ -26,7 +26,7 @@ - lld + lld From d77776e8a4da61aa71bf39141d6274c17cb189e2 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 10:43:20 -0500 Subject: [PATCH 25/84] HACK: installer --- .../pkg/sfx/Microsoft.NETCore.App/Directory.Build.props | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 6e48929f896e4..598d9c0bcbc51 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -120,6 +120,11 @@ + + + + + From e7eca1fdeaa941c97d9325d7e69301b316ba0019 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 10:44:24 -0500 Subject: [PATCH 26/84] disable armel --- src/native/libhellomanaged/compile-native.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index e01aa12a0f1c2..fa9f899c8242d 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -15,7 +15,7 @@ false false - false + false true false From 4149bea0262d2850df94d45ac4a429dccf922c56 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 11:13:06 -0500 Subject: [PATCH 27/84] remove bfd hack - it didn't work --- src/native/libhellomanaged/src/libhellomanaged.csproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/native/libhellomanaged/src/libhellomanaged.csproj b/src/native/libhellomanaged/src/libhellomanaged.csproj index 77f4ef32ba0a0..d29d09fb51adc 100644 --- a/src/native/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/libhellomanaged/src/libhellomanaged.csproj @@ -24,11 +24,6 @@ @rpath/$(MSBuildProjectName).dylib - - - lld - - From 11c9d900d8939d5140da8476976b11aa56e62ea8 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 11:13:33 -0500 Subject: [PATCH 28/84] pass SysRoot and --gcc-toolchain to native build --- src/native/libhellomanaged/compile-native.proj | 13 ++++++++++--- .../libhellomanaged/src/libhellomanaged.csproj | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index fa9f899c8242d..309cd4162351d 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -20,10 +20,17 @@ false + + $(ROOTFS_DIR) + --gcc-toolchain=$(ROOTFS_DIR)/usr + $(ExtraProps);SysRoot=$(SysRoot) + $(ExtraProps);CustomLinkerArgToolchainArg=$(CustomLinkerArgToolchainArg) + + + AdditionalProperties="%(AdditionalProperties);RuntimeConfiguration=$(RuntimeConfiguration);LibrariesConfiguration=$(LibrariesConfiguration);RuntimeIdentifier=$(OutputRID);NativeLib=$(NativeLibKind)$(ExtraProps)"/> @@ -32,13 +39,13 @@ diff --git a/src/native/libhellomanaged/src/libhellomanaged.csproj b/src/native/libhellomanaged/src/libhellomanaged.csproj index d29d09fb51adc..009881ef32288 100644 --- a/src/native/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/libhellomanaged/src/libhellomanaged.csproj @@ -24,6 +24,10 @@ @rpath/$(MSBuildProjectName).dylib + + + + From f664970a0534bac94666301eacc99d0c0e5bf633 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 11:46:14 -0500 Subject: [PATCH 29/84] fix typo (RID is linux-riscv64 not linux-riscv) --- src/native/libhellomanaged/compile-native.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 309cd4162351d..735e967a02640 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -15,7 +15,7 @@ false false - false + false true false From 70bc9c7aeaf92cda9a2f4be8d1c4c22ea320c9d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 11:50:49 -0500 Subject: [PATCH 30/84] set linker flavor if doing cross builds --- src/native/libhellomanaged/compile-native.proj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/libhellomanaged/compile-native.proj index 735e967a02640..f530673af6b93 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/libhellomanaged/compile-native.proj @@ -22,8 +22,10 @@ $(ROOTFS_DIR) + lld --gcc-toolchain=$(ROOTFS_DIR)/usr $(ExtraProps);SysRoot=$(SysRoot) + $(ExtraProps);LinkerFlavor=$(LinkerFlavor) $(ExtraProps);CustomLinkerArgToolchainArg=$(CustomLinkerArgToolchainArg) From 0f776cc6ec83e64278bde1e5d1a33137e607058f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 13:22:12 -0500 Subject: [PATCH 31/84] fix for cmake 3.20 --- eng/native/functions.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index c578d8deaf405..f6368ce5b1d3f 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -551,7 +551,12 @@ function(install_clr) elseif("${targetType}" STREQUAL "SHARED_LIBRARY") #imported shared lib - install the imported artifacts #imported static lib - nothing to install - install(IMPORTED_RUNTIME_ARTIFACTS ${targetName} DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + + if ("${CMAKE_VERSION}" VERSION_LESS "3.21") + install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + else() + install(IMPORTED_RUNTIME_ARTIFACTS ${targetName} DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) + endif() if (NOT "${symbolFile}" STREQUAL "") install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) endif() From 66f4b53d4c168030056b28e66ee61407ff3bd337 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 14:50:52 -0500 Subject: [PATCH 32/84] use GenerateFileFromTemplate for shared mode --- .../Templates/native-lib.shared.cmake.in | 5 +++ .../write-nativelib-cmake.targets | 34 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 src/native/libhellomanaged/Templates/native-lib.shared.cmake.in diff --git a/src/native/libhellomanaged/Templates/native-lib.shared.cmake.in b/src/native/libhellomanaged/Templates/native-lib.shared.cmake.in new file mode 100644 index 0000000000000..313afb8cb3185 --- /dev/null +++ b/src/native/libhellomanaged/Templates/native-lib.shared.cmake.in @@ -0,0 +1,5 @@ +set(${libCmakeName}_MODE "SHARED") +set(${libCmakeName}_NAME "${libArtifactName}") +set(${libCmakeName}_EXT "${libArtifactExt}") +set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") +set(${libCmakeName}_IMPLIBPATH "${libArtifactImpLibFullPath}") diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/libhellomanaged/write-nativelib-cmake.targets index 9221195818a9a..6ff13d433989c 100644 --- a/src/native/libhellomanaged/write-nativelib-cmake.targets +++ b/src/native/libhellomanaged/write-nativelib-cmake.targets @@ -1,12 +1,26 @@ + + + + + + + Overwrite="true" + Condition="'$(NativeLib)' == 'static'"/> @@ -19,13 +33,6 @@ - - - - $(IlcFrameworkPath.TrimEnd('\\/')) @@ -58,11 +65,12 @@ $(NativeLibraryArtifactImpLibFullPath.Replace('\', '\\')) - - - - - + + + + + + From c32f8ac8eb87c1532b1862e634ed0261501ce160 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 15:25:06 -0500 Subject: [PATCH 33/84] use GenerateFileFromTemplate for static libs --- .../Templates/native-lib.static.cmake.in | 6 +++ .../write-nativelib-cmake.targets | 46 +++++++++---------- 2 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 src/native/libhellomanaged/Templates/native-lib.static.cmake.in diff --git a/src/native/libhellomanaged/Templates/native-lib.static.cmake.in b/src/native/libhellomanaged/Templates/native-lib.static.cmake.in new file mode 100644 index 0000000000000..2903badddec11 --- /dev/null +++ b/src/native/libhellomanaged/Templates/native-lib.static.cmake.in @@ -0,0 +1,6 @@ +set(${libCmakeName}_MODE "STATIC") +set(${libCmakeName}_NAME "${libArtifactName}") +set(${libCmakeName}_EXT "${libArtifactExt}") +set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") +set(NATIVEAOT_FRAMEWORK_PATH "${libArtifactNativeAotFrameworkPath}") +set(NATIVEAOT_SDK_PATH "${libArtifactNativeAotSdkPath}") diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/libhellomanaged/write-nativelib-cmake.targets index 6ff13d433989c..f93ec128f71e7 100644 --- a/src/native/libhellomanaged/write-nativelib-cmake.targets +++ b/src/native/libhellomanaged/write-nativelib-cmake.targets @@ -5,70 +5,66 @@ - + + $(MSBuildThisFileDirectory)Templates/native-lib.shared.cmake.in + $(MSBuildThisFileDirectory)Templates/native-lib.static.cmake.in + - - + Properties="@(NativeLibraryCmakeFragmentProperties->'%(Identity)=%(Value)')" /> + - + $(TargetName.ToUpper()) $(ArtifactsObjDir)\$(TargetName)\$(TargetName).cmake $(TargetName) $(NativeBinaryExt) $(PublishDir)/ + + $(NativeLibraryArtifactLibPath.Replace('\', '\\')) + + + + + + - + $(IlcFrameworkPath.TrimEnd('\\/')) $(IlcSdkPath.TrimEnd('\\/')) - $(NativeLibraryArtifactLibPath.Replace('\', '\\')) $(NativeLibraryArtifactIlcFrameworkPath.Replace('\', '\\')) $(NativeLibraryArtifactIlcSdkPath.Replace('\', '\\')) - - - - - - + + - + $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(StaticLibSuffix)')) - $(NativeLibraryArtifactLibPath.Replace('\', '\\')) $(NativeLibraryArtifactImpLibFullPath.Replace('\', '\\')) - - - - From 556d0b586809f98866844ef969bbaac7c98eddce Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 20 Feb 2024 16:27:46 -0500 Subject: [PATCH 34/84] rename toplevel dir to src/native/managed --- eng/native/import-nativeaot-library.cmake | 2 +- src/coreclr/runtime-prereqs.proj | 2 +- .../Directory.Build.props | 0 .../Templates/native-lib.shared.cmake.in | 0 .../Templates/native-lib.static.cmake.in | 0 .../compile-native.proj | 2 +- .../libhellomanaged/inc/libhellomanaged.h | 0 .../libhellomanaged/src/Entrypoints.cs | 0 .../libhellomanaged/src/libhellomanaged.csproj | 13 +++---------- .../write-nativelib-cmake.targets | 0 10 files changed, 6 insertions(+), 13 deletions(-) rename src/native/{libhellomanaged => managed}/Directory.Build.props (100%) rename src/native/{libhellomanaged => managed}/Templates/native-lib.shared.cmake.in (100%) rename src/native/{libhellomanaged => managed}/Templates/native-lib.static.cmake.in (100%) rename src/native/{libhellomanaged => managed}/compile-native.proj (98%) rename src/native/{ => managed}/libhellomanaged/inc/libhellomanaged.h (100%) rename src/native/{ => managed}/libhellomanaged/src/Entrypoints.cs (100%) rename src/native/{ => managed}/libhellomanaged/src/libhellomanaged.csproj (67%) rename src/native/{libhellomanaged => managed}/write-nativelib-cmake.targets (100%) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index ec233f151c77a..8eaff36d1e5a1 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -101,7 +101,7 @@ function(add_imported_nativeaot_library targetName symbolPrefix) endif() # TODO bake this into the cmake fragment? - target_include_directories(${targetName} INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") + target_include_directories(${targetName} INTERFACE "${CLR_SRC_NATIVE_DIR}/managed/${libName}/inc") elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() diff --git a/src/coreclr/runtime-prereqs.proj b/src/coreclr/runtime-prereqs.proj index 34c8077ce3c13..6bbe50f7d550a 100644 --- a/src/coreclr/runtime-prereqs.proj +++ b/src/coreclr/runtime-prereqs.proj @@ -14,7 +14,7 @@ - + diff --git a/src/native/libhellomanaged/Directory.Build.props b/src/native/managed/Directory.Build.props similarity index 100% rename from src/native/libhellomanaged/Directory.Build.props rename to src/native/managed/Directory.Build.props diff --git a/src/native/libhellomanaged/Templates/native-lib.shared.cmake.in b/src/native/managed/Templates/native-lib.shared.cmake.in similarity index 100% rename from src/native/libhellomanaged/Templates/native-lib.shared.cmake.in rename to src/native/managed/Templates/native-lib.shared.cmake.in diff --git a/src/native/libhellomanaged/Templates/native-lib.static.cmake.in b/src/native/managed/Templates/native-lib.static.cmake.in similarity index 100% rename from src/native/libhellomanaged/Templates/native-lib.static.cmake.in rename to src/native/managed/Templates/native-lib.static.cmake.in diff --git a/src/native/libhellomanaged/compile-native.proj b/src/native/managed/compile-native.proj similarity index 98% rename from src/native/libhellomanaged/compile-native.proj rename to src/native/managed/compile-native.proj index f530673af6b93..955eb1a9b4e68 100644 --- a/src/native/libhellomanaged/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -7,7 +7,7 @@ - + diff --git a/src/native/libhellomanaged/inc/libhellomanaged.h b/src/native/managed/libhellomanaged/inc/libhellomanaged.h similarity index 100% rename from src/native/libhellomanaged/inc/libhellomanaged.h rename to src/native/managed/libhellomanaged/inc/libhellomanaged.h diff --git a/src/native/libhellomanaged/src/Entrypoints.cs b/src/native/managed/libhellomanaged/src/Entrypoints.cs similarity index 100% rename from src/native/libhellomanaged/src/Entrypoints.cs rename to src/native/managed/libhellomanaged/src/Entrypoints.cs diff --git a/src/native/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj similarity index 67% rename from src/native/libhellomanaged/src/libhellomanaged.csproj rename to src/native/managed/libhellomanaged/src/libhellomanaged.csproj index 009881ef32288..b87c822ede1fa 100644 --- a/src/native/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj @@ -9,8 +9,7 @@ true true true - + false @@ -32,15 +31,9 @@ - + - - - - - - - + diff --git a/src/native/libhellomanaged/write-nativelib-cmake.targets b/src/native/managed/write-nativelib-cmake.targets similarity index 100% rename from src/native/libhellomanaged/write-nativelib-cmake.targets rename to src/native/managed/write-nativelib-cmake.targets From fd04a079fe399578b014b7f885db5e8385d6e0c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 11:35:54 -0500 Subject: [PATCH 35/84] allow csproj to specify cmake include dir for native library --- eng/native/import-nativeaot-library.cmake | 4 ++-- src/native/managed/Templates/native-lib.shared.cmake.in | 1 + src/native/managed/Templates/native-lib.static.cmake.in | 1 + .../managed/libhellomanaged/src/libhellomanaged.csproj | 6 ++++-- src/native/managed/write-nativelib-cmake.targets | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 8eaff36d1e5a1..99f0f938feaaf 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -100,8 +100,8 @@ function(add_imported_nativeaot_library targetName symbolPrefix) set_property(TARGET ${targetName} PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") endif() - # TODO bake this into the cmake fragment? - target_include_directories(${targetName} INTERFACE "${CLR_SRC_NATIVE_DIR}/managed/${libName}/inc") + set(libIncludePath "${${symbolPrefix}_INCLUDE}") + target_include_directories(${targetName} INTERFACE "${libIncludePath}") elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() diff --git a/src/native/managed/Templates/native-lib.shared.cmake.in b/src/native/managed/Templates/native-lib.shared.cmake.in index 313afb8cb3185..27cfb7e7c19a8 100644 --- a/src/native/managed/Templates/native-lib.shared.cmake.in +++ b/src/native/managed/Templates/native-lib.shared.cmake.in @@ -3,3 +3,4 @@ set(${libCmakeName}_NAME "${libArtifactName}") set(${libCmakeName}_EXT "${libArtifactExt}") set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") set(${libCmakeName}_IMPLIBPATH "${libArtifactImpLibFullPath}") +set(${libCmakeName}_INCLUDE "${libArtifactIncludePath}") diff --git a/src/native/managed/Templates/native-lib.static.cmake.in b/src/native/managed/Templates/native-lib.static.cmake.in index 2903badddec11..718d557becf19 100644 --- a/src/native/managed/Templates/native-lib.static.cmake.in +++ b/src/native/managed/Templates/native-lib.static.cmake.in @@ -4,3 +4,4 @@ set(${libCmakeName}_EXT "${libArtifactExt}") set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") set(NATIVEAOT_FRAMEWORK_PATH "${libArtifactNativeAotFrameworkPath}") set(NATIVEAOT_SDK_PATH "${libArtifactNativeAotSdkPath}") +set(${libCmakeName}_INCLUDE "${libArtifactIncludePath}") diff --git a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj index b87c822ede1fa..49a876d1c9e9a 100644 --- a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj @@ -23,13 +23,15 @@ @rpath/$(MSBuildProjectName).dylib + + + + - - diff --git a/src/native/managed/write-nativelib-cmake.targets b/src/native/managed/write-nativelib-cmake.targets index f93ec128f71e7..94f2cdf49f840 100644 --- a/src/native/managed/write-nativelib-cmake.targets +++ b/src/native/managed/write-nativelib-cmake.targets @@ -36,6 +36,7 @@ + From f6dd13febae8141806faf3fb514116078fced8e1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:36:33 -0500 Subject: [PATCH 36/84] fixup INCLUDE path for Windows --- src/native/managed/write-nativelib-cmake.targets | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/native/managed/write-nativelib-cmake.targets b/src/native/managed/write-nativelib-cmake.targets index 94f2cdf49f840..d7b9dedefe323 100644 --- a/src/native/managed/write-nativelib-cmake.targets +++ b/src/native/managed/write-nativelib-cmake.targets @@ -30,13 +30,16 @@ $(PublishDir)/ $(NativeLibraryArtifactLibPath.Replace('\', '\\')) + + @(NativeLibraryCmakeFragmentIncludePath, ';') + $(NativeLibraryArtifactIncludePath.Replace('\', '\\')) - + From b06ddeb0f121a307738c5885e786eb0382d404b7 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:37:28 -0500 Subject: [PATCH 37/84] Use find_package to find native AOT libs --- eng/native/functions.cmake | 4 +- eng/native/import-nativeaot-library.cmake | 45 ++++++++++++++----- src/coreclr/debug/daccess/CMakeLists.txt | 15 ++++--- .../native-lib.find_package-config.cmake.in | 10 +++++ .../managed/write-nativelib-cmake.targets | 16 ++++++- 5 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 src/native/managed/Templates/native-lib.find_package-config.cmake.in diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index f6368ce5b1d3f..68ec9f58c9223 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -533,8 +533,8 @@ function(install_clr) endif() add_dependencies(${INSTALL_CLR_COMPONENT} ${targetName}) endif() - get_target_property(targetImportedNativeAotLib ${targetName} CLR_IMPORTED_NATIVEAOT_LIBRARY) - get_target_property(targetType ${targetName} TYPE) + get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) + get_target_property(targetType "${targetName}" TYPE) if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY" AND NOT "${targetImportedNativeAotLib}") get_symbol_file_name(${targetName} symbolFile) endif() diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 99f0f938feaaf..ef7897e973443 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -1,6 +1,24 @@ # Infrastructure to import a native aot compiled library into a native build +# Consumers should use this: +# +# find_nativeaot_library(libraryName [REQUIRED]) +# +function(find_nativeaot_library libraryName) + cmake_parse_arguments(PARSE_ARGV 1 "findNativeAOT_opt" "REQUIRED" "" "") + if (NOT "${findNativeAOT_opt_REQUIRED}") + find_package(${libraryName} CONFIG NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") + else() + find_package(${libraryName} CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") + endif() + set("${libraryName}_FOUND" "${${libraryName}_FOUND}" PARENT_SCOPE) + set("${libCmakeName}_CMAKE_FRAGMENT_PATH") +endfunction() + +### Implementation details used by libraryName-config.cmake find_package configuration +### files. Consumers don't need to do this directly. + # If we're statically linking one or more NativeAOTed libraries, add a target that brings in the # static library NativeAOT runtime components. This function can be called more than once. Each # imported library should add its own dependency on the "nativeAotFramework" target @@ -81,9 +99,18 @@ function(add_nativeAotFramework_targets_once) endif() endfunction() -# see add_imported_nativeaot_library_clr, below -function(add_imported_nativeaot_library targetName symbolPrefix) - message(STATUS "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") +# add_imported_nativeaot_library(targetName symbolPrefix [NAMESPACE namespace]) +# +# adds a target targetName that can be used to reference a NativeAOTed library. symbolPrefix should +# be the ALLCAPS prefix of the variables that define the mode and paths for the library. They are +# typically set in the artifacts/obj/targetName/targetName.cmake fragment which should be included +# before calling this function. +function(add_imported_nativeaot_library targetNameIn symbolPrefix) + cmake_parse_arguments(PARSE_ARGV 2 "add_imported_opt" "" "NAMESPACE" "") + message(TRACE "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") + set(targetName "${add_imported_opt_NAMESPACE}${targetNameIn}") + message(TRACE "Adding target ${targetName}") + if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED") set(libName "${${symbolPrefix}_NAME}") # typically same as targetName set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish @@ -147,16 +174,12 @@ function(add_imported_nativeaot_library targetName symbolPrefix) else() message(FATAL_ERROR "${symbolPrefix}_MODE must be one of SHARED or STATIC") endif() -endfunction() - -# adds a target targetName that can be used to reference a NativeAOTed library. symbolPrefix should -# be the ALLCAPS prefix of the variables that define the mode and paths for the library. They are -# typically set in the artifacts/obj/targetName/targetName.cmake fragment which should be included -# before calling this function. -function(add_imported_nativeaot_library_clr targetName symbolPrefix) - add_imported_nativeaot_library(${ARGV}) # FIXME: target xyz-shared is imported and does not build here #if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) # strip_symbols("${ARGV0}-shared" symbolFile) #endif() endfunction() + +function(add_imported_nativeaot_library_clr targetName symbolPrefix) + add_imported_nativeaot_library(${ARGV}) +endfunction() diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index a09f02c4eed80..e403752000005 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -1,6 +1,12 @@ add_definitions(-DFEATURE_NO_HOST) -include(${CLR_ARTIFACTS_OBJ_DIR}/libhellomanaged/libhellomanaged.cmake OPTIONAL RESULT_VARIABLE INCLUDED_HELLOMANAGED) +find_nativeaot_library(libhellomanaged REQUIRED) +if ("${libhellomanaged_FOUND}") + message(STATUS "found libhellomanaged") +else() + message(FATAL_ERROR "expected libhellomanaged to be found") +endif() +# include(${CLR_ARTIFACTS_OBJ_DIR}/libhellomanaged/libhellomanaged.cmake OPTIONAL RESULT_VARIABLE INCLUDED_HELLOMANAGED) include_directories(BEFORE ${VM_DIR}) include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR}) @@ -43,12 +49,11 @@ add_library_clr(daccess ${DACCESS_SOURCES}) set_target_properties(daccess PROPERTIES DAC_COMPONENT TRUE) target_precompile_headers(daccess PRIVATE [["stdafx.h"]]) -if(NOT "${INCLUDED_HELLOMANAGED}" STREQUAL "NOTFOUND") - add_imported_nativeaot_library_clr(libhellomanagedTarget LIBHELLOMANAGED) - target_link_libraries(daccess PRIVATE libhellomanagedTarget) +if("${libhellomanaged_FOUND}") + target_link_libraries(daccess PRIVATE libhellomanaged::libhellomanaged) target_compile_definitions(daccess PRIVATE HAVE_LIBHELLOMANAGED) # FIXME: can we put this with mscordaccore instead? - install_clr(TARGETS libhellomanagedTarget DESTINATIONS . sharedFramework COMPONENT debug) + install_clr(TARGETS libhellomanaged::libhellomanaged DESTINATIONS . sharedFramework COMPONENT debug) endif() add_dependencies(daccess eventing_headers) diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in new file mode 100644 index 0000000000000..8c71ccfc0c645 --- /dev/null +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -0,0 +1,10 @@ +# This is a Config-style package configuration file for cmake's find_package command for ${libArtifactName} +set(CMAKE_FRAGMENT_PATH "${libArtifactConfigFragment}") + +include("`${CLR_ENG_NATIVE_DIR}/import-nativeaot-library.cmake") + +include("`${CMAKE_FRAGMENT_PATH}") + +# adds a ${libArtifactName}::${libArtifactName} target +add_imported_nativeaot_library("${libArtifactName}" "${libCmakeName}" NAMESPACE "${libArtifactName}::") + diff --git a/src/native/managed/write-nativelib-cmake.targets b/src/native/managed/write-nativelib-cmake.targets index d7b9dedefe323..12270ee77e366 100644 --- a/src/native/managed/write-nativelib-cmake.targets +++ b/src/native/managed/write-nativelib-cmake.targets @@ -3,10 +3,15 @@ + + $([MSBuild]::NormalizeDirectory('$(ArtifactsObjDir)\cmake\find_package\')) + + + + Outputs="$(NativeLibraryCMakeFragmentPath);$(NativeLibraryCMakeFindPackageConfigPath)"> @@ -40,6 +51,7 @@ + From 533f183b82a25cdfea89a9c90f970c7d1068820d Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:37:47 -0500 Subject: [PATCH 38/84] Add README --- src/native/managed/README.md | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/native/managed/README.md diff --git a/src/native/managed/README.md b/src/native/managed/README.md new file mode 100644 index 0000000000000..a1a7e7c1435b4 --- /dev/null +++ b/src/native/managed/README.md @@ -0,0 +1,51 @@ +# Native runtime component libraries using NativeAOT + +This directory contains managed libraries that will be compiled using NativeAOT and can be used in runtime components. + +## Using existing libraries + +In a `CMakeLists.txt` add + +``` cmake +find_nativeaot_library(libWhatever REQUIRED) +``` + +This will look for a cmake fragment file in +`artifacts/obj/cmake/find_package/libWhatever-config.cmake` that will import some variables from +`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libWhatever` that can +be used as a dependency in `target_link_libraries()` or in a `install_clr()` command. + + +## Adding a new managed library + +Add a new subdirectory to `src/native/managed` for your library with a `src` and `inc` subdirectories: + +``` console +$ mkdir -p libMyNewLibrary/src libMyNewLibrary/inc +$ dotnet new classlib -n libMyNewLibrary -o libMyNewLibrary/src +``` + +In `src/native/managed/compile-native.proj`, add +`src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj` to the `NativeLibsProjectsToBuild` +item group. + +In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: +1. Set `PublishAot` to true +2. Set `@rpath/$(MSBuildProjectName).dylib` +3. Set `` + +The following is recommended: + +1. The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms. +2. The project should just have a single `EntryPoints.cs` that has a `static class` that provides + `[UnmanagedCallersOnly]` API entrypoints. The bulk of the code should be imported using + `ProjectReference` from another managed class library project. That managed project can be + tested using normal managed unit tests, consumed in other managed libraries, etc. +3. The `inc` directory should provide a `libMyNewLibrary.h` header file with a C declaration for each entrypoint. + + +Limitations: + +Currently only shared library output is supported. In principle static linking is possible, but the +infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with static +linking will not be supported on Windows. From 211d683a696dacc81e147f20ab39eb031b4840e9 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:39:34 -0500 Subject: [PATCH 39/84] remove unused function --- eng/native/import-nativeaot-library.cmake | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index ef7897e973443..9554223fb9726 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -179,7 +179,3 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) # strip_symbols("${ARGV0}-shared" symbolFile) #endif() endfunction() - -function(add_imported_nativeaot_library_clr targetName symbolPrefix) - add_imported_nativeaot_library(${ARGV}) -endfunction() From 70db26189ba7c5b41c76ddf2eabc91e05be8d103 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:40:45 -0500 Subject: [PATCH 40/84] libhellomanaged is optional --- src/coreclr/debug/daccess/CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index e403752000005..08ede628675f9 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -1,12 +1,6 @@ add_definitions(-DFEATURE_NO_HOST) -find_nativeaot_library(libhellomanaged REQUIRED) -if ("${libhellomanaged_FOUND}") - message(STATUS "found libhellomanaged") -else() - message(FATAL_ERROR "expected libhellomanaged to be found") -endif() -# include(${CLR_ARTIFACTS_OBJ_DIR}/libhellomanaged/libhellomanaged.cmake OPTIONAL RESULT_VARIABLE INCLUDED_HELLOMANAGED) +find_nativeaot_library(libhellomanaged) include_directories(BEFORE ${VM_DIR}) include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR}) From f9b52d5896b8b541301323cc1c250f69f4c5e72d Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:45:38 -0500 Subject: [PATCH 41/84] move user-facing cmake to eng/functions.cmake --- eng/native/functions.cmake | 20 ++++++++++++++++++++ eng/native/import-nativeaot-library.cmake | 15 --------------- src/coreclr/CMakeLists.txt | 2 -- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 68ec9f58c9223..d0f867adc88d6 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -678,3 +678,23 @@ function(adhoc_sign_with_entitlements targetName entitlementsFile) POST_BUILD COMMAND codesign -s - -f --entitlements ${entitlementsFile} $) endfunction() + +# find_nativeaot_library(libraryName [REQUIRED]) +# +# Imports a native library produced by NativeAOT (see src/native/managed). +# If the library is found, sets libraryName_FOUND to true, else false. +# If the library is found, a target libraryName::libraryName is defined. +# If REQUIRED is specified, it's a fatal error not to find the library, otherwise the library is considered optional. +# +# For implementation details see import-nativeaot-library.cmake +function(find_nativeaot_library libraryName) + cmake_parse_arguments(PARSE_ARGV 1 "findNativeAOT_opt" "REQUIRED" "" "") + if (NOT "${findNativeAOT_opt_REQUIRED}") + find_package(${libraryName} CONFIG NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") + else() + find_package(${libraryName} CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") + endif() + set("${libraryName}_FOUND" "${${libraryName}_FOUND}" PARENT_SCOPE) + set("${libCmakeName}_CMAKE_FRAGMENT_PATH") +endfunction() + diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 9554223fb9726..2318cdcaae0c1 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -1,21 +1,6 @@ # Infrastructure to import a native aot compiled library into a native build -# Consumers should use this: -# -# find_nativeaot_library(libraryName [REQUIRED]) -# -function(find_nativeaot_library libraryName) - cmake_parse_arguments(PARSE_ARGV 1 "findNativeAOT_opt" "REQUIRED" "" "") - if (NOT "${findNativeAOT_opt_REQUIRED}") - find_package(${libraryName} CONFIG NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") - else() - find_package(${libraryName} CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") - endif() - set("${libraryName}_FOUND" "${${libraryName}_FOUND}" PARENT_SCOPE) - set("${libCmakeName}_CMAKE_FRAGMENT_PATH") -endfunction() - ### Implementation details used by libraryName-config.cmake find_package configuration ### files. Consumers don't need to do this directly. diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 1bbde5fac19f2..1c314d9bf624e 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -9,8 +9,6 @@ include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) include_directories("${CLR_SRC_NATIVE_DIR}") include_directories("${CLR_SRC_NATIVE_DIR}/inc") -include(${CLR_ENG_NATIVE_DIR}/import-nativeaot-library.cmake) - if(MSVC) set(CMAKE_CXX_STANDARD_LIBRARIES "") # do not link against standard win32 libs i.e. kernel32, uuid, user32, etc. endif (MSVC) From c3b231dedc6e3312115c84cc1a579b3c09498030 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 13:51:19 -0500 Subject: [PATCH 42/84] remove cruft --- .../src/Microsoft.DotNet.HelloManaged.csproj | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj index a7643942a8eef..b90a61572801b 100644 --- a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj +++ b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj @@ -1,7 +1,6 @@ - $(NetCoreAppToolCurrent) Example managed library that will be included in a NativeAOT compiled binary true @@ -10,22 +9,8 @@ true true true - + false - - - - - - - - - - - - - From 014a67447979a068e211845d810e7bf1be4506b4 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 14:00:17 -0500 Subject: [PATCH 43/84] fix windows paths --- src/native/managed/write-nativelib-cmake.targets | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/native/managed/write-nativelib-cmake.targets b/src/native/managed/write-nativelib-cmake.targets index 12270ee77e366..05404d504b5bb 100644 --- a/src/native/managed/write-nativelib-cmake.targets +++ b/src/native/managed/write-nativelib-cmake.targets @@ -44,6 +44,9 @@ @(NativeLibraryCmakeFragmentIncludePath, ';') $(NativeLibraryArtifactIncludePath.Replace('\', '\\')) + + $(NativeLibraryCMakeFragmentPath.Replace('\', '\\')) + $(NativeLibraryCMakeFragmentPath) @@ -51,7 +54,7 @@ - + From 0c964654b03c974f9ec9ad2678247a44e20a9efe Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 14:58:21 -0500 Subject: [PATCH 44/84] Use unix-style paths even on Windows; cmake prefers this --- eng/native/import-nativeaot-library.cmake | 4 +-- .../managed/write-nativelib-cmake.targets | 32 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 2318cdcaae0c1..c6311c6e10ed4 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -102,7 +102,7 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) set(libFilename "${libName}${${symbolPrefix}_EXT}") # .dll, .so or .dylib set(libFullPath "${libPath}/${libFilename}") # windows import library - set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically \...\artifacts\bin\\\\native\.lib + set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically /.../artifacts/bin////native/.lib add_library(${targetName} SHARED IMPORTED GLOBAL) set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${libFullPath}") @@ -146,7 +146,7 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) target_link_options(${targetName}-static INTERFACE "LINKER:--exclude-libs=${libFilename}") elseif("${CLR_CMAKE_HOST_WIN32}") add_library(${targetName}-static STATIC IMPORTED) - set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}\\${libFilename}") + set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}/${libFilename}") endif() # TODO bake this into the cmake fragment? diff --git a/src/native/managed/write-nativelib-cmake.targets b/src/native/managed/write-nativelib-cmake.targets index 05404d504b5bb..1555d1afbc122 100644 --- a/src/native/managed/write-nativelib-cmake.targets +++ b/src/native/managed/write-nativelib-cmake.targets @@ -39,34 +39,34 @@ $(NativeLibraryCMakeFindPackageConfigOutputPath)$(NativeLibraryArtifactName)-config.cmake $(NativeBinaryExt) $(PublishDir)/ - - $(NativeLibraryArtifactLibPath.Replace('\', '\\')) - + + $(NativeLibraryArtifactLibPath.Replace('\', '/')) + @(NativeLibraryCmakeFragmentIncludePath, ';') - $(NativeLibraryArtifactIncludePath.Replace('\', '\\')) - - $(NativeLibraryCMakeFragmentPath.Replace('\', '\\')) + $(NativeLibraryArtifactIncludePath.Replace('\', '/')) + + $(NativeLibraryCMakeFragmentPath.Replace('\', '/')) $(NativeLibraryCMakeFragmentPath) - - + + - $(IlcFrameworkPath.TrimEnd('\\/')) - $(IlcSdkPath.TrimEnd('\\/')) + $(IlcFrameworkPath.TrimEnd('\/')) + $(IlcSdkPath.TrimEnd('\/')) - + - $(NativeLibraryArtifactIlcFrameworkPath.Replace('\', '\\')) - $(NativeLibraryArtifactIlcSdkPath.Replace('\', '\\')) + $(NativeLibraryArtifactIlcFrameworkPath.Replace('\', '/')) + $(NativeLibraryArtifactIlcSdkPath.Replace('\', '/')) @@ -79,12 +79,12 @@ $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(StaticLibSuffix)')) - + - $(NativeLibraryArtifactImpLibFullPath.Replace('\', '\\')) + $(NativeLibraryArtifactImpLibFullPath.Replace('\', '/')) - + From bf6c499ea27405a52dfde9333339f529a3d61f48 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 21 Feb 2024 16:44:58 -0500 Subject: [PATCH 45/84] dependency tracking and stripping --- eng/native/functions.cmake | 73 ++++++++++++++----- eng/native/import-nativeaot-library.cmake | 21 +++++- .../src/libhellomanaged.csproj | 1 + .../src/HelloManaged.cs | 2 +- 4 files changed, 78 insertions(+), 19 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index d0f867adc88d6..1818f69d4220e 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -367,18 +367,39 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix) endfunction() function (get_symbol_file_name targetName outputSymbolFilename) - if (CLR_CMAKE_HOST_UNIX) - if (CLR_CMAKE_TARGET_APPLE) - set(strip_destination_file $.dwarf) - else () - set(strip_destination_file $.dbg) - endif () - - set(${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE) - elseif(CLR_CMAKE_HOST_WIN32) - # We can't use the $ generator expression here since - # the generator expression isn't supported on resource DLLs. - set(${outputSymbolFilename} $/$$.pdb PARENT_SCOPE) + get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) + if (NOT "${targetImportedNativeAotLib}") + if (CLR_CMAKE_HOST_UNIX) + if (CLR_CMAKE_TARGET_APPLE) + set(strip_destination_file $.dwarf) + else () + set(strip_destination_file $.dbg) + endif () + + set(${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE) + elseif(CLR_CMAKE_HOST_WIN32) + # We can't use the $ generator expression here since + # the generator expression isn't supported on resource DLLs. + set(${outputSymbolFilename} $/$$.pdb PARENT_SCOPE) + endif() + else() + get_property(libraryType TARGET ${targetName} PROPERTY TYPE) + message(TRACE "Target ${targetName} is imported of type ${libraryType}") + if ("${libraryType}" STREQUAL "SHARED_LIBRARY") + get_property(importedLocation TARGET ${targetName} PROPERTY IMPORTED_LOCATION) + message(TRACE "Target ${targetName} is imported from ${importedLocation}") + if (CLR_CMAKE_HOST_UNIX) + if (CLR_CMAKE_TARGET_APPLE) + set(importedLocation "${importedLocation}.dwarf") + else() + set(importedLocation "${importedLocation}.dbg") + endif() + elseif(CLR_CMAKE_HOST_WIN32) + cmake_path(REPLACE_EXTENSION "${importedLocation}" ".pdb") + endif() + set(${outputSymbolFilename} "${importedLocation}" PARENT_SCOPE) + message(TRACE "Target ${targetName} symbols will be in ${importedLocation}") + endif() endif() endfunction() @@ -386,7 +407,14 @@ function(strip_symbols targetName outputFilename) get_symbol_file_name(${targetName} strip_destination_file) set(${outputFilename} ${strip_destination_file} PARENT_SCOPE) if (CLR_CMAKE_HOST_UNIX) - set(strip_source_file $) + get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) + if (NOT "${targetImportedNativeAotLib}") + set(strip_source_file $) + else() + get_property(strip_source_file TARGET ${targetName} PROPERTY IMPORTED_LOCATION) + # for an imported library, we will hang the post-build event on the copy target + get_property(copy_target TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY_COPY_TARGET) + endif() if (CLR_CMAKE_TARGET_APPLE) @@ -421,8 +449,14 @@ function(strip_symbols targetName outputFilename) list(APPEND DSYMUTIL_OPTS "--minimize") endif () + if (NOT "${targetImportedNativeAotLib}") + set(post_build_target "${targetName}") + else() + set(post_build_target "${copy_target}") + endif() + add_custom_command( - TARGET ${targetName} + TARGET ${post_build_target} POST_BUILD VERBATIM COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" @@ -431,8 +465,14 @@ function(strip_symbols targetName outputFilename) ) else (CLR_CMAKE_TARGET_APPLE) + if (NOT "${targetImportedNativeAotLib}") + set(post_build_target "${targetName}") + else() + set(post_build_target "${copy_target}") + endif() + add_custom_command( - TARGET ${targetName} + TARGET ${post_build_target} POST_BUILD VERBATIM COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" @@ -535,10 +575,9 @@ function(install_clr) endif() get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) get_target_property(targetType "${targetName}" TYPE) - if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY" AND NOT "${targetImportedNativeAotLib}") + if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY") get_symbol_file_name(${targetName} symbolFile) endif() - # FIXME: make symbol files for native aot libs too foreach(destination ${destinations}) # We don't need to install the export libraries for our DLLs diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index c6311c6e10ed4..d237fe76dac21 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -104,9 +104,26 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) # windows import library set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically /.../artifacts/bin////native/.lib + # Copy the imported library into our binary dir. + # We do this so that we may strip it and also so that cmake dependency tracking will be aware if the file changes + set (importedFullPath "${CMAKE_CURRENT_BINARY_DIR}/imported_nativeaot_library/${targetNameIn}/${libFilename}") + + add_custom_command(OUTPUT "${importedFullPath}" + DEPENDS "${libFullPath}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${libFullPath}" "${importedFullPath}" + ) + # TODO: if Windows, also copy the PDB file + + # now make a custom target that other targets can depend on + set(copy_target_name "${targetNameIn}_copy_imported_library") + add_custom_target("${copy_target_name}" DEPENDS "${importedFullPath}") + + add_library(${targetName} SHARED IMPORTED GLOBAL) - set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${libFullPath}") + add_dependencies(${targetName} "${copy_target_name}") + set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${importedFullPath}") set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) + set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY_COPY_TARGET "${copy_target_name}") if("${CLR_CMAKE_HOST_WIN32}") set_property(TARGET ${targetName} PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") @@ -115,6 +132,8 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) set(libIncludePath "${${symbolPrefix}_INCLUDE}") target_include_directories(${targetName} INTERFACE "${libIncludePath}") + strip_symbols(${targetName} symbolFile) + elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() diff --git a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj index 49a876d1c9e9a..67591b21fb715 100644 --- a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj @@ -16,6 +16,7 @@ true true + false diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs b/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs index f046936b1be77..6f57b84c0c5db 100644 --- a/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs +++ b/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs @@ -9,5 +9,5 @@ public class HelloManaged { public HelloManaged() {} - public ulong GetMagic() => 0x20240209L; + public ulong GetMagic() => 0x20240222L; } From 44ba2cc819870431f1ad0e3c2c94a0448a57e679 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 12:06:28 -0500 Subject: [PATCH 46/84] windows stripping support --- eng/native/functions.cmake | 2 +- eng/native/import-nativeaot-library.cmake | 54 ++++++++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 1818f69d4220e..84e741c719f5b 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -395,7 +395,7 @@ function (get_symbol_file_name targetName outputSymbolFilename) set(importedLocation "${importedLocation}.dbg") endif() elseif(CLR_CMAKE_HOST_WIN32) - cmake_path(REPLACE_EXTENSION "${importedLocation}" ".pdb") + cmake_path(REPLACE_EXTENSION importedLocation ".pdb") endif() set(${outputSymbolFilename} "${importedLocation}" PARENT_SCOPE) message(TRACE "Target ${targetName} symbols will be in ${importedLocation}") diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index d237fe76dac21..731f877d01d31 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -1,8 +1,7 @@ - # Infrastructure to import a native aot compiled library into a native build -### Implementation details used by libraryName-config.cmake find_package configuration -### files. Consumers don't need to do this directly. +# ## Implementation details used by libraryName-config.cmake find_package configuration +# ## files. Consumers don't need to do this directly. # If we're statically linking one or more NativeAOTed libraries, add a target that brings in the # static library NativeAOT runtime components. This function can be called more than once. Each @@ -13,13 +12,13 @@ # they will each run in their own isolated NativeAOT runtime. function(add_nativeAotFramework_targets_once) get_property(targets_added GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED) - if (NOT "${targets_added}") + + if(NOT "${targets_added}") add_library(nativeAotFramework INTERFACE) # depends on NATIVEAOT_FRAMEWORK_PATH and NATIVEAOT_SDK_PATH to be set # by the generated .cmake fragment during the managed build - - if ("${CLR_CMAKE_HOST_WIN32}") + if("${CLR_CMAKE_HOST_WIN32}") set(NAOT_SDK_BASE_BOOTSTRAP bootstrapperdll${CMAKE_C_OUTPUT_EXTENSION}) else() set(NAOT_SDK_BASE_BOOTSTRAP libbootstrapperdll${CMAKE_C_OUTPUT_EXTENSION}) @@ -79,7 +78,7 @@ function(add_nativeAotFramework_targets_once) target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_LIBS}" "${NAOT_FRAMEWORK_LIBS}" BCrypt) endif() - + set_property(GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED 1) endif() endfunction() @@ -95,29 +94,45 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) message(TRACE "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") set(targetName "${add_imported_opt_NAMESPACE}${targetNameIn}") message(TRACE "Adding target ${targetName}") - - if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED") + + if("${${symbolPrefix}_MODE}" STREQUAL "SHARED") set(libName "${${symbolPrefix}_NAME}") # typically same as targetName set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish set(libFilename "${libName}${${symbolPrefix}_EXT}") # .dll, .so or .dylib set(libFullPath "${libPath}/${libFilename}") + + if(CLR_CMAKE_HOST_WIN32) + set(libPdbFullPath "${libPath}/${libName}.pdb") + endif() + # windows import library set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically /.../artifacts/bin////native/.lib # Copy the imported library into our binary dir. # We do this so that we may strip it and also so that cmake dependency tracking will be aware if the file changes - set (importedFullPath "${CMAKE_CURRENT_BINARY_DIR}/imported_nativeaot_library/${targetNameIn}/${libFilename}") + set(importedFullPath "${CMAKE_CURRENT_BINARY_DIR}/imported_nativeaot_library/${targetNameIn}/${libFilename}") add_custom_command(OUTPUT "${importedFullPath}" DEPENDS "${libFullPath}" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${libFullPath}" "${importedFullPath}" ) - # TODO: if Windows, also copy the PDB file - + + if(CLR_CMAKE_HOST_WIN32) + set(importedPdbFullPath "${CMAKE_CURRENT_BINARY_DIR}/imported_nativeaot_library/${targetNameIn}/${libName}.pdb") + message(STATUS "Copying ${libPdbFullPath} to ${importedPdbFullPath} for ${targetName}") + add_custom_command(OUTPUT "${importedPdbFullPath}" + DEPENDS "${libPdbFullPath}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${libPdbFullPath}" "${importedPdbFullPath}") + endif() + # now make a custom target that other targets can depend on set(copy_target_name "${targetNameIn}_copy_imported_library") - add_custom_target("${copy_target_name}" DEPENDS "${importedFullPath}") - + + if(CLR_CMAKE_HOST_WIN32) + add_custom_target("${copy_target_name}" DEPENDS "${importedFullPath}" "${importedPdbFullPath}") + else() + add_custom_target("${copy_target_name}" DEPENDS "${importedFullPath}") + endif() add_library(${targetName} SHARED IMPORTED GLOBAL) add_dependencies(${targetName} "${copy_target_name}") @@ -134,7 +149,7 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) strip_symbols(${targetName} symbolFile) - elseif ("${${symbolPrefix}_MODE}" STREQUAL "STATIC") + elseif("${${symbolPrefix}_MODE}" STREQUAL "STATIC") add_nativeAotFramework_targets_once() set(libName "${${symbolPrefix}_NAME}") # typically same as targetName @@ -151,9 +166,9 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) # "-fvisibility=hidden" mechanism would hide all the non-exported symbols. Or if we had an # exported symbols list we could use an LD version script or the apple -exported_symbols_list # option. But we dont' have that, so instead we use the GNU LD `--exclude-libs=libtargetName.a` option, or the apple `-hidden-ltargetName` option - if("${CLR_CMAKE_HOST_APPLE}") message(STATUS creeating ${targetName}-static for apple) + # hack: -hidden-l wants the library name without a "lib" prefix STRING(REGEX REPLACE "^lib" "" libBaseName ${libName}) add_library(${targetName}-static INTERFACE IMPORTED) @@ -177,9 +192,6 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) else() message(FATAL_ERROR "${symbolPrefix}_MODE must be one of SHARED or STATIC") - endif() - # FIXME: target xyz-shared is imported and does not build here - #if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) - # strip_symbols("${ARGV0}-shared" symbolFile) - #endif() + endif() # FIXME: target xyz-shared is imported and does not build here# if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)# strip_symbols("${ARGV0}-shared" symbolFile) +# endif() endfunction() From 3184d6dc8554b1f927f8b79a2ffb2214e230ad4a Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 12:32:47 -0500 Subject: [PATCH 47/84] cleanup --- .../src/libhellomanaged.csproj | 22 ++----------------- src/native/managed/native-library.props | 18 +++++++++++++++ ...b-cmake.targets => native-library.targets} | 6 +++++ 3 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 src/native/managed/native-library.props rename src/native/managed/{write-nativelib-cmake.targets => native-library.targets} (95%) diff --git a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj index 67591b21fb715..be6fb74310879 100644 --- a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj @@ -13,30 +13,12 @@ false - - true - true - false - - - - - @rpath/$(MSBuildProjectName).dylib - - - - - - - - - - + - + diff --git a/src/native/managed/native-library.props b/src/native/managed/native-library.props new file mode 100644 index 0000000000000..7f2c29b70e9d2 --- /dev/null +++ b/src/native/managed/native-library.props @@ -0,0 +1,18 @@ + + + true + true + + false + + + + + @rpath/$(MSBuildProjectName).dylib + + + + + + + diff --git a/src/native/managed/write-nativelib-cmake.targets b/src/native/managed/native-library.targets similarity index 95% rename from src/native/managed/write-nativelib-cmake.targets rename to src/native/managed/native-library.targets index 1555d1afbc122..e7d47998c9d0a 100644 --- a/src/native/managed/write-nativelib-cmake.targets +++ b/src/native/managed/native-library.targets @@ -3,6 +3,12 @@ + + + + + + $([MSBuild]::NormalizeDirectory('$(ArtifactsObjDir)\cmake\find_package\')) From 38353257019cbcfce1745bcb3bd558e9f1cb54a1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 12:38:06 -0500 Subject: [PATCH 48/84] update README --- src/native/managed/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/native/managed/README.md b/src/native/managed/README.md index a1a7e7c1435b4..7b8e89390187f 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -30,9 +30,8 @@ In `src/native/managed/compile-native.proj`, add item group. In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: -1. Set `PublishAot` to true -2. Set `@rpath/$(MSBuildProjectName).dylib` -3. Set `` +1. Near the top, add `` +2. Near the bottom, add `` The following is recommended: @@ -41,8 +40,11 @@ The following is recommended: `[UnmanagedCallersOnly]` API entrypoints. The bulk of the code should be imported using `ProjectReference` from another managed class library project. That managed project can be tested using normal managed unit tests, consumed in other managed libraries, etc. -3. The `inc` directory should provide a `libMyNewLibrary.h` header file with a C declaration for each entrypoint. - +3. The `inc` directory if it exists will be added to the include path of any cmake targets that + depend on the native library. Typically the directory should contain a `libMyNewLibrary.h` header + file with a C declaration for each entrypoint. If you want ot have more include directories, add + them all to the `NativeLibraryCmakeFragmentIncludePath` item. In that case `inc` won't be added + by default. Limitations: From 4b0402925794c72d7c574b3f87e210d59e674cc6 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 12:42:33 -0500 Subject: [PATCH 49/84] remove FIXME --- src/native/managed/compile-native.proj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 955eb1a9b4e68..8f843bbc9f1c4 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -35,7 +35,6 @@ AdditionalProperties="%(AdditionalProperties);RuntimeConfiguration=$(RuntimeConfiguration);LibrariesConfiguration=$(LibrariesConfiguration);RuntimeIdentifier=$(OutputRID);NativeLib=$(NativeLibKind)$(ExtraProps)"/> - From 77d9899d387c2fe1766887121c5df4c3ffae494f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 12:51:37 -0500 Subject: [PATCH 50/84] remove static linking support it wasn't a good fit for CoreCLR because the EventPipe and GC symbols clashed between CoreCLR and NativeAOT during static linking. A possible way forward is to use incremental linking (`clang -Wl,-r`) on Linux/Mac in combination with the `--exclude-libs` or `-hidden-lx` linker options. However on Windows since NativeAOT static artifacts are always built in Release mode, we would only be able to do static linking in limited circumstances (and we would need to find the right linker option to do the apropriate symbol hiding / incremental linking) --- eng/native/functions.cmake | 1 - eng/native/import-nativeaot-library.cmake | 126 +----------------- .../Templates/native-lib.static.cmake.in | 7 - src/native/managed/compile-native.proj | 2 +- src/native/managed/native-library.targets | 22 +-- 5 files changed, 7 insertions(+), 151 deletions(-) delete mode 100644 src/native/managed/Templates/native-lib.static.cmake.in diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 84e741c719f5b..5187b8453096d 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -589,7 +589,6 @@ function(install_clr) endif() elseif("${targetType}" STREQUAL "SHARED_LIBRARY") #imported shared lib - install the imported artifacts - #imported static lib - nothing to install if ("${CMAKE_VERSION}" VERSION_LESS "3.21") install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 731f877d01d31..d548c4977c7fd 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -3,86 +3,6 @@ # ## Implementation details used by libraryName-config.cmake find_package configuration # ## files. Consumers don't need to do this directly. -# If we're statically linking one or more NativeAOTed libraries, add a target that brings in the -# static library NativeAOT runtime components. This function can be called more than once. Each -# imported library should add its own dependency on the "nativeAotFramework" target -# -# This is only necessary if NativeAOT libraries are compiled to static native libraries (in which -# case they will share a single NativeAOT runtime). If all the NativeAOTed libraries are shared, -# they will each run in their own isolated NativeAOT runtime. -function(add_nativeAotFramework_targets_once) - get_property(targets_added GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED) - - if(NOT "${targets_added}") - add_library(nativeAotFramework INTERFACE) - - # depends on NATIVEAOT_FRAMEWORK_PATH and NATIVEAOT_SDK_PATH to be set - # by the generated .cmake fragment during the managed build - if("${CLR_CMAKE_HOST_WIN32}") - set(NAOT_SDK_BASE_BOOTSTRAP bootstrapperdll${CMAKE_C_OUTPUT_EXTENSION}) - else() - set(NAOT_SDK_BASE_BOOTSTRAP libbootstrapperdll${CMAKE_C_OUTPUT_EXTENSION}) - endif() - - set(NAOT_SDK_BASE_LIBS - Runtime.WorkstationGC - eventpipe-disabled) - - if(NOT "${CLR_CMAKE_HOST_WIN32}") - list(APPEND NAOT_SDK_BASE_LIBS stdc++compat) - else() - list(APPEND NAOT_SDK_BASE_LIBS - Runtime.VxsortEnabled - System.Globalization.Native.Aot - System.IO.Compression.Native.Aot - ) - endif() - - addprefix(NAOT_SDK_BOOTSTRAP "${NATIVEAOT_SDK_PATH}" "${NAOT_SDK_BASE_BOOTSTRAP}") - addprefix(NAOT_SDK_LIBS "${NATIVEAOT_SDK_PATH}" "${NAOT_SDK_BASE_LIBS}") - - if("${CLR_CMAKE_HOST_WIN32}") - set(NAOT_FRAMEWORK_BASE_LIBS) - else() - set(NAOT_FRAMEWORK_BASE_LIBS - System.Native - System.Globalization.Native - System.IO.Compression.Native - System.Net.Security.Native - System.Security.Cryptography.Native.OpenSsl) - endif() - - addprefix(NAOT_FRAMEWORK_LIBS "${NATIVEAOT_FRAMEWORK_PATH}" "${NAOT_FRAMEWORK_BASE_LIBS}") - - if("${CLR_CMAKE_HOST_WIN32}") - list(TRANSFORM NAOT_FRAMEWORK_LIBS APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}") - list(TRANSFORM NAOT_SDK_LIBS APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif() - - if("${CLR_CMAKE_HOST_APPLE}") - list(TRANSFORM NAOT_SDK_BASE_LIBS PREPEND "-Wl,-hidden-l" OUTPUT_VARIABLE NAOT_SDK_HIDDEN_LIBS) - list(TRANSFORM NAOT_FRAMEWORK_BASE_LIBS PREPEND "-Wl,-hidden-l" OUTPUT_VARIABLE NAOT_FRAMEWORK_HIDDEN_LIBS) - target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") - target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_HIDDEN_LIBS}" "${NAOT_FRAMEWORK_HIDDEN_LIBS}" -lm) - elseif("${CLR_CMAKE_HOST_UNIX}") - target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") - list(TRANSFORM NAOT_SDK_BASE_LIBS PREPEND "lib" OUTPUT_VARIABLE NAOT_SDK_HIDDEN_LIBS) - list(TRANSFORM NAOT_FRAMEWORK_BASE_LIBS PREPEND "lib" OUTPUT_VARIABLE NAOT_FRAMEWORK_HIDDEN_LIBS) - string(REPLACE ";" ":" NAOT_SDK_EXCLUDE_ARG "${NAOT_SDK_HIDDEN_LIBS}") - string(REPLACE ";" ":" NAOT_FRAMEWORK_EXCLUDE_ARG "${NAOT_FRAMEWORK_HIDDEN_LIBS}") - target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_BASE_LIBS}" "${NAOT_FRAMEWORK_BASE_LIBS}" -lm) - target_link_options(nativeAotFramework INTERFACE "LINKER:--exclude-libs=${NAOT_SDK_EXCLUDE_ARG}:${NAOT_FRAMEWORK_EXCLUDE_ARG}") - target_link_options(nativeAotFramework INTERFACE "LINKER:--discard-all") - target_link_options(nativeAotFramework INTERFACE "LINKER:--gc-sections") - elseif("${CLR_CMAKE_HOST_WIN32}") - target_link_directories(nativeAotFramework INTERFACE "${NATIVEAOT_FRAMEWORK_PATH}" "${NATIVEAOT_SDK_PATH}") - target_link_libraries(nativeAotFramework INTERFACE "${NAOT_SDK_BOOTSTRAP}" "${NAOT_SDK_LIBS}" "${NAOT_FRAMEWORK_LIBS}" BCrypt) - endif() - - set_property(GLOBAL PROPERTY CLR_CMAKE_NATIVEAOTFRAMEWORK_TARGETS_ADDED 1) - endif() -endfunction() - # add_imported_nativeaot_library(targetName symbolPrefix [NAMESPACE namespace]) # # adds a target targetName that can be used to reference a NativeAOTed library. symbolPrefix should @@ -149,49 +69,7 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) strip_symbols(${targetName} symbolFile) - elseif("${${symbolPrefix}_MODE}" STREQUAL "STATIC") - add_nativeAotFramework_targets_once() - - set(libName "${${symbolPrefix}_NAME}") # typically same as targetName - set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish - set(libFilename "${libName}${${symbolPrefix}_EXT}") # targetName.a or targetName.lib - - # FIXME: annoyingly cmake doesn't treat changes at IMPORTED_LOCATION or target_link_libraries as - # a trigger to rebuild the downstream targets. we might need to use an add_custom_command that - # pretends the library is a BYPRODUCTS of the custom command. although that will cause the - # library to be deleted if we ever run "make clean". Maybe that's what we want. - - # what we're trying to achieve is that all the symbols from the static library are hidden in the - # final shared library or executable target. If we had object files, the normal GCC/Clang - # "-fvisibility=hidden" mechanism would hide all the non-exported symbols. Or if we had an - # exported symbols list we could use an LD version script or the apple -exported_symbols_list - # option. But we dont' have that, so instead we use the GNU LD `--exclude-libs=libtargetName.a` option, or the apple `-hidden-ltargetName` option - if("${CLR_CMAKE_HOST_APPLE}") - message(STATUS creeating ${targetName}-static for apple) - - # hack: -hidden-l wants the library name without a "lib" prefix - STRING(REGEX REPLACE "^lib" "" libBaseName ${libName}) - add_library(${targetName}-static INTERFACE IMPORTED) - target_link_directories(${targetName}-static INTERFACE "${libPath}") - target_link_libraries(${targetName}-static INTERFACE "-Wl,-hidden-l${libBaseName}") - elseif("${CLR_CMAKE_HOST_UNIX}") - add_library(${targetName}-static STATIC IMPORTED) - set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}/${libFilename}") - target_link_options(${targetName}-static INTERFACE "LINKER:--exclude-libs=${libFilename}") - elseif("${CLR_CMAKE_HOST_WIN32}") - add_library(${targetName}-static STATIC IMPORTED) - set_property(TARGET ${targetName}-static PROPERTY IMPORTED_LOCATION "${libPath}/${libFilename}") - endif() - - # TODO bake this into the cmake fragment? - target_include_directories(${targetName}-static INTERFACE "${CLR_SRC_NATIVE_DIR}/${libName}/inc") - target_link_libraries(${targetName}-static INTERFACE nativeAotFramework) - - add_library(${targetName} INTERFACE) - target_link_libraries(${targetName} INTERFACE ${targetName}-static) - set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) else() - message(FATAL_ERROR "${symbolPrefix}_MODE must be one of SHARED or STATIC") - endif() # FIXME: target xyz-shared is imported and does not build here# if ("${${symbolPrefix}_MODE}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)# strip_symbols("${ARGV0}-shared" symbolFile) -# endif() + message(FATAL_ERROR "${symbolPrefix}_MODE must be SHARED") + endif() endfunction() diff --git a/src/native/managed/Templates/native-lib.static.cmake.in b/src/native/managed/Templates/native-lib.static.cmake.in deleted file mode 100644 index 718d557becf19..0000000000000 --- a/src/native/managed/Templates/native-lib.static.cmake.in +++ /dev/null @@ -1,7 +0,0 @@ -set(${libCmakeName}_MODE "STATIC") -set(${libCmakeName}_NAME "${libArtifactName}") -set(${libCmakeName}_EXT "${libArtifactExt}") -set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") -set(NATIVEAOT_FRAMEWORK_PATH "${libArtifactNativeAotFrameworkPath}") -set(NATIVEAOT_SDK_PATH "${libArtifactNativeAotSdkPath}") -set(${libCmakeName}_INCLUDE "${libArtifactIncludePath}") diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 8f843bbc9f1c4..1baf03c399d5d 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -2,7 +2,7 @@ Release - + shared diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index e7d47998c9d0a..3dd2f99e84b89 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -16,7 +16,7 @@ - $(MSBuildThisFileDirectory)Templates/native-lib.shared.cmake.in - $(MSBuildThisFileDirectory)Templates/native-lib.static.cmake.in $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in + + + - - - $(IlcFrameworkPath.TrimEnd('\/')) - $(IlcSdkPath.TrimEnd('\/')) - - - - $(NativeLibraryArtifactIlcFrameworkPath.Replace('\', '/')) - $(NativeLibraryArtifactIlcSdkPath.Replace('\', '/')) - - - - - - - From 5a4be9a98317c0f844918a8a830e646b90bdf872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Thu, 22 Feb 2024 16:45:22 -0500 Subject: [PATCH 51/84] use _IsPublishing for the publish target Co-authored-by: Jeremy Koritzinsky --- src/native/managed/compile-native.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 1baf03c399d5d..2350b92a509b8 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -46,7 +46,7 @@ From 7ecdca034c3d88b0fb8ca0c01adf6bbef6b83fd9 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 16:47:55 -0500 Subject: [PATCH 52/84] set MSBuildRestoreSessionId when restoring --- src/native/managed/compile-native.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 2350b92a509b8..366ce62131afb 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -40,7 +40,7 @@ From 238ee10648c920706660c247ec7feb657623e9bb Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 18:48:07 -0500 Subject: [PATCH 53/84] rename property to CLR_IMPORTED_COPY_TARGET use it to decide whether we will have special strip logic --- eng/native/functions.cmake | 16 ++++++---------- eng/native/import-nativeaot-library.cmake | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 5187b8453096d..8c0f81b87bd41 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -407,13 +407,15 @@ function(strip_symbols targetName outputFilename) get_symbol_file_name(${targetName} strip_destination_file) set(${outputFilename} ${strip_destination_file} PARENT_SCOPE) if (CLR_CMAKE_HOST_UNIX) - get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) - if (NOT "${targetImportedNativeAotLib}") + get_property(copy_target TARGET ${targetName} PROPERTY CLR_IMPORTED_COPY_TARGET) + if (NOT "${copy_target}") + # normal target, we will add the post-build event to it set(strip_source_file $) + set(post_build_target "${targetName}") else() + # for an imported library, we will add the post-build event on the copy target get_property(strip_source_file TARGET ${targetName} PROPERTY IMPORTED_LOCATION) - # for an imported library, we will hang the post-build event on the copy target - get_property(copy_target TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY_COPY_TARGET) + set(post_build_target "${copy_target}") endif() if (CLR_CMAKE_TARGET_APPLE) @@ -465,12 +467,6 @@ function(strip_symbols targetName outputFilename) ) else (CLR_CMAKE_TARGET_APPLE) - if (NOT "${targetImportedNativeAotLib}") - set(post_build_target "${targetName}") - else() - set(post_build_target "${copy_target}") - endif() - add_custom_command( TARGET ${post_build_target} POST_BUILD diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index d548c4977c7fd..05088902c0434 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -58,7 +58,7 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) add_dependencies(${targetName} "${copy_target_name}") set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${importedFullPath}") set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) - set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY_COPY_TARGET "${copy_target_name}") + set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_COPY_TARGET "${copy_target_name}") if("${CLR_CMAKE_HOST_WIN32}") set_property(TARGET ${targetName} PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") From d7a57b836ba7c15706856ffb28c883f8263792cb Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 22 Feb 2024 19:31:33 -0500 Subject: [PATCH 54/84] add a general purpose add_imported_library_clr cmake function it always strips and copies the symbols. use it to implement add_imported_nativeaot_library --- eng/native/functions.cmake | 102 +++++++++++++++++----- eng/native/import-nativeaot-library.cmake | 32 +------ 2 files changed, 82 insertions(+), 52 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 8c0f81b87bd41..eccb2912e6798 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -366,9 +366,78 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix) PROPERTIES GENERATED TRUE) endfunction() -function (get_symbol_file_name targetName outputSymbolFilename) - get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) - if (NOT "${targetImportedNativeAotLib}") +define_property(TARGET PROPERTY CLR_IMPORTED_COPY_TARGET + BRIEF_DOCS "set to the COPY_TARGET option that was used to define the target using add_imported_library_clr" + FULL_DOCS "set to the COPY_TARGET option that was used to define the target using add_imported_library_clr" + "Since imported targets don't have build events, the COPY_TARGET's POST_BUILD event can be used instead") + +# add_imported_library_clr(targetName COPY_TARGET copyTargetName IMPORTED_LOCATION importLocation) +# +# same as add_library(targetName SHARED IMPORTED GLOBAL) but it will first copy the library from +# importLocation into our build tree using the target copyTargetName. We do this so that we can +# strip the symbols from the library and place them into a separate symbol file. +# +# Incidentally this also makes cmake dependency analysis work correctly: if the imported library +# changes (for example, if it is built during an earlier stage of our build that cmake can't see, +# the dependencies of targetName will be rebuilt) +function(add_imported_library_clr targetName) + set(options) + set(oneValueArgs COPY_TARGET IMPORTED_LOCATION) + set(multiValueArgs) + cmake_parse_arguments(PARSE_ARGV 1 opt "${options}" "${oneValueArgs}" "${multiValueArgs}") + if ("${opt_COPY_TARGET}" STREQUAL "" OR "${opt_KEYWORDS_MISSING_VALUES}" MATCHES "COPY_TARGET") + message(FATAL_ERROR "add_imported_library_clr requires COPY_TARGET option") + endif() + if ("${opt_IMPORTED_LOCATION}" STREQUAL "" OR "${opt_KEYWORDS_MISSING_VALUES}" MATCHES "IMPORTED_LOCATION") + message(FATAL_ERROR "add_imported_library_clr requires IMPORTED_LOCATION option") + endif() + if (NOT "${opt_UNPARSED_ARGUMENTS}" STREQUAL "") + message(FATAL_ERROR "add_imported_library_clr called with unrecognized options ${opt_UNPARSED_ARGUMENTS}") + endif() + + # Copy the imported library into our binary dir. + # We do this so that we may strip it and also so that cmake dependency tracking will be aware if the file changes + + set(src "${opt_IMPORTED_LOCATION}") + cmake_path(GET src FILENAME srcFilename) + + # for namespaced targets replace :: by _ - otherwise the make generator produces a Makefile rule that make doesn't like + string(REPLACE "::" "_" destSubdir "${targetName}") + set(dest "${CMAKE_CURRENT_BINARY_DIR}/imported_library/${destSubdir}/${srcFilename}") + + add_custom_command(OUTPUT "${dest}" + DEPENDS "${src}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${src}" "${dest}" + ) + + if (CLR_CMAKE_HOST_WIN32) + cmake_path(REPLACE_EXTENSION opt_IMPORTED_LOCATION ".pdb" OUTPUT_VARIABLE srcPdb) + cmake_path(GET srcPdb FILENAME srcPdbFilename) + set(destPdb "${CMAKE_CURRENT_BINARY_DIR}/imported_library/${destSubdir}/${srcPdbFilename}") + + add_custom_command(OUTPUT "${destPdb}" + DEPENDS "${srcPdb}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${srcPdb}" "${destPdb}" + ) + endif() + + if (CLR_CMAKE_HOST_WIN32) + add_custom_target("${opt_COPY_TARGET}" DEPENDS "${dest}" "${destPdb}") + else() + add_custom_target("${opt_COPY_TARGET}" DEPENDS "${dest}") + endif() + + add_library(${targetName} SHARED IMPORTED GLOBAL) + add_dependencies(${targetName} "${opt_COPY_TARGET}") + set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${dest}") + set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_COPY_TARGET "${opt_COPY_TARGET}") + + strip_symbols(${targetName} symbolFile) +endfunction() + +function(get_symbol_file_name targetName outputSymbolFilename) + get_target_property(importedCopyTarget "${targetName}" CLR_IMPORTED_COPY_TARGET) # see add_imported_library_clr + if ("${importedCopyTarget}" STREQUAL "importedCopyTarget-NOTFOUND") if (CLR_CMAKE_HOST_UNIX) if (CLR_CMAKE_TARGET_APPLE) set(strip_destination_file $.dwarf) @@ -383,7 +452,7 @@ function (get_symbol_file_name targetName outputSymbolFilename) set(${outputSymbolFilename} $/$$.pdb PARENT_SCOPE) endif() else() - get_property(libraryType TARGET ${targetName} PROPERTY TYPE) + get_target_property(libraryType "${targetName}" TYPE) message(TRACE "Target ${targetName} is imported of type ${libraryType}") if ("${libraryType}" STREQUAL "SHARED_LIBRARY") get_property(importedLocation TARGET ${targetName} PROPERTY IMPORTED_LOCATION) @@ -407,8 +476,8 @@ function(strip_symbols targetName outputFilename) get_symbol_file_name(${targetName} strip_destination_file) set(${outputFilename} ${strip_destination_file} PARENT_SCOPE) if (CLR_CMAKE_HOST_UNIX) - get_property(copy_target TARGET ${targetName} PROPERTY CLR_IMPORTED_COPY_TARGET) - if (NOT "${copy_target}") + get_target_property(copy_target "${targetName}" CLR_IMPORTED_COPY_TARGET) + if ("${copy_target}" STREQUAL "copy_target-NOTFOUND") # normal target, we will add the post-build event to it set(strip_source_file $) set(post_build_target "${targetName}") @@ -451,12 +520,6 @@ function(strip_symbols targetName outputFilename) list(APPEND DSYMUTIL_OPTS "--minimize") endif () - if (NOT "${targetImportedNativeAotLib}") - set(post_build_target "${targetName}") - else() - set(post_build_target "${copy_target}") - endif() - add_custom_command( TARGET ${post_build_target} POST_BUILD @@ -569,7 +632,7 @@ function(install_clr) endif() add_dependencies(${INSTALL_CLR_COMPONENT} ${targetName}) endif() - get_target_property(targetImportedNativeAotLib "${targetName}" CLR_IMPORTED_NATIVEAOT_LIBRARY) + get_property(hasCopyTarget TARGET "${targetName}" PROPERTY CLR_IMPORTED_COPY_TARGET SET) get_target_property(targetType "${targetName}" TYPE) if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY") get_symbol_file_name(${targetName} symbolFile) @@ -578,22 +641,19 @@ function(install_clr) foreach(destination ${destinations}) # We don't need to install the export libraries for our DLLs # since they won't be directly linked against. - if (NOT "${targetImportedNativeAotLib}") + if (NOT "${hasCopyTarget}") install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - if (NOT "${symbolFile}" STREQUAL "") - install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - endif() elseif("${targetType}" STREQUAL "SHARED_LIBRARY") - #imported shared lib - install the imported artifacts + # for shared libraries added with add_imported_library_clr install the imported artifacts if ("${CMAKE_VERSION}" VERSION_LESS "3.21") install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) else() install(IMPORTED_RUNTIME_ARTIFACTS ${targetName} DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) endif() - if (NOT "${symbolFile}" STREQUAL "") - install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - endif() + endif() + if (NOT "${symbolFile}" STREQUAL "") + install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) endif() if(CLR_CMAKE_PGO_INSTRUMENT) diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake index 05088902c0434..35b98d639ac5c 100644 --- a/eng/native/import-nativeaot-library.cmake +++ b/eng/native/import-nativeaot-library.cmake @@ -28,37 +28,10 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) # windows import library set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically /.../artifacts/bin////native/.lib - # Copy the imported library into our binary dir. - # We do this so that we may strip it and also so that cmake dependency tracking will be aware if the file changes - set(importedFullPath "${CMAKE_CURRENT_BINARY_DIR}/imported_nativeaot_library/${targetNameIn}/${libFilename}") - - add_custom_command(OUTPUT "${importedFullPath}" - DEPENDS "${libFullPath}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${libFullPath}" "${importedFullPath}" - ) - - if(CLR_CMAKE_HOST_WIN32) - set(importedPdbFullPath "${CMAKE_CURRENT_BINARY_DIR}/imported_nativeaot_library/${targetNameIn}/${libName}.pdb") - message(STATUS "Copying ${libPdbFullPath} to ${importedPdbFullPath} for ${targetName}") - add_custom_command(OUTPUT "${importedPdbFullPath}" - DEPENDS "${libPdbFullPath}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${libPdbFullPath}" "${importedPdbFullPath}") - endif() - - # now make a custom target that other targets can depend on set(copy_target_name "${targetNameIn}_copy_imported_library") - if(CLR_CMAKE_HOST_WIN32) - add_custom_target("${copy_target_name}" DEPENDS "${importedFullPath}" "${importedPdbFullPath}") - else() - add_custom_target("${copy_target_name}" DEPENDS "${importedFullPath}") - endif() - - add_library(${targetName} SHARED IMPORTED GLOBAL) - add_dependencies(${targetName} "${copy_target_name}") - set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${importedFullPath}") + add_imported_library_clr(${targetName} COPY_TARGET ${copy_target_name} IMPORTED_LOCATION "${libFullPath}") set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) - set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_COPY_TARGET "${copy_target_name}") if("${CLR_CMAKE_HOST_WIN32}") set_property(TARGET ${targetName} PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") @@ -66,9 +39,6 @@ function(add_imported_nativeaot_library targetNameIn symbolPrefix) set(libIncludePath "${${symbolPrefix}_INCLUDE}") target_include_directories(${targetName} INTERFACE "${libIncludePath}") - - strip_symbols(${targetName} symbolFile) - else() message(FATAL_ERROR "${symbolPrefix}_MODE must be SHARED") endif() From 0e05f1773979e1c723cff3b86db25d4030441c63 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 4 Mar 2024 16:29:02 -0500 Subject: [PATCH 55/84] move call to hellomanaged_Hello to CLRDataAccessCreateInstance --- src/coreclr/debug/daccess/daccess.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 89c7f68729f23..40b3b428b30ed 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -67,10 +67,6 @@ BOOL WINAPI DllMain(HANDLE instance, DWORD reason, LPVOID reserved) #endif } -#ifdef HAVE_HELLOMANAGED - hellomanaged_Hello(); -#endif - #ifdef HOST_UNIX int err = PAL_InitializeDLL(); if(err != 0) @@ -7048,6 +7044,11 @@ STDAPI CLRDataAccessCreateInstance(ICLRDataTarget * pLegacyTarget, return E_INVALIDARG; } +#ifdef HAVE_HELLOMANAGED + hellomanaged_Hello(); +#endif + + *pClrDataAccess = NULL; // Create an adapter which implements the new ICorDebugDataTarget interfaces using From 481a77a7e6b13492b9940b3cce5c154b2eca4f23 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 4 Mar 2024 16:29:30 -0500 Subject: [PATCH 56/84] WIP: copy runtime components to final location in native-library.targets --- eng/native/functions.cmake | 4 ++-- .../src/libhellomanaged.csproj | 5 +++++ src/native/managed/native-library.props | 5 +++++ src/native/managed/native-library.targets | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index eccb2912e6798..1eb7d39523c5c 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -407,7 +407,7 @@ function(add_imported_library_clr targetName) add_custom_command(OUTPUT "${dest}" DEPENDS "${src}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${src}" "${dest}" + COMMAND ${CMAKE_COMMAND} -E true "${src}" "${dest}" ) if (CLR_CMAKE_HOST_WIN32) @@ -417,7 +417,7 @@ function(add_imported_library_clr targetName) add_custom_command(OUTPUT "${destPdb}" DEPENDS "${srcPdb}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${srcPdb}" "${destPdb}" + COMMAND ${CMAKE_COMMAND} -E true "${srcPdb}" "${destPdb}" ) endif() diff --git a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj index be6fb74310879..46b5da489a27d 100644 --- a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj @@ -15,6 +15,11 @@ + + + + + diff --git a/src/native/managed/native-library.props b/src/native/managed/native-library.props index 7f2c29b70e9d2..b456d64353169 100644 --- a/src/native/managed/native-library.props +++ b/src/native/managed/native-library.props @@ -11,6 +11,11 @@ @rpath/$(MSBuildProjectName).dylib + + + true + + diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 3dd2f99e84b89..c49d7c8ac84a8 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -81,4 +81,23 @@ + + + + + + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', '$(RuntimeFlavor.ToLower())', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfiguration)')) + + + + <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDest.Identity)'))" /> + + + + + + + From de1114b0569789043d92714677c4ef0ec3cec15f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:11:40 -0500 Subject: [PATCH 57/84] add ::libs and ::headers imported lib targets do not do any copying in cmake --- src/coreclr/debug/daccess/CMakeLists.txt | 4 +--- .../native-lib.find_package-config.cmake.in | 12 ++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index 08ede628675f9..3e0dae999f7cb 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -44,10 +44,8 @@ set_target_properties(daccess PROPERTIES DAC_COMPONENT TRUE) target_precompile_headers(daccess PRIVATE [["stdafx.h"]]) if("${libhellomanaged_FOUND}") - target_link_libraries(daccess PRIVATE libhellomanaged::libhellomanaged) + target_link_libraries(daccess PRIVATE libhellomanaged::libs libhellomanaged::headers) target_compile_definitions(daccess PRIVATE HAVE_LIBHELLOMANAGED) - # FIXME: can we put this with mscordaccore instead? - install_clr(TARGETS libhellomanaged::libhellomanaged DESTINATIONS . sharedFramework COMPONENT debug) endif() add_dependencies(daccess eventing_headers) diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in index 8c71ccfc0c645..f5ca9847db711 100644 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -1,10 +1,14 @@ # This is a Config-style package configuration file for cmake's find_package command for ${libArtifactName} set(CMAKE_FRAGMENT_PATH "${libArtifactConfigFragment}") -include("`${CLR_ENG_NATIVE_DIR}/import-nativeaot-library.cmake") - include("`${CMAKE_FRAGMENT_PATH}") -# adds a ${libArtifactName}::${libArtifactName} target -add_imported_nativeaot_library("${libArtifactName}" "${libCmakeName}" NAMESPACE "${libArtifactName}::") +# add a ${libArtifactName}::libs target +add_library("${libArtifactName}::libs" SHARED IMPORTED GLOBAL) +set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${${libCMakeName}_LIBPATH}/`${${libCmakeName}_NAME}`${${libCmakeName}_EXT}") +if("`${CLR_CMAKE_HOST_WIN32}") + set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${${libCmakeName}_IMPLIBPATH}") +endif() +add_library("${libArtifactName}::headers" INTERFACE IMPORTED GLOBAL) +target_include_directories("${libArtifactName}::headers" INTERFACE "`${${libCmakeName}_INCLUDE}") From 0d21d2e087c6bcd6d929f2bae200f3ef4fb4f4d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:13:43 -0500 Subject: [PATCH 58/84] remove unused var --- eng/native/functions.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 1eb7d39523c5c..f706562be5e85 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -789,6 +789,5 @@ function(find_nativeaot_library libraryName) find_package(${libraryName} CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") endif() set("${libraryName}_FOUND" "${${libraryName}_FOUND}" PARENT_SCOPE) - set("${libCmakeName}_CMAKE_FRAGMENT_PATH") endfunction() From 7c409be49d4a38ece0ea884fb18ccff61515e740 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:29:20 -0500 Subject: [PATCH 59/84] add TODOs for new approach --- src/native/managed/native-library.targets | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index c49d7c8ac84a8..c4d76871e23c7 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -81,7 +81,13 @@ - + + + + @@ -89,6 +95,8 @@ $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', '$(RuntimeFlavor.ToLower())', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfiguration)')) + + <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDest.Identity)'))" /> @@ -100,4 +108,5 @@ SkipUnchangedFiles="true" /> + From 2b0850a5e1a27117c111200901e671fe8d37b057 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:29:35 -0500 Subject: [PATCH 60/84] remove import-nativeaot-library.cmake --- eng/native/import-nativeaot-library.cmake | 45 ----------------------- 1 file changed, 45 deletions(-) delete mode 100644 eng/native/import-nativeaot-library.cmake diff --git a/eng/native/import-nativeaot-library.cmake b/eng/native/import-nativeaot-library.cmake deleted file mode 100644 index 35b98d639ac5c..0000000000000 --- a/eng/native/import-nativeaot-library.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# Infrastructure to import a native aot compiled library into a native build - -# ## Implementation details used by libraryName-config.cmake find_package configuration -# ## files. Consumers don't need to do this directly. - -# add_imported_nativeaot_library(targetName symbolPrefix [NAMESPACE namespace]) -# -# adds a target targetName that can be used to reference a NativeAOTed library. symbolPrefix should -# be the ALLCAPS prefix of the variables that define the mode and paths for the library. They are -# typically set in the artifacts/obj/targetName/targetName.cmake fragment which should be included -# before calling this function. -function(add_imported_nativeaot_library targetNameIn symbolPrefix) - cmake_parse_arguments(PARSE_ARGV 2 "add_imported_opt" "" "NAMESPACE" "") - message(TRACE "${symbolPrefix}_MODE is ${${symbolPrefix}_MODE}") - set(targetName "${add_imported_opt_NAMESPACE}${targetNameIn}") - message(TRACE "Adding target ${targetName}") - - if("${${symbolPrefix}_MODE}" STREQUAL "SHARED") - set(libName "${${symbolPrefix}_NAME}") # typically same as targetName - set(libPath "${${symbolPrefix}_LIBPATH}") # typically /.../artifacts/bin////publish - set(libFilename "${libName}${${symbolPrefix}_EXT}") # .dll, .so or .dylib - set(libFullPath "${libPath}/${libFilename}") - - if(CLR_CMAKE_HOST_WIN32) - set(libPdbFullPath "${libPath}/${libName}.pdb") - endif() - - # windows import library - set(libImpLibFullPath "${${symbolPrefix}_IMPLIBPATH}") # typically /.../artifacts/bin////native/.lib - - set(copy_target_name "${targetNameIn}_copy_imported_library") - - add_imported_library_clr(${targetName} COPY_TARGET ${copy_target_name} IMPORTED_LOCATION "${libFullPath}") - set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_NATIVEAOT_LIBRARY 1) - - if("${CLR_CMAKE_HOST_WIN32}") - set_property(TARGET ${targetName} PROPERTY IMPORTED_IMPLIB "${libImpLibFullPath}") - endif() - - set(libIncludePath "${${symbolPrefix}_INCLUDE}") - target_include_directories(${targetName} INTERFACE "${libIncludePath}") - else() - message(FATAL_ERROR "${symbolPrefix}_MODE must be SHARED") - endif() -endfunction() From 6dad61e76ca5ca9d9338de01ba00b58fa8b1c25a Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:29:52 -0500 Subject: [PATCH 61/84] remove add_imported_library_clr cmake function --- eng/native/functions.cmake | 71 -------------------------------------- 1 file changed, 71 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index f706562be5e85..101345a0fc94b 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -366,75 +366,6 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix) PROPERTIES GENERATED TRUE) endfunction() -define_property(TARGET PROPERTY CLR_IMPORTED_COPY_TARGET - BRIEF_DOCS "set to the COPY_TARGET option that was used to define the target using add_imported_library_clr" - FULL_DOCS "set to the COPY_TARGET option that was used to define the target using add_imported_library_clr" - "Since imported targets don't have build events, the COPY_TARGET's POST_BUILD event can be used instead") - -# add_imported_library_clr(targetName COPY_TARGET copyTargetName IMPORTED_LOCATION importLocation) -# -# same as add_library(targetName SHARED IMPORTED GLOBAL) but it will first copy the library from -# importLocation into our build tree using the target copyTargetName. We do this so that we can -# strip the symbols from the library and place them into a separate symbol file. -# -# Incidentally this also makes cmake dependency analysis work correctly: if the imported library -# changes (for example, if it is built during an earlier stage of our build that cmake can't see, -# the dependencies of targetName will be rebuilt) -function(add_imported_library_clr targetName) - set(options) - set(oneValueArgs COPY_TARGET IMPORTED_LOCATION) - set(multiValueArgs) - cmake_parse_arguments(PARSE_ARGV 1 opt "${options}" "${oneValueArgs}" "${multiValueArgs}") - if ("${opt_COPY_TARGET}" STREQUAL "" OR "${opt_KEYWORDS_MISSING_VALUES}" MATCHES "COPY_TARGET") - message(FATAL_ERROR "add_imported_library_clr requires COPY_TARGET option") - endif() - if ("${opt_IMPORTED_LOCATION}" STREQUAL "" OR "${opt_KEYWORDS_MISSING_VALUES}" MATCHES "IMPORTED_LOCATION") - message(FATAL_ERROR "add_imported_library_clr requires IMPORTED_LOCATION option") - endif() - if (NOT "${opt_UNPARSED_ARGUMENTS}" STREQUAL "") - message(FATAL_ERROR "add_imported_library_clr called with unrecognized options ${opt_UNPARSED_ARGUMENTS}") - endif() - - # Copy the imported library into our binary dir. - # We do this so that we may strip it and also so that cmake dependency tracking will be aware if the file changes - - set(src "${opt_IMPORTED_LOCATION}") - cmake_path(GET src FILENAME srcFilename) - - # for namespaced targets replace :: by _ - otherwise the make generator produces a Makefile rule that make doesn't like - string(REPLACE "::" "_" destSubdir "${targetName}") - set(dest "${CMAKE_CURRENT_BINARY_DIR}/imported_library/${destSubdir}/${srcFilename}") - - add_custom_command(OUTPUT "${dest}" - DEPENDS "${src}" - COMMAND ${CMAKE_COMMAND} -E true "${src}" "${dest}" - ) - - if (CLR_CMAKE_HOST_WIN32) - cmake_path(REPLACE_EXTENSION opt_IMPORTED_LOCATION ".pdb" OUTPUT_VARIABLE srcPdb) - cmake_path(GET srcPdb FILENAME srcPdbFilename) - set(destPdb "${CMAKE_CURRENT_BINARY_DIR}/imported_library/${destSubdir}/${srcPdbFilename}") - - add_custom_command(OUTPUT "${destPdb}" - DEPENDS "${srcPdb}" - COMMAND ${CMAKE_COMMAND} -E true "${srcPdb}" "${destPdb}" - ) - endif() - - if (CLR_CMAKE_HOST_WIN32) - add_custom_target("${opt_COPY_TARGET}" DEPENDS "${dest}" "${destPdb}") - else() - add_custom_target("${opt_COPY_TARGET}" DEPENDS "${dest}") - endif() - - add_library(${targetName} SHARED IMPORTED GLOBAL) - add_dependencies(${targetName} "${opt_COPY_TARGET}") - set_property(TARGET ${targetName} PROPERTY IMPORTED_LOCATION "${dest}") - set_property(TARGET ${targetName} PROPERTY CLR_IMPORTED_COPY_TARGET "${opt_COPY_TARGET}") - - strip_symbols(${targetName} symbolFile) -endfunction() - function(get_symbol_file_name targetName outputSymbolFilename) get_target_property(importedCopyTarget "${targetName}" CLR_IMPORTED_COPY_TARGET) # see add_imported_library_clr if ("${importedCopyTarget}" STREQUAL "importedCopyTarget-NOTFOUND") @@ -779,8 +710,6 @@ endfunction() # If the library is found, sets libraryName_FOUND to true, else false. # If the library is found, a target libraryName::libraryName is defined. # If REQUIRED is specified, it's a fatal error not to find the library, otherwise the library is considered optional. -# -# For implementation details see import-nativeaot-library.cmake function(find_nativeaot_library libraryName) cmake_parse_arguments(PARSE_ARGV 1 "findNativeAOT_opt" "REQUIRED" "" "") if (NOT "${findNativeAOT_opt_REQUIRED}") From e075acdd8c731ea4d4f9a00b2b75e2f10e4b1655 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:31:32 -0500 Subject: [PATCH 62/84] revert cmake changes for imported libs remove the special install_clr and strip_symbols handling for imported libraries --- eng/native/functions.cmake | 77 +++++++++----------------------------- 1 file changed, 18 insertions(+), 59 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 101345a0fc94b..aec267d705a5b 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -366,40 +366,19 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix) PROPERTIES GENERATED TRUE) endfunction() -function(get_symbol_file_name targetName outputSymbolFilename) - get_target_property(importedCopyTarget "${targetName}" CLR_IMPORTED_COPY_TARGET) # see add_imported_library_clr - if ("${importedCopyTarget}" STREQUAL "importedCopyTarget-NOTFOUND") - if (CLR_CMAKE_HOST_UNIX) - if (CLR_CMAKE_TARGET_APPLE) - set(strip_destination_file $.dwarf) - else () - set(strip_destination_file $.dbg) - endif () - - set(${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE) - elseif(CLR_CMAKE_HOST_WIN32) - # We can't use the $ generator expression here since - # the generator expression isn't supported on resource DLLs. - set(${outputSymbolFilename} $/$$.pdb PARENT_SCOPE) - endif() - else() - get_target_property(libraryType "${targetName}" TYPE) - message(TRACE "Target ${targetName} is imported of type ${libraryType}") - if ("${libraryType}" STREQUAL "SHARED_LIBRARY") - get_property(importedLocation TARGET ${targetName} PROPERTY IMPORTED_LOCATION) - message(TRACE "Target ${targetName} is imported from ${importedLocation}") - if (CLR_CMAKE_HOST_UNIX) - if (CLR_CMAKE_TARGET_APPLE) - set(importedLocation "${importedLocation}.dwarf") - else() - set(importedLocation "${importedLocation}.dbg") - endif() - elseif(CLR_CMAKE_HOST_WIN32) - cmake_path(REPLACE_EXTENSION importedLocation ".pdb") - endif() - set(${outputSymbolFilename} "${importedLocation}" PARENT_SCOPE) - message(TRACE "Target ${targetName} symbols will be in ${importedLocation}") - endif() +function (get_symbol_file_name targetName outputSymbolFilename) + if (CLR_CMAKE_HOST_UNIX) + if (CLR_CMAKE_TARGET_APPLE) + set(strip_destination_file $.dwarf) + else () + set(strip_destination_file $.dbg) + endif () + + set(${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE) + elseif(CLR_CMAKE_HOST_WIN32) + # We can't use the $ generator expression here since + # the generator expression isn't supported on resource DLLs. + set(${outputSymbolFilename} $/$$.pdb PARENT_SCOPE) endif() endfunction() @@ -407,16 +386,7 @@ function(strip_symbols targetName outputFilename) get_symbol_file_name(${targetName} strip_destination_file) set(${outputFilename} ${strip_destination_file} PARENT_SCOPE) if (CLR_CMAKE_HOST_UNIX) - get_target_property(copy_target "${targetName}" CLR_IMPORTED_COPY_TARGET) - if ("${copy_target}" STREQUAL "copy_target-NOTFOUND") - # normal target, we will add the post-build event to it - set(strip_source_file $) - set(post_build_target "${targetName}") - else() - # for an imported library, we will add the post-build event on the copy target - get_property(strip_source_file TARGET ${targetName} PROPERTY IMPORTED_LOCATION) - set(post_build_target "${copy_target}") - endif() + set(strip_source_file $) if (CLR_CMAKE_TARGET_APPLE) @@ -452,7 +422,7 @@ function(strip_symbols targetName outputFilename) endif () add_custom_command( - TARGET ${post_build_target} + TARGET ${targetName} POST_BUILD VERBATIM COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" @@ -462,7 +432,7 @@ function(strip_symbols targetName outputFilename) else (CLR_CMAKE_TARGET_APPLE) add_custom_command( - TARGET ${post_build_target} + TARGET ${targetName} POST_BUILD VERBATIM COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" @@ -563,8 +533,7 @@ function(install_clr) endif() add_dependencies(${INSTALL_CLR_COMPONENT} ${targetName}) endif() - get_property(hasCopyTarget TARGET "${targetName}" PROPERTY CLR_IMPORTED_COPY_TARGET SET) - get_target_property(targetType "${targetName}" TYPE) + get_target_property(targetType ${targetName} TYPE) if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC_LIBRARY") get_symbol_file_name(${targetName} symbolFile) endif() @@ -572,17 +541,7 @@ function(install_clr) foreach(destination ${destinations}) # We don't need to install the export libraries for our DLLs # since they won't be directly linked against. - if (NOT "${hasCopyTarget}") - install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - elseif("${targetType}" STREQUAL "SHARED_LIBRARY") - # for shared libraries added with add_imported_library_clr install the imported artifacts - - if ("${CMAKE_VERSION}" VERSION_LESS "3.21") - install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - else() - install(IMPORTED_RUNTIME_ARTIFACTS ${targetName} DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) - endif() - endif() + install(PROGRAMS $ DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) if (NOT "${symbolFile}" STREQUAL "") install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT}) endif() From ce1c1c74744c499868c83f673e0bdb92e1db7b98 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:37:33 -0500 Subject: [PATCH 63/84] update README --- src/native/managed/README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/native/managed/README.md b/src/native/managed/README.md index 7b8e89390187f..e4bcebf9a7593 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -12,9 +12,9 @@ find_nativeaot_library(libWhatever REQUIRED) This will look for a cmake fragment file in `artifacts/obj/cmake/find_package/libWhatever-config.cmake` that will import some variables from -`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libWhatever` that can -be used as a dependency in `target_link_libraries()` or in a `install_clr()` command. - +`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs` and +`libWhatever::headers` targets that can be used as dependencies in `target_link_libraries()` +properties. ## Adding a new managed library @@ -32,6 +32,13 @@ item group. In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: 1. Near the top, add `` 2. Near the bottom, add `` +3. Define an item `@InstallRuntimeComponentDest` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: + ```xml + + + + + ``` The following is recommended: From 7eff8e6e29e950294586ff1eacf4a2dd6d75d5ea Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:42:26 -0500 Subject: [PATCH 64/84] just emit one cmake file --- .../native-lib.find_package-config.cmake.in | 8 ++++++-- .../managed/Templates/native-lib.shared.cmake.in | 6 ------ src/native/managed/native-library.targets | 12 +----------- 3 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 src/native/managed/Templates/native-lib.shared.cmake.in diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in index f5ca9847db711..28a6e9bc9a304 100644 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -1,7 +1,11 @@ # This is a Config-style package configuration file for cmake's find_package command for ${libArtifactName} -set(CMAKE_FRAGMENT_PATH "${libArtifactConfigFragment}") -include("`${CMAKE_FRAGMENT_PATH}") +set(${libCmakeName}_MODE "SHARED") +set(${libCmakeName}_NAME "${libArtifactName}") +set(${libCmakeName}_EXT "${libArtifactExt}") +set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") +set(${libCmakeName}_IMPLIBPATH "${libArtifactImpLibFullPath}") +set(${libCmakeName}_INCLUDE "${libArtifactIncludePath}") # add a ${libArtifactName}::libs target add_library("${libArtifactName}::libs" SHARED IMPORTED GLOBAL) diff --git a/src/native/managed/Templates/native-lib.shared.cmake.in b/src/native/managed/Templates/native-lib.shared.cmake.in deleted file mode 100644 index 27cfb7e7c19a8..0000000000000 --- a/src/native/managed/Templates/native-lib.shared.cmake.in +++ /dev/null @@ -1,6 +0,0 @@ -set(${libCmakeName}_MODE "SHARED") -set(${libCmakeName}_NAME "${libArtifactName}") -set(${libCmakeName}_EXT "${libArtifactExt}") -set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") -set(${libCmakeName}_IMPLIBPATH "${libArtifactImpLibFullPath}") -set(${libCmakeName}_INCLUDE "${libArtifactIncludePath}") diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index c4d76871e23c7..2e0ff6fdfed8d 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -17,22 +17,17 @@ + Outputs="$(NativeLibraryCMakeFindPackageConfigPath)"> - $(MSBuildThisFileDirectory)Templates/native-lib.shared.cmake.in $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in - $(TargetName.ToUpper()) - $(ArtifactsObjDir)$(TargetName)\$(TargetName).cmake $(TargetName) $(NativeLibraryCMakeFindPackageConfigOutputPath)$(NativeLibraryArtifactName)-config.cmake $(NativeBinaryExt) @@ -52,9 +46,6 @@ @(NativeLibraryCmakeFragmentIncludePath, ';') $(NativeLibraryArtifactIncludePath.Replace('\', '/')) - - $(NativeLibraryCMakeFragmentPath.Replace('\', '/')) - $(NativeLibraryCMakeFragmentPath) @@ -62,7 +53,6 @@ - From 182df7a8833ac1453597b49f6a3780066449570c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 14:47:14 -0500 Subject: [PATCH 65/84] simplify the cmake template --- .../native-lib.find_package-config.cmake.in | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in index 28a6e9bc9a304..0050e8dd925b5 100644 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -1,18 +1,17 @@ # This is a Config-style package configuration file for cmake's find_package command for ${libArtifactName} -set(${libCmakeName}_MODE "SHARED") -set(${libCmakeName}_NAME "${libArtifactName}") -set(${libCmakeName}_EXT "${libArtifactExt}") -set(${libCmakeName}_LIBPATH "${libArtifactLibPath}") -set(${libCmakeName}_IMPLIBPATH "${libArtifactImpLibFullPath}") -set(${libCmakeName}_INCLUDE "${libArtifactIncludePath}") +set(MODE "SHARED") +set(NAME "${libArtifactName}") +set(EXT "${libArtifactExt}") +set(LIBBASEPATH "${libArtifactLibPath}") +set(IMPLIBPATH "${libArtifactImpLibFullPath}") +set(INCLUDE_DIRS "${libArtifactIncludePath}") -# add a ${libArtifactName}::libs target -add_library("${libArtifactName}::libs" SHARED IMPORTED GLOBAL) -set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${${libCMakeName}_LIBPATH}/`${${libCmakeName}_NAME}`${${libCmakeName}_EXT}") -if("`${CLR_CMAKE_HOST_WIN32}") - set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${${libCmakeName}_IMPLIBPATH}") +add_library("${libArtifactName}::libs" "`${MODE}" IMPORTED GLOBAL) +set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${LIBBASEPATH}/`${NAME}`${EXT}") +if("`${CLR_CMAKE_HOST_WIN32}" AND "`${MODE}" STREQUAL "SHARED") + set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${IMPLIBPATH}") endif() add_library("${libArtifactName}::headers" INTERFACE IMPORTED GLOBAL) -target_include_directories("${libArtifactName}::headers" INTERFACE "`${${libCmakeName}_INCLUDE}") +target_include_directories("${libArtifactName}::headers" INTERFACE "`${INCLUDE_DIRS}") From 8eb8e36a3b8dc9de372deee62a89affeffed001d Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 16:13:55 -0500 Subject: [PATCH 66/84] rename some cmake vars --- .../Templates/native-lib.find_package-config.cmake.in | 2 +- src/native/managed/native-library.targets | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in index 0050e8dd925b5..847d84a503ec3 100644 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -3,7 +3,7 @@ set(MODE "SHARED") set(NAME "${libArtifactName}") set(EXT "${libArtifactExt}") -set(LIBBASEPATH "${libArtifactLibPath}") +set(LIBBASEPATH "${libArtifactLibBasePath}") set(IMPLIBPATH "${libArtifactImpLibFullPath}") set(INCLUDE_DIRS "${libArtifactIncludePath}") diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 2e0ff6fdfed8d..42f88649cc193 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -36,22 +36,20 @@ - $(TargetName.ToUpper()) $(TargetName) $(NativeLibraryCMakeFindPackageConfigOutputPath)$(NativeLibraryArtifactName)-config.cmake $(NativeBinaryExt) - $(PublishDir)/ + $(PublishDir)/ - $(NativeLibraryArtifactLibPath.Replace('\', '/')) + $(NativeLibraryArtifactLibBasePath.Replace('\', '/')) @(NativeLibraryCmakeFragmentIncludePath, ';') $(NativeLibraryArtifactIncludePath.Replace('\', '/')) - - + From dd50ff03ca1c72342cdbdd645c796f96e5246f5e Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 16:14:08 -0500 Subject: [PATCH 67/84] strip nativeoat-built componentlike coreclr does on mac/linux windows remains to be done --- src/native/managed/native-library.targets | 60 ++++++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 42f88649cc193..f9127bf6a0261 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -73,9 +73,50 @@ - on mac, leave a .dylib.dwarf file next to the library. - on linux leave a .so.dbg file next to to the library --> - + + + $(OutputPath)stripped\ + $(StrippedOutputPath)$(TargetName)$(NativeBinaryExt) + .dylib.dwarf + .so.dbg + $(StrippedOutputPath)$(TargetName)$(StrippedExt) + + + + + + + + + + + + + <_StripLike Condition="'$(TargetsOSX)' == 'true' or '$(TargetsAppleMobile)' == 'true'">apple + <_StripLike Condition="'$(_StripLike)' == ''">gnu + + + + + + + + + + + - + @@ -83,17 +124,22 @@ $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', '$(RuntimeFlavor.ToLower())', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfiguration)')) - - <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDest.Identity)'))" /> - + + + + + + + - + SkipUnchangedFiles="true" + Condition="'$(TargetsWindows)' != 'true'"/> From bdc85a0177683fb8cb3a8052f95acd57f14f3cf5 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 5 Mar 2024 17:29:26 -0500 Subject: [PATCH 68/84] fixup osx and linux builds --- src/native/managed/native-library.targets | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index f9127bf6a0261..597da2570563a 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -86,7 +86,7 @@ @@ -106,12 +106,12 @@ - - + + - - - + + + Date: Tue, 5 Mar 2024 20:17:54 -0500 Subject: [PATCH 69/84] empty commit to trigger build From 003af6a39a5b1258b9e18411bd04c27597d6d67a Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 10:18:05 -0500 Subject: [PATCH 70/84] copy windows PDBs to final install destinations --- src/native/managed/native-library.targets | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 597da2570563a..f973078479007 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -84,7 +84,7 @@ $(StrippedOutputPath)$(TargetName)$(StrippedExt) - + - + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', '$(RuntimeFlavor.ToLower())', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfiguration)')) - + <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDest.Identity)'))" /> - + - + + + + + + + + + Condition="'$(TargetsWindows)' == 'true'"/> From edbbe84559e96f767faee064c051551b2e7958b0 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 10:51:46 -0500 Subject: [PATCH 71/84] DRY --- src/native/managed/compile-native.proj | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 366ce62131afb..7fac3b51f02c5 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -7,46 +7,61 @@ + + false - + false + false true false + $(ROOTFS_DIR) lld --gcc-toolchain=$(ROOTFS_DIR)/usr - $(ExtraProps);SysRoot=$(SysRoot) - $(ExtraProps);LinkerFlavor=$(LinkerFlavor) - $(ExtraProps);CustomLinkerArgToolchainArg=$(CustomLinkerArgToolchainArg) + + + + + + + + + + + + + + + AdditionalProperties="%(AdditionalProperties);@(SubprojectProps->'%(Identity)=%(Value)', ';')"/> - - + + @(SubprojectProps->'%(Identity)=%(Value)', ';') + + - - From adc93143246e4f1ce60b7f4617f786a3989f20e2 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 11:25:54 -0500 Subject: [PATCH 72/84] simplify example --- .../managed/libhellomanaged}/src/HelloManaged.cs | 0 .../libhellomanaged/src/libhellomanaged.csproj | 4 ---- .../Directory.Build.props | 3 --- .../src/Directory.Build.props | 3 --- .../src/Microsoft.DotNet.HelloManaged.csproj | 16 ---------------- 5 files changed, 26 deletions(-) rename src/{tools/Microsoft.DotNet.HelloManaged => native/managed/libhellomanaged}/src/HelloManaged.cs (100%) delete mode 100644 src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props delete mode 100644 src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props delete mode 100644 src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs b/src/native/managed/libhellomanaged/src/HelloManaged.cs similarity index 100% rename from src/tools/Microsoft.DotNet.HelloManaged/src/HelloManaged.cs rename to src/native/managed/libhellomanaged/src/HelloManaged.cs diff --git a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj index 46b5da489a27d..7ad7409b39248 100644 --- a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj +++ b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj @@ -20,10 +20,6 @@ - - - - diff --git a/src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props b/src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props deleted file mode 100644 index aac96214a96d8..0000000000000 --- a/src/tools/Microsoft.DotNet.HelloManaged/Directory.Build.props +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props b/src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props deleted file mode 100644 index 0a801022f17dd..0000000000000 --- a/src/tools/Microsoft.DotNet.HelloManaged/src/Directory.Build.props +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj b/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj deleted file mode 100644 index b90a61572801b..0000000000000 --- a/src/tools/Microsoft.DotNet.HelloManaged/src/Microsoft.DotNet.HelloManaged.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - $(NetCoreAppToolCurrent) - Example managed library that will be included in a NativeAOT compiled binary - true - enable - true - true - true - true - - false - - - From 3a5353b7dc2d711fcfda3ea96b27f9fae8acded1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 11:29:40 -0500 Subject: [PATCH 73/84] fixup comments and docs --- eng/native/functions.cmake | 2 +- src/native/managed/README.md | 14 +++++--------- src/native/managed/native-library.targets | 1 - 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index aec267d705a5b..7be12dbb7814a 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -667,7 +667,7 @@ endfunction() # # Imports a native library produced by NativeAOT (see src/native/managed). # If the library is found, sets libraryName_FOUND to true, else false. -# If the library is found, a target libraryName::libraryName is defined. +# If the library is found, it will provide targets libraryName::libs and libraryName::headers. # If REQUIRED is specified, it's a fatal error not to find the library, otherwise the library is considered optional. function(find_nativeaot_library libraryName) cmake_parse_arguments(PARSE_ARGV 1 "findNativeAOT_opt" "REQUIRED" "" "") diff --git a/src/native/managed/README.md b/src/native/managed/README.md index e4bcebf9a7593..b9940ae962034 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -32,7 +32,7 @@ item group. In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: 1. Near the top, add `` 2. Near the bottom, add `` -3. Define an item `@InstallRuntimeComponentDest` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: +3. Define an item `@(InstallRuntimeComponentDest)` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: ```xml @@ -43,15 +43,11 @@ In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: The following is recommended: 1. The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms. -2. The project should just have a single `EntryPoints.cs` that has a `static class` that provides - `[UnmanagedCallersOnly]` API entrypoints. The bulk of the code should be imported using - `ProjectReference` from another managed class library project. That managed project can be - tested using normal managed unit tests, consumed in other managed libraries, etc. -3. The `inc` directory if it exists will be added to the include path of any cmake targets that +2. The `inc` directory if it exists will be added to the include path of any cmake targets that depend on the native library. Typically the directory should contain a `libMyNewLibrary.h` header - file with a C declaration for each entrypoint. If you want ot have more include directories, add - them all to the `NativeLibraryCmakeFragmentIncludePath` item. In that case `inc` won't be added - by default. + file with a C declaration for each `[UnmanagedCallersOnly]` entrypoint. If you want to have more + include directories, add them all to the `NativeLibraryCmakeFragmentIncludePath` item in your + `.csproj`. In that case `inc` won't be added by default. Limitations: diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index f973078479007..9ff8620c6820f 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -128,7 +128,6 @@ <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDest.Identity)'))" /> - From c7b67513ef391994b3d7374856478c617e40f155 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 11:47:43 -0500 Subject: [PATCH 74/84] cleanup --- src/native/managed/native-library.targets | 39 +++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 9ff8620c6820f..b6fbaa2d39684 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -1,6 +1,6 @@ - + @@ -10,21 +10,26 @@ + + $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in + + $([MSBuild]::NormalizeDirectory('$(ArtifactsObjDir)\cmake\find_package\')) + - - - $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in - @@ -34,7 +39,11 @@ Properties="@(NativeLibraryCmakeFragmentProperties->'%(Identity)=%(Value)')" /> - + + $(TargetName) $(NativeLibraryCMakeFindPackageConfigOutputPath)$(NativeLibraryArtifactName)-config.cmake @@ -46,24 +55,22 @@ @(NativeLibraryCmakeFragmentIncludePath, ';') $(NativeLibraryArtifactIncludePath.Replace('\', '/')) + - - - + + $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(StaticLibSuffix)')) - - - + $(NativeLibraryArtifactImpLibFullPath.Replace('\', '/')) - + @@ -92,7 +99,7 @@ Outputs="$(StripSourceFile);$(StripDestinationFile)"> - + - - + + Date: Wed, 6 Mar 2024 12:34:21 -0500 Subject: [PATCH 75/84] set library name on linux and mac SharedLibraryInstallName only works on mobile apple platforms --- src/native/managed/native-library.props | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/native/managed/native-library.props b/src/native/managed/native-library.props index b456d64353169..c3e9a52368038 100644 --- a/src/native/managed/native-library.props +++ b/src/native/managed/native-library.props @@ -6,10 +6,20 @@ false + - + @rpath/$(MSBuildProjectName).dylib + + + + + + + From 0cc4db438bc4aa3a6f325a0321e53c56c017059e Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 12:59:47 -0500 Subject: [PATCH 76/84] remove example --- src/coreclr/debug/daccess/CMakeLists.txt | 7 ------ src/coreclr/debug/daccess/daccess.cpp | 9 ------- .../Directory.Build.props | 5 ---- src/native/managed/compile-native.proj | 2 +- .../libhellomanaged/inc/libhellomanaged.h | 19 -------------- .../libhellomanaged/src/Entrypoints.cs | 17 ------------- .../libhellomanaged/src/HelloManaged.cs | 13 ---------- .../src/libhellomanaged.csproj | 25 ------------------- 8 files changed, 1 insertion(+), 96 deletions(-) delete mode 100644 src/native/managed/libhellomanaged/inc/libhellomanaged.h delete mode 100644 src/native/managed/libhellomanaged/src/Entrypoints.cs delete mode 100644 src/native/managed/libhellomanaged/src/HelloManaged.cs delete mode 100644 src/native/managed/libhellomanaged/src/libhellomanaged.csproj diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index 3e0dae999f7cb..5332e957c9eca 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -1,7 +1,5 @@ add_definitions(-DFEATURE_NO_HOST) -find_nativeaot_library(libhellomanaged) - include_directories(BEFORE ${VM_DIR}) include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR}) include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}) @@ -43,11 +41,6 @@ add_library_clr(daccess ${DACCESS_SOURCES}) set_target_properties(daccess PROPERTIES DAC_COMPONENT TRUE) target_precompile_headers(daccess PRIVATE [["stdafx.h"]]) -if("${libhellomanaged_FOUND}") - target_link_libraries(daccess PRIVATE libhellomanaged::libs libhellomanaged::headers) - target_compile_definitions(daccess PRIVATE HAVE_LIBHELLOMANAGED) -endif() - add_dependencies(daccess eventing_headers) if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 40b3b428b30ed..e79dab808def3 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -33,10 +33,6 @@ extern "C" bool TryGetSymbol(ICorDebugDataTarget* dataTarget, uint64_t baseAddre #include "dwbucketmanager.hpp" #include "gcinterface.dac.h" -#ifdef HAVE_HELLOMANAGED -#include "libhellomanaged.h" -#endif - // To include definition of IsThrowableThreadAbortException // #include @@ -7044,11 +7040,6 @@ STDAPI CLRDataAccessCreateInstance(ICLRDataTarget * pLegacyTarget, return E_INVALIDARG; } -#ifdef HAVE_HELLOMANAGED - hellomanaged_Hello(); -#endif - - *pClrDataAccess = NULL; // Create an adapter which implements the new ICorDebugDataTarget interfaces using diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index dabe659e60b94..4a1a720cf6a0d 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -120,11 +120,6 @@ - - - - - diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 7fac3b51f02c5..4116e5d9a1940 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -8,7 +8,7 @@ - + diff --git a/src/native/managed/libhellomanaged/inc/libhellomanaged.h b/src/native/managed/libhellomanaged/inc/libhellomanaged.h deleted file mode 100644 index bb9886051cfc8..0000000000000 --- a/src/native/managed/libhellomanaged/inc/libhellomanaged.h +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#ifndef _LIBHELLOMANAGED_H -#define _LIBHELLOMANAGED_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -void -hellomanaged_Hello(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/native/managed/libhellomanaged/src/Entrypoints.cs b/src/native/managed/libhellomanaged/src/Entrypoints.cs deleted file mode 100644 index 98e8e8b067fa3..0000000000000 --- a/src/native/managed/libhellomanaged/src/Entrypoints.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Runtime.InteropServices; - -namespace Microsoft.DotNet.HelloManaged; - -public static class Entrypoints -{ - [UnmanagedCallersOnly(EntryPoint="hellomanaged_Hello")] - public static void Hello() - { - HelloManaged o = new(); - Console.WriteLine ($"Hello {o.GetMagic()}"); - } -} diff --git a/src/native/managed/libhellomanaged/src/HelloManaged.cs b/src/native/managed/libhellomanaged/src/HelloManaged.cs deleted file mode 100644 index 6f57b84c0c5db..0000000000000 --- a/src/native/managed/libhellomanaged/src/HelloManaged.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -namespace Microsoft.DotNet.HelloManaged; - -public class HelloManaged -{ - public HelloManaged() {} - - public ulong GetMagic() => 0x20240222L; -} diff --git a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj b/src/native/managed/libhellomanaged/src/libhellomanaged.csproj deleted file mode 100644 index 7ad7409b39248..0000000000000 --- a/src/native/managed/libhellomanaged/src/libhellomanaged.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - $(NetCoreAppToolCurrent) - Example managed library that will be included in a NativeAOT compiled binary - true - enable - true - true - true - true - - false - - - - - - - - - - - - From 0f90a932a9cdbad8080e2bb465929072d3517487 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 7 Mar 2024 18:44:35 -0500 Subject: [PATCH 77/84] remove support for exporting a header target --- src/native/managed/README.md | 23 +++++++------------ .../native-lib.find_package-config.cmake.in | 3 --- src/native/managed/native-library.targets | 10 -------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/native/managed/README.md b/src/native/managed/README.md index b9940ae962034..d98c1b424777c 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -12,9 +12,8 @@ find_nativeaot_library(libWhatever REQUIRED) This will look for a cmake fragment file in `artifacts/obj/cmake/find_package/libWhatever-config.cmake` that will import some variables from -`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs` and -`libWhatever::headers` targets that can be used as dependencies in `target_link_libraries()` -properties. +`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs`targets that can +be used ins dependencies in `target_link_libraries()` properties. ## Adding a new managed library @@ -40,17 +39,11 @@ In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: ``` -The following is recommended: - -1. The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms. -2. The `inc` directory if it exists will be added to the include path of any cmake targets that - depend on the native library. Typically the directory should contain a `libMyNewLibrary.h` header - file with a C declaration for each `[UnmanagedCallersOnly]` entrypoint. If you want to have more - include directories, add them all to the `NativeLibraryCmakeFragmentIncludePath` item in your - `.csproj`. In that case `inc` won't be added by default. - Limitations: -Currently only shared library output is supported. In principle static linking is possible, but the -infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with static -linking will not be supported on Windows. +* The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on +all platforms. + +* Currently only shared library output is supported. In principle static linking is possible, but +the infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with +static linking will not be supported on Windows. diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in index 847d84a503ec3..4081472d96604 100644 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -5,7 +5,6 @@ set(NAME "${libArtifactName}") set(EXT "${libArtifactExt}") set(LIBBASEPATH "${libArtifactLibBasePath}") set(IMPLIBPATH "${libArtifactImpLibFullPath}") -set(INCLUDE_DIRS "${libArtifactIncludePath}") add_library("${libArtifactName}::libs" "`${MODE}" IMPORTED GLOBAL) set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${LIBBASEPATH}/`${NAME}`${EXT}") @@ -13,5 +12,3 @@ if("`${CLR_CMAKE_HOST_WIN32}" AND "`${MODE}" STREQUAL "SHARED") set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${IMPLIBPATH}") endif() -add_library("${libArtifactName}::headers" INTERFACE IMPORTED GLOBAL) -target_include_directories("${libArtifactName}::headers" INTERFACE "`${INCLUDE_DIRS}") diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index b6fbaa2d39684..50e817852cc72 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -3,12 +3,6 @@ - - - - - - $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in @@ -51,16 +45,12 @@ $(PublishDir)/ $(NativeLibraryArtifactLibBasePath.Replace('\', '/')) - - @(NativeLibraryCmakeFragmentIncludePath, ';') - $(NativeLibraryArtifactIncludePath.Replace('\', '/')) - From 0a582c26b6561b435dce393589c1c8fc5ef71d7c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 7 Mar 2024 18:51:13 -0500 Subject: [PATCH 78/84] Revert "remove support for exporting a header target" This reverts commit 0f90a932a9cdbad8080e2bb465929072d3517487. --- src/native/managed/README.md | 23 ++++++++++++------- .../native-lib.find_package-config.cmake.in | 3 +++ src/native/managed/native-library.targets | 10 ++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/native/managed/README.md b/src/native/managed/README.md index d98c1b424777c..b9940ae962034 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -12,8 +12,9 @@ find_nativeaot_library(libWhatever REQUIRED) This will look for a cmake fragment file in `artifacts/obj/cmake/find_package/libWhatever-config.cmake` that will import some variables from -`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs`targets that can -be used ins dependencies in `target_link_libraries()` properties. +`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs` and +`libWhatever::headers` targets that can be used as dependencies in `target_link_libraries()` +properties. ## Adding a new managed library @@ -39,11 +40,17 @@ In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: ``` -Limitations: +The following is recommended: + +1. The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms. +2. The `inc` directory if it exists will be added to the include path of any cmake targets that + depend on the native library. Typically the directory should contain a `libMyNewLibrary.h` header + file with a C declaration for each `[UnmanagedCallersOnly]` entrypoint. If you want to have more + include directories, add them all to the `NativeLibraryCmakeFragmentIncludePath` item in your + `.csproj`. In that case `inc` won't be added by default. -* The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on -all platforms. +Limitations: -* Currently only shared library output is supported. In principle static linking is possible, but -the infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with -static linking will not be supported on Windows. +Currently only shared library output is supported. In principle static linking is possible, but the +infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with static +linking will not be supported on Windows. diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in index 4081472d96604..847d84a503ec3 100644 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ b/src/native/managed/Templates/native-lib.find_package-config.cmake.in @@ -5,6 +5,7 @@ set(NAME "${libArtifactName}") set(EXT "${libArtifactExt}") set(LIBBASEPATH "${libArtifactLibBasePath}") set(IMPLIBPATH "${libArtifactImpLibFullPath}") +set(INCLUDE_DIRS "${libArtifactIncludePath}") add_library("${libArtifactName}::libs" "`${MODE}" IMPORTED GLOBAL) set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${LIBBASEPATH}/`${NAME}`${EXT}") @@ -12,3 +13,5 @@ if("`${CLR_CMAKE_HOST_WIN32}" AND "`${MODE}" STREQUAL "SHARED") set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${IMPLIBPATH}") endif() +add_library("${libArtifactName}::headers" INTERFACE IMPORTED GLOBAL) +target_include_directories("${libArtifactName}::headers" INTERFACE "`${INCLUDE_DIRS}") diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 50e817852cc72..b6fbaa2d39684 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -3,6 +3,12 @@ + + + + + + $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in @@ -45,12 +51,16 @@ $(PublishDir)/ $(NativeLibraryArtifactLibBasePath.Replace('\', '/')) + + @(NativeLibraryCmakeFragmentIncludePath, ';') + $(NativeLibraryArtifactIncludePath.Replace('\', '/')) + From 937a1739bbf7bf6e761f240590f9efb2522ec427 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 6 Mar 2024 20:01:15 -0500 Subject: [PATCH 79/84] native-library.targets: make SetupOSSpecificProps probe for objcopy --- src/native/managed/native-library.targets | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index b6fbaa2d39684..784faf18afbea 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -92,6 +92,28 @@ + + + + true + + + + + + false + + + Date: Thu, 7 Mar 2024 18:55:12 -0500 Subject: [PATCH 80/84] Remove cmake integration --- eng/native/functions.cmake | 17 ----- src/native/managed/README.md | 27 +------ .../native-lib.find_package-config.cmake.in | 17 ----- src/native/managed/native-library.targets | 76 ------------------- 4 files changed, 3 insertions(+), 134 deletions(-) delete mode 100644 src/native/managed/Templates/native-lib.find_package-config.cmake.in diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 7be12dbb7814a..543722a9c0a59 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -662,20 +662,3 @@ function(adhoc_sign_with_entitlements targetName entitlementsFile) POST_BUILD COMMAND codesign -s - -f --entitlements ${entitlementsFile} $) endfunction() - -# find_nativeaot_library(libraryName [REQUIRED]) -# -# Imports a native library produced by NativeAOT (see src/native/managed). -# If the library is found, sets libraryName_FOUND to true, else false. -# If the library is found, it will provide targets libraryName::libs and libraryName::headers. -# If REQUIRED is specified, it's a fatal error not to find the library, otherwise the library is considered optional. -function(find_nativeaot_library libraryName) - cmake_parse_arguments(PARSE_ARGV 1 "findNativeAOT_opt" "REQUIRED" "" "") - if (NOT "${findNativeAOT_opt_REQUIRED}") - find_package(${libraryName} CONFIG NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") - else() - find_package(${libraryName} CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${CLR_ARTIFACTS_OBJ_DIR}/cmake/find_package") - endif() - set("${libraryName}_FOUND" "${${libraryName}_FOUND}" PARENT_SCOPE) -endfunction() - diff --git a/src/native/managed/README.md b/src/native/managed/README.md index b9940ae962034..92ccc9d1a8bf6 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -2,20 +2,6 @@ This directory contains managed libraries that will be compiled using NativeAOT and can be used in runtime components. -## Using existing libraries - -In a `CMakeLists.txt` add - -``` cmake -find_nativeaot_library(libWhatever REQUIRED) -``` - -This will look for a cmake fragment file in -`artifacts/obj/cmake/find_package/libWhatever-config.cmake` that will import some variables from -`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs` and -`libWhatever::headers` targets that can be used as dependencies in `target_link_libraries()` -properties. - ## Adding a new managed library Add a new subdirectory to `src/native/managed` for your library with a `src` and `inc` subdirectories: @@ -40,17 +26,10 @@ In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: ``` -The following is recommended: - -1. The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms. -2. The `inc` directory if it exists will be added to the include path of any cmake targets that - depend on the native library. Typically the directory should contain a `libMyNewLibrary.h` header - file with a C declaration for each `[UnmanagedCallersOnly]` entrypoint. If you want to have more - include directories, add them all to the `NativeLibraryCmakeFragmentIncludePath` item in your - `.csproj`. In that case `inc` won't be added by default. - Limitations: -Currently only shared library output is supported. In principle static linking is possible, but the +* The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms. + +* Currently only shared library output is supported. In principle static linking is possible, but the infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with static linking will not be supported on Windows. diff --git a/src/native/managed/Templates/native-lib.find_package-config.cmake.in b/src/native/managed/Templates/native-lib.find_package-config.cmake.in deleted file mode 100644 index 847d84a503ec3..0000000000000 --- a/src/native/managed/Templates/native-lib.find_package-config.cmake.in +++ /dev/null @@ -1,17 +0,0 @@ -# This is a Config-style package configuration file for cmake's find_package command for ${libArtifactName} - -set(MODE "SHARED") -set(NAME "${libArtifactName}") -set(EXT "${libArtifactExt}") -set(LIBBASEPATH "${libArtifactLibBasePath}") -set(IMPLIBPATH "${libArtifactImpLibFullPath}") -set(INCLUDE_DIRS "${libArtifactIncludePath}") - -add_library("${libArtifactName}::libs" "`${MODE}" IMPORTED GLOBAL) -set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${LIBBASEPATH}/`${NAME}`${EXT}") -if("`${CLR_CMAKE_HOST_WIN32}" AND "`${MODE}" STREQUAL "SHARED") - set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${IMPLIBPATH}") -endif() - -add_library("${libArtifactName}::headers" INTERFACE IMPORTED GLOBAL) -target_include_directories("${libArtifactName}::headers" INTERFACE "`${INCLUDE_DIRS}") diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index 784faf18afbea..a1f21322b7585 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -1,80 +1,4 @@ - - - - - - - - - - - - - $(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in - - - $([MSBuild]::NormalizeDirectory('$(ArtifactsObjDir)\cmake\find_package\')) - - - - - - - - - - - - - - - - - - $(TargetName) - $(NativeLibraryCMakeFindPackageConfigOutputPath)$(NativeLibraryArtifactName)-config.cmake - $(NativeBinaryExt) - $(PublishDir)/ - - $(NativeLibraryArtifactLibBasePath.Replace('\', '/')) - - @(NativeLibraryCmakeFragmentIncludePath, ';') - $(NativeLibraryArtifactIncludePath.Replace('\', '/')) - - - - - - - - - - - - - $([System.IO.Path]::GetFullPath('$(NativeOutputPath)$(TargetName)$(StaticLibSuffix)')) - - $(NativeLibraryArtifactImpLibFullPath.Replace('\', '/')) - - - - - - + false From 095898118b8e6f5d51dd58cdedec3b4239f38f4c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 7 Mar 2024 21:50:11 -0500 Subject: [PATCH 82/84] rename InstallRuntimeComponentDestination --- src/native/managed/README.md | 6 +++--- src/native/managed/native-library.targets | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/native/managed/README.md b/src/native/managed/README.md index 92ccc9d1a8bf6..b559657342c28 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -18,11 +18,11 @@ item group. In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: 1. Near the top, add `` 2. Near the bottom, add `` -3. Define an item `@(InstallRuntimeComponentDest)` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: +3. Define an item `@(InstallRuntimeComponentDestination)` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: ```xml - - + + ``` diff --git a/src/native/managed/native-library.targets b/src/native/managed/native-library.targets index a1f21322b7585..e0f23322bba48 100644 --- a/src/native/managed/native-library.targets +++ b/src/native/managed/native-library.targets @@ -67,10 +67,10 @@ - - + @@ -78,7 +78,7 @@ - <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDest.Identity)'))" /> + <_NormalizedInstallRuntimeComponentDest Include="$([MSBuild]::NormalizeDirectory('$(FinalRuntimeComponentDestinationBase)', '%(InstallRuntimeComponentDestination.Identity)'))" /> From f55ebcc54682de6e911cdeb973afa84318b98c42 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 7 Mar 2024 21:54:30 -0500 Subject: [PATCH 83/84] automatically include native-library.{props,targets} for IsSourceProject C# projects under src/native/managed --- src/native/managed/Directory.Build.props | 1 + src/native/managed/Directory.Build.targets | 4 ++++ src/native/managed/README.md | 4 +--- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 src/native/managed/Directory.Build.targets diff --git a/src/native/managed/Directory.Build.props b/src/native/managed/Directory.Build.props index 3461462e54d14..a431ff1b38fd6 100644 --- a/src/native/managed/Directory.Build.props +++ b/src/native/managed/Directory.Build.props @@ -1,3 +1,4 @@ + diff --git a/src/native/managed/Directory.Build.targets b/src/native/managed/Directory.Build.targets new file mode 100644 index 0000000000000..40dd9aec1ccba --- /dev/null +++ b/src/native/managed/Directory.Build.targets @@ -0,0 +1,4 @@ + + + + diff --git a/src/native/managed/README.md b/src/native/managed/README.md index b559657342c28..c32d95cc6c0e3 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -16,9 +16,7 @@ In `src/native/managed/compile-native.proj`, add item group. In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`: -1. Near the top, add `` -2. Near the bottom, add `` -3. Define an item `@(InstallRuntimeComponentDestination)` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: +1. Define an item `@(InstallRuntimeComponentDestination)` that has directory names relative to `artifacts/bin///` where the shared library should be installed. It's a good idea to have at least `.`: ```xml From b97c391489f4a24ac557813b50f61d9baa061e4f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 7 Mar 2024 22:05:18 -0500 Subject: [PATCH 84/84] switch compile-native.proj to the traversal sdk Co-Authored-By: Jeremy Koritzinsky --- src/native/managed/README.md | 4 ++-- src/native/managed/compile-native.proj | 29 ++++++++++---------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/native/managed/README.md b/src/native/managed/README.md index c32d95cc6c0e3..047d9fcc327d8 100644 --- a/src/native/managed/README.md +++ b/src/native/managed/README.md @@ -4,10 +4,10 @@ This directory contains managed libraries that will be compiled using NativeAOT ## Adding a new managed library -Add a new subdirectory to `src/native/managed` for your library with a `src` and `inc` subdirectories: +Add a new subdirectory to `src/native/managed` for your library with a `src`, `inc` and `test` subdirectories: ``` console -$ mkdir -p libMyNewLibrary/src libMyNewLibrary/inc +$ mkdir -p libMyNewLibrary/src libMyNewLibrary/inc libMyNewLibrary/test $ dotnet new classlib -n libMyNewLibrary -o libMyNewLibrary/src ``` diff --git a/src/native/managed/compile-native.proj b/src/native/managed/compile-native.proj index 4116e5d9a1940..4203835936ecb 100644 --- a/src/native/managed/compile-native.proj +++ b/src/native/managed/compile-native.proj @@ -1,9 +1,12 @@ - + Release shared + + + $(TraversalPublishGlobalProperties);_IsPublishing=true @@ -44,24 +47,14 @@ - + + @(SubprojectProps->'%(Identity)=%(Value)', ';') + + + + AdditionalProperties="%(AdditionalProperties);$(SplitSubprojectProps)" + Condition="$(SupportsNativeAotComponents)"/> - - - - @(SubprojectProps->'%(Identity)=%(Value)', ';') - - - - - - -