From 6c79fe61197f5a0452e4a5c88080ad05a3762c61 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 6 Feb 2025 22:17:01 -0500 Subject: [PATCH 1/9] Bring up android+coreclr windows build. Mostly works except for the AndroidAppBuilder trying to build the sample --- eng/Subsets.props | 1 + eng/native/configureplatform.cmake | 7 +- eng/native/configuretools.cmake | 15 ++- eng/native/functions.cmake | 91 ++++++++++++----- eng/native/gen-buildsys.cmd | 27 +++++ eng/native/generateversionscript.ps1 | 34 +++++++ eng/native/tryrun.cmake | 78 ++++++--------- eng/native/version/copy_version_files.ps1 | 27 +++++ src/coreclr/CMakeLists.txt | 31 ++++-- src/coreclr/build-runtime.cmd | 29 +++++- src/coreclr/debug/runtimeinfo/CMakeLists.txt | 3 +- src/coreclr/dlls/mscordac/CMakeLists.txt | 55 ++++++++--- src/coreclr/generateredefinesfile.ps1 | 40 ++++++++ .../Runtime/eventpipe/CMakeLists.txt | 2 +- src/coreclr/nativeresources/processrc.ps1 | 98 +++++++++++++++++++ src/coreclr/pal/src/configure.cmake | 1 + src/coreclr/runtime-prereqs.proj | 12 ++- src/coreclr/runtime.proj | 24 ++--- src/coreclr/scripts/genEventing.py | 22 +++-- src/coreclr/vm/eventing/CMakeLists.txt | 2 +- .../corehost/apphost/static/CMakeLists.txt | 4 +- src/native/corehost/corehost.proj | 2 +- src/native/libs/build-native.cmd | 15 ++- src/native/libs/build-native.proj | 13 ++- src/tasks/AndroidAppBuilder/ApkBuilder.cs | 33 +++++-- src/tasks/Common/AndroidSdkHelper.cs | 3 +- .../Android/AndroidProject.cs | 2 +- 27 files changed, 530 insertions(+), 141 deletions(-) create mode 100644 eng/native/generateversionscript.ps1 create mode 100644 eng/native/version/copy_version_files.ps1 create mode 100644 src/coreclr/generateredefinesfile.ps1 create mode 100644 src/coreclr/nativeresources/processrc.ps1 diff --git a/eng/Subsets.props b/eng/Subsets.props index 266add7128805c..c57049df1934cf 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -98,6 +98,7 @@ clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools+host.native clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools + clr.runtime+clr.alljits+clr.corelib+clr.nativecorelib+clr.tools+clr.packages clr.iltools+clr.packages diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 6f70e39f30c502..fc207977125c3e 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -368,6 +368,11 @@ if(CLR_CMAKE_HOST_LINUX_MUSL OR CLR_CMAKE_TARGET_OS STREQUAL alpine) set(CLR_CMAKE_TARGET_LINUX_MUSL 1) endif(CLR_CMAKE_HOST_LINUX_MUSL OR CLR_CMAKE_TARGET_OS STREQUAL alpine) +macro(set_cache_value) + set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE) + set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE) +endmacro() + if(CLR_CMAKE_TARGET_OS STREQUAL android) set(CLR_CMAKE_TARGET_UNIX 1) set(CLR_CMAKE_TARGET_LINUX 1) @@ -471,7 +476,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL windows) endif() # check if host & target os/arch combination are valid -if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_ANDROID) if(NOT (CLR_CMAKE_HOST_OS STREQUAL windows)) message(FATAL_ERROR "Invalid host and target os/arch combination. Host OS: ${CLR_CMAKE_HOST_OS}") endif() diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index 6898f88578df13..de4571f905a5e5 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -77,10 +77,17 @@ endif() if (NOT CLR_CMAKE_HOST_WIN32) # detect linker - execute_process(COMMAND sh -c "${CMAKE_C_COMPILER} ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version | head -1" - ERROR_QUIET - OUTPUT_VARIABLE ldVersionOutput - OUTPUT_STRIP_TRAILING_WHITESPACE) + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + execute_process(COMMAND ${CMAKE_C_COMPILER} -Wl,--version + ERROR_QUIET + OUTPUT_VARIABLE ldVersionOutput + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + execute_process(COMMAND sh -c "${CMAKE_C_COMPILER} ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version | head -1" + ERROR_QUIET + OUTPUT_VARIABLE ldVersionOutput + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() if("${ldVersionOutput}" MATCHES "LLD") set(LD_LLVM 1) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 2b8db967373341..f797b0e46c2754 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -338,39 +338,66 @@ function(generate_exports_file) list(GET INPUT_LIST -1 outputFilename) list(REMOVE_AT INPUT_LIST -1) - if(CLR_CMAKE_TARGET_APPLE) - set(SCRIPT_NAME generateexportedsymbols.sh) + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(SCRIPT_NAME ${CLR_ENG_NATIVE_DIR}/generateversionscript.ps1) + + add_custom_command( + OUTPUT ${outputFilename} + COMMAND powershell -NoProfile -ExecutionPolicy ByPass -File "${SCRIPT_NAME}" ${INPUT_LIST} >${outputFilename} + DEPENDS ${INPUT_LIST} ${SCRIPT_NAME} + COMMENT "Generating exports file ${outputFilename}" + ) else() - set(SCRIPT_NAME generateversionscript.sh) + if(CLR_CMAKE_TARGET_APPLE) + set(SCRIPT_NAME ${CLR_ENG_NATIVE_DIR}/generateexportedsymbols.sh) + else() + set(SCRIPT_NAME ${CLR_ENG_NATIVE_DIR}/generateversionscript.sh) + endif() + + add_custom_command( + OUTPUT ${outputFilename} + COMMAND ${SCRIPT_NAME} ${INPUT_LIST} >${outputFilename} + DEPENDS ${INPUT_LIST} ${SCRIPT_NAME} + COMMENT "Generating exports file ${outputFilename}" + ) endif() - add_custom_command( - OUTPUT ${outputFilename} - COMMAND ${CLR_ENG_NATIVE_DIR}/${SCRIPT_NAME} ${INPUT_LIST} >${outputFilename} - DEPENDS ${INPUT_LIST} ${CLR_ENG_NATIVE_DIR}/${SCRIPT_NAME} - COMMENT "Generating exports file ${outputFilename}" - ) set_source_files_properties(${outputFilename} PROPERTIES GENERATED TRUE) endfunction() function(generate_exports_file_prefix inputFilename outputFilename prefix) - if(CMAKE_SYSTEM_NAME STREQUAL Darwin) set(SCRIPT_NAME generateexportedsymbols.sh) else() - set(SCRIPT_NAME generateversionscript.sh) + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(SCRIPT_NAME ${CLR_ENG_NATIVE_DIR}/generateversionscript.ps1) + else() + set(SCRIPT_NAME ${CLR_ENG_NATIVE_DIR}/generateversionscript.sh) + endif() + if (NOT ${prefix} STREQUAL "") set(EXTRA_ARGS ${prefix}) endif() endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) - add_custom_command( - OUTPUT ${outputFilename} - COMMAND ${CLR_ENG_NATIVE_DIR}/${SCRIPT_NAME} ${inputFilename} ${EXTRA_ARGS} >${outputFilename} - DEPENDS ${inputFilename} ${CLR_ENG_NATIVE_DIR}/${SCRIPT_NAME} - COMMENT "Generating exports file ${outputFilename}" - ) + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + add_custom_command( + OUTPUT ${outputFilename} + COMMAND powershell -NoProfile -ExecutionPolicy ByPass -File \"${SCRIPT_NAME}\" ${inputFilename} ${EXTRA_ARGS} >${outputFilename} + DEPENDS ${inputFilename} ${SCRIPT_NAME} + COMMENT "Generating exports file ${outputFilename}" + ) + else() + add_custom_command( + OUTPUT ${outputFilename} + COMMAND ${SCRIPT_NAME} ${inputFilename} ${EXTRA_ARGS} >${outputFilename} + DEPENDS ${inputFilename} ${SCRIPT_NAME} + COMMENT "Generating exports file ${outputFilename}" + ) + endif() set_source_files_properties(${outputFilename} PROPERTIES GENERATED TRUE) endfunction() @@ -445,16 +472,28 @@ function(strip_symbols targetName outputFilename) COMMAND ${strip_command} ) else (CLR_CMAKE_TARGET_APPLE) - - add_custom_command( - TARGET ${targetName} - POST_BUILD - VERBATIM - COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" - COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file} - COMMAND ${CMAKE_OBJCOPY} --strip-debug --strip-unneeded ${strip_source_file} - COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file} + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + add_custom_command( + TARGET ${targetName} + POST_BUILD + VERBATIM + COMMAND powershell -C "echo Stripping symbols from $(Split-Path -Path '${strip_source_file}' -Leaf) into $(Split-Path -Path '${strip_destination_file}' -Leaf)" + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file} + COMMAND ${CMAKE_OBJCOPY} --strip-debug --strip-unneeded ${strip_source_file} + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file} ) + else() + add_custom_command( + TARGET ${targetName} + POST_BUILD + VERBATIM + COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file} + COMMAND ${CMAKE_OBJCOPY} --strip-debug --strip-unneeded ${strip_source_file} + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file} + ) + endif() endif (CLR_CMAKE_TARGET_APPLE) endif(CLR_CMAKE_HOST_UNIX) endfunction() diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 83682d69cfc393..7ea24262015070 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -80,6 +80,32 @@ if /i "%__Arch%" == "wasm" ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" ) +if /i "%__Os%" == "android" ( + :: Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot + set __ANDROID_API_LEVEL=21 + if "%ANDROID_NDK_ROOT%" == "" ( + echo Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root. + exit /B 1 + ) + + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_ROOT:/=\%/build/cmake/android.toolchain.cmake" + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_BUILD=1" "-C %__repoRoot%/eng/native/tryrun.cmake" "-DANDROID_CPP_FEATURES='no-rtti exceptions'" + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_PLATFORM=android-!__ANDROID_API_LEVEL!" "-DANDROID_NATIVE_API_LEVEL=!__ANDROID_API_LEVEL!" + + if "%__Arch%" == "x64" ( + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=x86_64" + ) + if "%__Arch%" == "x86" ( + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=x86" + ) + if "%__Arch%" == "arm64" ( + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=arm64-v8a" + ) + if "%__Arch%" == "x64" ( + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=armeabi-v7a" + ) +) + :loop if [%6] == [] goto end_loop set __ExtraCmakeParams=%__ExtraCmakeParams% %6 @@ -111,6 +137,7 @@ if not "%__ConfigureOnly%" == "1" ( if /i "%__UseEmcmake%" == "1" ( call "!EMSDK_PATH!/emsdk_env.cmd" > nul 2>&1 && emcmake "%CMakePath%" %__ExtraCmakeParams% --no-warn-unused-cli -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir% ) else ( + echo "%CMakePath% %__ExtraCmakeParams% --no-warn-unused-cli -G %__CmakeGenerator% -B %__IntermediatesDir% -S %__SourceDir%" "%CMakePath%" %__ExtraCmakeParams% --no-warn-unused-cli -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir% ) diff --git a/eng/native/generateversionscript.ps1 b/eng/native/generateversionscript.ps1 new file mode 100644 index 00000000000000..945ab6f706a439 --- /dev/null +++ b/eng/native/generateversionscript.ps1 @@ -0,0 +1,34 @@ +param ( + [string]$inputFile, + [string]$prefix +) + +# Print the header +Write-Output "V1.0 {" +Write-Output " global:" + +# Read the input file line by line +Get-Content $inputFile | ForEach-Object { + $line = $_.Trim() + + # Skip empty lines and comment lines starting with semicolon + if ($line -match '^\;.*$' -or $line -match '^[\s]*$') { + return + } + + # Remove the CR character in case the sources are mapped from + # a Windows share and contain CRLF line endings + $line = $line -replace "`r", "" + + # Only prefix the entries that start with "#" + if ($line -match '^#.*$') { + $line = $line -replace '^#', '' + Write-Output " $prefix$line;" + } else { + Write-Output " $line;" + } +} + +# Print the footer +Write-Output " local: *;" +Write-Output "};" \ No newline at end of file diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index 8fd127f9e3e802..a818662677be7b 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -1,21 +1,5 @@ set(CROSS_ROOTFS $ENV{ROOTFS_DIR}) set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH}) -set(ANDROID_BUILD $ENV{ANDROID_BUILD}) - -# Also allow building as Android without specifying `-cross`. -if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_BUILD) - if(ANDROID_ABI STREQUAL "arm64-v8a") - set(TARGET_ARCH_NAME "arm64") - elseif(ANDROID_ABI STREQUAL "x86_64") - set(TARGET_ARCH_NAME "x64") - elseif(ANDROID_ABI STREQUAL "armeabi-v7a") - set(TARGET_ARCH_NAME "arm") - elseif(ANDROID_ABI STREQUAL "x86") - set(TARGET_ARCH_NAME "x86") - else() - message(FATAL_ERROR "ANDROID_ABI ${ANDROID_ABI} not recognized!") - endif() -endif() macro(set_cache_value) set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE) @@ -50,35 +34,7 @@ if(NOT DEFINED ANDROID_BUILD) endif() endif() -if(DARWIN) - if(DEFINED ANDROID_BUILD OR TARGET_ARCH_NAME MATCHES "^(arm64|x64)$") - set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1) - set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1) - set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1) - set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1) - set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) - set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0) - set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0) - set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0) - set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1) - set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 1) - set_cache_value(HAVE_PROCFS_CTL_EXITCODE 1) - set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1) - set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1) - set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1) - set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0) - set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0) - set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0) - set_cache_value(MMAP_ANON_IGNORES_PROTECTION_EXITCODE 1) - set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1) - set_cache_value(PTHREAD_CREATE_MODIFIES_ERRNO_EXITCODE 1) - set_cache_value(REALPATH_SUPPORTS_NONEXISTENT_FILES_EXITCODE 1) - set_cache_value(SEM_INIT_MODIFIES_ERRNO_EXITCODE 1) - set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1) - else() - message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!") - endif() -elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86|x64)$" OR FREEBSD OR ILLUMOS OR TIZEN OR HAIKU) +if(DEFINED ANDROID_BUILD OR TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86|x64)$" OR FREEBSD OR ILLUMOS OR TIZEN OR HAIKU) set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 0) set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 0) set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) @@ -123,8 +79,38 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s39 set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1) set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1) set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1) + elseif(ANDROID_BUILD) + set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS 0) + endif() +elseif(DARWIN) + if(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$") + set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1) + set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1) + set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1) + set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1) + set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) + set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0) + set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0) + set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0) + set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1) + set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 1) + set_cache_value(HAVE_PROCFS_CTL_EXITCODE 1) + set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1) + set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1) + set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1) + set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0) + set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0) + set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0) + set_cache_value(MMAP_ANON_IGNORES_PROTECTION_EXITCODE 1) + set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1) + set_cache_value(PTHREAD_CREATE_MODIFIES_ERRNO_EXITCODE 1) + set_cache_value(REALPATH_SUPPORTS_NONEXISTENT_FILES_EXITCODE 1) + set_cache_value(SEM_INIT_MODIFIES_ERRNO_EXITCODE 1) + set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1) + else() + message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!") endif() -else() +elseif(NOT WIN32) message(FATAL_ERROR "Unsupported platform. OS: ${CMAKE_SYSTEM_NAME}, arch: ${TARGET_ARCH_NAME}") endif() diff --git a/eng/native/version/copy_version_files.ps1 b/eng/native/version/copy_version_files.ps1 new file mode 100644 index 00000000000000..7573abcbb11a5a --- /dev/null +++ b/eng/native/version/copy_version_files.ps1 @@ -0,0 +1,27 @@ +$VersionFolder = $PSScriptRoot +$RepoRoot = (Resolve-Path "$VersionFolder/../../../").Path.TrimEnd("\") + +Get-ChildItem -Path "$VersionFolder" -Filter "_version.*" | ForEach-Object { + $path = $_.FullName + if ($_.Name -eq "_version.c") { + # For _version.c, update the commit ID if it has changed from the last build. + $commit = (git rev-parse HEAD 2>$null) + if (-not $commit) { $commit = "N/A" } + $substitute = "static char sccsid[] __attribute__((used)) = `"@(#)Version N/A @Commit: $commit`";" + $version_file_contents = Get-Content -Path $path | ForEach-Object { $_ -replace "^static.*", $substitute } + $version_file_destination = "$RepoRoot\\artifacts\\obj\\_version.c" + $current_contents = "" + $is_placeholder_file = $false + if (Test-Path -Path $version_file_destination) { + $current_contents = Get-Content -Path $version_file_destination -Raw + $is_placeholder_file = $current_contents -match "@\(#\)Version N/A @Commit:" + } else { + $is_placeholder_file = $true + } + if ($is_placeholder_file -and $version_file_contents -ne $current_contents) { + $version_file_contents | Set-Content -Path $version_file_destination + } + } elseif (-not (Test-Path -Path "$RepoRoot\\artifacts\\obj\\$($_.Name)")) { + Copy-Item -Path $path -Destination "$RepoRoot\\artifacts\\obj\\" + } +} diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index e519e1e71e5ae8..405cf527687c1a 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -215,7 +215,13 @@ if(CLR_CMAKE_HOST_UNIX) set (NATIVE_RESOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/nativeresources) include_directories(${NATIVE_RESOURCE_DIR}) - set (PROCESS_RC_SCRIPT ${NATIVE_RESOURCE_DIR}/processrc.sh) + + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set (PROCESS_RC_SCRIPT ${NATIVE_RESOURCE_DIR}/processrc.ps1) + else() + set (PROCESS_RC_SCRIPT ${NATIVE_RESOURCE_DIR}/processrc.sh) + endif() set (RESOURCE_STRING_HEADER_DIR ${NATIVE_RESOURCE_DIR}) # Create a command to create a C++ source file containing an array of @@ -230,16 +236,25 @@ if(CLR_CMAKE_HOST_UNIX) set(RESOURCE_ENTRY_ARRAY_CPP ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.cpp) - add_custom_command( - OUTPUT ${RESOURCE_ENTRY_ARRAY_CPP} - # Convert the preprocessed .rc file to a C++ file which will be used to make a static lib. - COMMAND ${PROCESS_RC_SCRIPT} ${PREPROCESSED_SOURCE} ${TARGET_NAME} >${RESOURCE_ENTRY_ARRAY_CPP} - DEPENDS ${PREPROCESSED_SOURCE} ${PROCESS_RC_SCRIPT} - ) + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + add_custom_command( + OUTPUT ${RESOURCE_ENTRY_ARRAY_CPP} + # Convert the preprocessed .rc file to a C++ file which will be used to make a static lib. + COMMAND powershell -NoProfile -ExecutionPolicy ByPass -File \"${PROCESS_RC_SCRIPT}\" ${PREPROCESSED_SOURCE} ${TARGET_NAME} >${RESOURCE_ENTRY_ARRAY_CPP} + DEPENDS ${PREPROCESSED_SOURCE} ${PROCESS_RC_SCRIPT} + ) + else() + add_custom_command( + OUTPUT ${RESOURCE_ENTRY_ARRAY_CPP} + # Convert the preprocessed .rc file to a C++ file which will be used to make a static lib. + COMMAND ${PROCESS_RC_SCRIPT} ${PREPROCESSED_SOURCE} ${TARGET_NAME} >${RESOURCE_ENTRY_ARRAY_CPP} + DEPENDS ${PREPROCESSED_SOURCE} ${PROCESS_RC_SCRIPT} + ) + endif() include_directories(${RESOURCE_STRING_HEADER_DIR}) set(${TARGET_FILE} ${RESOURCE_ENTRY_ARRAY_CPP} PARENT_SCOPE) - endfunction() add_subdirectory(nativeresources) diff --git a/src/coreclr/build-runtime.cmd b/src/coreclr/build-runtime.cmd index 907565de64f22c..af18fd9e7247e6 100644 --- a/src/coreclr/build-runtime.cmd +++ b/src/coreclr/build-runtime.cmd @@ -64,6 +64,7 @@ set __UnprocessedBuildArgs= set __BuildNative=1 set __RestoreOptData=1 +set __HostOS= set __HostArch= set __PgoOptDataPath= set __CMakeArgs= @@ -127,6 +128,7 @@ if [!__PassThroughArgs!]==[] ( set "__PassThroughArgs=%__PassThroughArgs% %1" ) +if /i "%1" == "-hostos" (set __HostOS=%2&shift&shift&goto Arg_Loop) if /i "%1" == "-hostarch" (set __HostArch=%2&shift&shift&goto Arg_Loop) if /i "%1" == "-os" (set __TargetOS=%2&shift&shift&goto Arg_Loop) if /i "%1" == "-outputrid" (set __OutputRid=%2&shift&shift&goto Arg_Loop) @@ -271,7 +273,11 @@ REM ============================================================================ @if defined _echo @echo on -call "%__RepoRootDir%\eng\native\version\copy_version_files.cmd" +if not "%__TargetOS%"=="android" ( + call "%__RepoRootDir%\eng\native\version\copy_version_files.cmd" +) else ( + call powershell -NoProfile -ExecutionPolicy ByPass -File "%__RepoRootDir%\eng\native\version\copy_version_files.ps1" +) REM ========================================================================================= REM === @@ -373,9 +379,24 @@ if %__BuildNative% EQU 1 ( set __ExtraCmakeArgs="-DCMAKE_BUILD_TYPE=!__BuildType!" ) - set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_TARGET_ARCH=%__TargetArch%" "-DCLR_CMAKE_TARGET_OS=%__TargetOS%" "-DCLI_CMAKE_FALLBACK_OS=%__HostFallbackOS%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" %__CMakeArgs% - echo Calling "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% %__TargetOS% !__ExtraCmakeArgs! - call "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% %__TargetOS% !__ExtraCmakeArgs! + if /i not "%__HostOS%" == "%__TargetOS%" ( + if /i "%__HostOS%" == "" ( + set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_TARGET_OS=%__TargetOS%" + ) + ) + + set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLI_CMAKE_FALLBACK_OS=%__HostFallbackOS%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" + + if /i "%__TargetOS%" == "android" ( + if not "%__HostOS%" == "" ( + set "__TargetOS=!__HostOS!" + ) + ) + + set __ExtraCmakeArgs=!__ExtraCmakeArgs! %__CMakeArgs% + + echo Calling "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% !__TargetOS! !__ExtraCmakeArgs! + call "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% !__TargetOS! !__ExtraCmakeArgs! if not !errorlevel! == 0 ( echo %__ErrMsgPrefix%%__MsgPrefix%Error: failed to generate native component build project! goto ExitWithError diff --git a/src/coreclr/debug/runtimeinfo/CMakeLists.txt b/src/coreclr/debug/runtimeinfo/CMakeLists.txt index 018e49645cd0de..9705bdfd31fd7b 100644 --- a/src/coreclr/debug/runtimeinfo/CMakeLists.txt +++ b/src/coreclr/debug/runtimeinfo/CMakeLists.txt @@ -7,7 +7,8 @@ set(RUNTIMEINFO_SOURCES add_library_clr(runtimeinfo STATIC ${RUNTIMEINFO_SOURCES}) function(generate_module_index Target ModuleIndexFile) - if(CLR_CMAKE_HOST_WIN32) + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(scriptExt ".cmd") else() set(scriptExt ".sh") diff --git a/src/coreclr/dlls/mscordac/CMakeLists.txt b/src/coreclr/dlls/mscordac/CMakeLists.txt index ed7d7f03f9522e..0b580604c54bc2 100644 --- a/src/coreclr/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/dlls/mscordac/CMakeLists.txt @@ -45,7 +45,11 @@ else(CLR_CMAKE_HOST_WIN32) # Generate DAC export file with the DAC_ prefix generate_exports_file_prefix(${DEF_SOURCES} ${EXPORTS_FILE} DAC_) - set(REDEFINES_FILE_SCRIPT ${CMAKE_SOURCE_DIR}/generateredefinesfile.sh) + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(REDEFINES_FILE_SCRIPT ${CMAKE_SOURCE_DIR}/generateredefinesfile.ps1) + else() + set(REDEFINES_FILE_SCRIPT ${CMAKE_SOURCE_DIR}/generateredefinesfile.sh) + endif() if (CLR_CMAKE_HOST_ARCH_ARM OR CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(JUMP_INSTRUCTION b) @@ -57,23 +61,46 @@ else(CLR_CMAKE_HOST_WIN32) # Generate the palredefines.inc file to map from the imported prefixed APIs (foo to DAC_foo) set(PAL_REDEFINES_INC ${GENERATED_INCLUDE_DIR}/palredefines.inc) - add_custom_command( - OUTPUT ${PAL_REDEFINES_INC} - COMMAND ${REDEFINES_FILE_SCRIPT} ${DEF_SOURCES} ${JUMP_INSTRUCTION} "" DAC_ > ${PAL_REDEFINES_INC} - DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_SCRIPT} - COMMENT "Generating PAL redefines file -> ${PAL_REDEFINES_INC}" - VERBATIM - ) + + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + add_custom_command( + OUTPUT ${PAL_REDEFINES_INC} + COMMAND powershell -NoProfile -ExecutionPolicy ByPass -File \"${REDEFINES_FILE_SCRIPT}\" -filename \"${DEF_SOURCES}\" -jump ${JUMP_INSTRUCTION} -prefix1 \"\" -prefix2 \"DAC_\" > ${PAL_REDEFINES_INC} + DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_SCRIPT} + COMMENT "Generating PAL redefines file -> ${PAL_REDEFINES_INC}" + ) + else() + add_custom_command( + OUTPUT ${PAL_REDEFINES_INC} + COMMAND ${REDEFINES_FILE_SCRIPT} ${DEF_SOURCES} ${JUMP_INSTRUCTION} "" DAC_ > ${PAL_REDEFINES_INC} + DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_SCRIPT} + COMMENT "Generating PAL redefines file -> ${PAL_REDEFINES_INC}" + VERBATIM + ) + endif() add_custom_target(pal_redefines_file DEPENDS ${PAL_REDEFINES_INC}) # Generate the libredefines.inc file for the DAC to export the prefixed APIs (DAC_foo to foo) set(LIB_REDEFINES_INC ${GENERATED_INCLUDE_DIR}/libredefines.inc) - add_custom_command( - OUTPUT ${LIB_REDEFINES_INC} - COMMAND ${REDEFINES_FILE_SCRIPT} ${DEF_SOURCES} ${JUMP_INSTRUCTION} DAC_ > ${LIB_REDEFINES_INC} - DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_SCRIPT} - COMMENT "Generating DAC export redefines file -> ${LIB_REDEFINES_INC}" - ) + + # Win32 may be false when cross compiling + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + add_custom_command( + OUTPUT ${LIB_REDEFINES_INC} + COMMAND powershell -NoProfile -ExecutionPolicy ByPass -File \"${REDEFINES_FILE_SCRIPT}\" -filename \"${DEF_SOURCES}\" -jump ${JUMP_INSTRUCTION} -prefix1 \"DAC_\" > ${LIB_REDEFINES_INC} + DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_SCRIPT} + COMMENT "Generating DAC export redefines file -> ${LIB_REDEFINES_INC}" + ) + else() + add_custom_command( + OUTPUT ${LIB_REDEFINES_INC} + COMMAND ${REDEFINES_FILE_SCRIPT} ${DEF_SOURCES} ${JUMP_INSTRUCTION} DAC_ > ${LIB_REDEFINES_INC} + DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_SCRIPT} + COMMENT "Generating DAC export redefines file -> ${LIB_REDEFINES_INC}" + VERBATIM + ) + endif() add_custom_target(lib_redefines_inc DEPENDS ${LIB_REDEFINES_INC}) # Add lib redefines file to DAC diff --git a/src/coreclr/generateredefinesfile.ps1 b/src/coreclr/generateredefinesfile.ps1 new file mode 100644 index 00000000000000..aedc41510a7355 --- /dev/null +++ b/src/coreclr/generateredefinesfile.ps1 @@ -0,0 +1,40 @@ +param ( + [string]$filename = "", + [string]$jump = "", + [string]$prefix1 = "", + [string]$prefix2 = "" +) + +# Function to display usage information +function Show-Usage { + Write-Host "Usage:" + Write-Host "generateredefinesfile.ps1 " + exit 1 +} + +if ($filename.Length -eq 0) { + Show-Usage +} + +# Read the file line by line +Get-Content $filename | ForEach-Object { + $line = $_.Trim() + + # Skip empty lines and comment lines starting with semicolon + if ($line -match '^\;.*$' -or $line -match '^[\s]*$') { + return + } + + # Remove the CR character in case the sources are mapped from + # a Windows share and contain CRLF line endings + $line = $line -replace "`r", "" + + # Only process the entries that begin with "#" + if ($line -match '^#.*$') { + $line = $line -replace '^#', '' + Write-Host "LEAF_ENTRY ${prefix1}${line}, _TEXT" + Write-Host " ${jump} EXTERNAL_C_FUNC(${prefix2}${line})" + Write-Host "LEAF_END ${prefix1}${line}, _TEXT" + Write-Host "" + } +} diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index 739738e6743465..e7efe26147defd 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -29,7 +29,7 @@ set (EventingHeaders add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --inc ${EVENT_INCLUSION_FILE} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h --runtimeflavor nativeaot ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} + COMMAND ${Python_EXECUTABLE} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --inc ${EVENT_INCLUSION_FILE} --targetos ${CLR_CMAKE_TARGET_OS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h --runtimeflavor nativeaot ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp DEPENDS ${EVENT_MANIFEST} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} VERBATIM diff --git a/src/coreclr/nativeresources/processrc.ps1 b/src/coreclr/nativeresources/processrc.ps1 new file mode 100644 index 00000000000000..8ff7559e85eaa9 --- /dev/null +++ b/src/coreclr/nativeresources/processrc.ps1 @@ -0,0 +1,98 @@ +param ( + [string]$Filename, + [string]$Targetname +) + +function Evaluate-ComplexExpression { + param ( + [string]$expression + ) + + # Extract the components of the expression + if ($expression -match '\(0x([0-9A-Fa-f]+)\s*\+\s*\(\(\(0x([0-9A-Fa-f]+)\)\s*&\s*0x([0-9A-Fa-f]+)\)\)\)') { + $baseValue = [convert]::ToInt64($matches[1], 16) + $hexValue = [convert]::ToInt64($matches[2], 16) + $mask = [convert]::ToInt64($matches[3], 16) + + # Perform the bitwise AND operation + $maskedValue = $hexValue -band $mask + + # Add the base value to the masked value + $result = $baseValue + $maskedValue + + return $result + } else { + throw "$expression - Input string was not in the correct format" + } +} + +# Function to determine if the input is a simple hex value or a complex expression +function Evaluate-Input { + param ( + [string]$expr + ) + + # Regular expression for a simple hex value + $hexRegex = '^0x[0-9A-Fa-f]+$' + + # Regular expression for a complex expression + $complexRegex = '^\(0x[0-9A-Fa-f]+\s*\+\s*\(\(\(0x[0-9A-Fa-f]+\)\s*&\s*0x[0-9A-Fa-f]+\)\)\)$' + + if ($expr -match $hexRegex) { + # Input is a simple hex value + return [convert]::ToInt64($expr, 16) + } elseif ($expr -match $complexRegex) { + # Input is a complex expression + return Evaluate-ComplexExpression($expr) + } else { + Write-Host "Input string was not in the correct format" + return 0 + } +} + +$ArrayName = "nativeStringResourceArray_$Targetname" +$TableName = "nativeStringResourceTable_$Targetname" + +$InStringTable = $false +$InBeginEnd = $false +$ResourceArray = @{} + +Get-Content $Filename | ForEach-Object { + $line = $_.Trim() + if ($line -match "^STRINGTABLE\s*DISCARDABLE") { + $InStringTable = $true + } elseif ($line -eq "BEGIN") { + $InBeginEnd = $InStringTable + } elseif ($InBeginEnd -and $line -eq "END") { + $InBeginEnd = $false + $InStringTable = $false + } elseif ($InBeginEnd -and $line -notmatch "^\s*$") { + $id = $line -replace '\".*', '' -replace '\(HRESULT\)', '' -replace 'L', '' + $id = $id.Trim() + $id = Evaluate-Input($id) + + if ($line -match '"([^"]+)"') { + $content = $matches[1] + $ResourceArray[$id.ToString("x8")] = $content + } + } +} + +Write-Output "// Licensed to the .NET Foundation under one or more agreements." +Write-Output "// The .NET Foundation licenses this file to you under the MIT license." +Write-Output "//" +Write-Output "// This code was generated by processrc.ps1 and is not meant to be modified manually." +Write-Output "" +Write-Output "#include " +Write-Output "" +Write-Output "extern NativeStringResourceTable $TableName;" +Write-Output "const NativeStringResource $ArrayName[] = {" + +foreach ($id in $ResourceArray.Keys) { + $hexId = "{0:x8}" -f $id + Write-Output " {0x$hexId,`"$($ResourceArray[$id])`"}," +} + +Write-Output "};" +Write-Output "" +Write-Output "NativeStringResourceTable $TableName __attribute__((visibility(`"default`"))) = { $($ResourceArray.Count), $ArrayName };" diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake index bc4f3258b44b3a..bff333bba3cd32 100644 --- a/src/coreclr/pal/src/configure.cmake +++ b/src/coreclr/pal/src/configure.cmake @@ -512,6 +512,7 @@ int main(void) exit(ret != 1); }" ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS) + set(CMAKE_REQUIRED_LIBRARIES pthread) check_cxx_source_runs(" #include diff --git a/src/coreclr/runtime-prereqs.proj b/src/coreclr/runtime-prereqs.proj index b1d1cf8b041df8..e4d1b52f74bbae 100644 --- a/src/coreclr/runtime-prereqs.proj +++ b/src/coreclr/runtime-prereqs.proj @@ -2,7 +2,7 @@ $(ArtifactsObjDir)_version.h - $(ArtifactsObjDir)_version.c + $(ArtifactsObjDir)_version.c $(ArtifactsObjDir)runtime_version.h $(ArtifactsObjDir)native.sourcelink.json false @@ -14,6 +14,16 @@ + + + $(ArtifactsObjDir)_version.h + + + + + $(ArtifactsObjDir)_version.c + + + <_CoreClrBuildArg Condition="!$([MSBuild]::IsOsPlatform(Windows))" + Include="-cmakeargs -DANDROID_CPP_FEATURES="no-rtti exceptions""/> diff --git a/src/coreclr/scripts/genEventing.py b/src/coreclr/scripts/genEventing.py index e1ca570166e708..6a16459fbfe26c 100644 --- a/src/coreclr/scripts/genEventing.py +++ b/src/coreclr/scripts/genEventing.py @@ -872,8 +872,8 @@ def getKeywordsMaskCombined(keywords, keywordsToMask): return mask -def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, clrallevents, inclusion_list, generatedFileType, user_events): - is_windows = os.name == 'nt' +def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, clrallevents, inclusion_list, generatedFileType, user_events): + is_windows = targetOS == "windows" with open_for_update(clrallevents) as Clrallevents: Clrallevents.write(stdprolog) if generatedFileType=="header-impl": @@ -944,7 +944,7 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_ if generatedFileType == "header": Clrallevents.write("#endif // __CLR_ETW_ALL_MAIN_H__\n") -def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, inclusion_list, user_events): +def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, targetOS, inclusion_list, user_events): generateEtmDummyHeader(sClrEtwAllMan,etmDummyFile) tree = DOM.parse(sClrEtwAllMan) @@ -1014,16 +1014,16 @@ def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern #endif // DOTNET_TRACE_CONTEXT_DEF """ - is_windows = os.name == 'nt' + is_windows = targetOS == "windows" # Write the main source(s) for FireETW* functions # nativeaot requires header and source file to be separated as well as a noop implementation if runtimeFlavor.nativeaot: - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.cpp"), inclusion_list, "source-impl", user_events) - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header", user_events) - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "disabledclretwallmain.cpp"), inclusion_list, "source-impl-noop", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.cpp"), inclusion_list, "source-impl", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "disabledclretwallmain.cpp"), inclusion_list, "source-impl-noop", user_events) else: - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header-impl", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header-impl", user_events) if write_xplatheader: clrproviders = os.path.join(incDir, "clrproviders.h") @@ -1143,7 +1143,8 @@ def main(argv): required.add_argument('--dummy', type=str,default=None, help='full path to file that will have dummy definitions of FireEtw functions') required.add_argument('--runtimeflavor', type=str,default="CoreCLR", - help='runtime flavor') + help='runtime flavor'), + required.add_argument('--targetos', type=str,default=None), required.add_argument('--nonextern', action='store_true', help='if specified, will not generated extern function stub headers' ) required.add_argument('--noxplatheader', action='store_true', @@ -1163,6 +1164,7 @@ def main(argv): extern = not args.nonextern write_xplatheader = not args.noxplatheader user_events = args.userevents + targetOS = args.targetos target_cpp = True if runtimeFlavor.mono: @@ -1172,7 +1174,7 @@ def main(argv): inclusion_list = parseInclusionList(inclusion_filename) - generatePlatformIndependentFiles(sClrEtwAllMan, incdir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, inclusion_list, user_events) + generatePlatformIndependentFiles(sClrEtwAllMan, incdir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, targetOS, inclusion_list, user_events) if __name__ == '__main__': return_code = main(sys.argv[1:]) diff --git a/src/coreclr/vm/eventing/CMakeLists.txt b/src/coreclr/vm/eventing/CMakeLists.txt index 861f50dc160c3a..a533a428fb8c0e 100644 --- a/src/coreclr/vm/eventing/CMakeLists.txt +++ b/src/coreclr/vm/eventing/CMakeLists.txt @@ -30,7 +30,7 @@ set(GENEVENTING_SCRIPT ${CLR_DIR}/scripts/genEventing.py) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventing_headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GENEVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} ${USEREVENTS_ARG} + COMMAND ${Python_EXECUTABLE} ${GENEVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --targetos ${CLR_CMAKE_TARGET_OS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} ${USEREVENTS_ARG} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventing_headers.timestamp DEPENDS ${EVENT_MANIFEST} ${GENEVENTING_SCRIPT} VERBATIM diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 9939ca18493173..66498e4f0d5c69 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -198,7 +198,7 @@ else() include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) append_extra_compression_libs(NATIVE_LIBS) - if (NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID) # no gssapi on tvOS, see https://developer.apple.com/documentation/gss + if (NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) # no gssapi on tvOS, see https://developer.apple.com/documentation/gss # Additional requirements for System.Net.Security.Native include(${CLR_SRC_NATIVE_DIR}/libs/System.Net.Security.Native/extra_libs.cmake) append_extra_security_libs(NATIVE_LIBS) @@ -208,7 +208,7 @@ else() include(${CLR_SRC_NATIVE_DIR}/libs/System.Native/extra_libs.cmake) append_extra_system_libs(NATIVE_LIBS) - if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID) + if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) # Additional requirements for System.Security.Cryptography.Native.OpenSsl include(${CLR_SRC_NATIVE_DIR}/libs/System.Security.Cryptography.Native/extra_libs.cmake) append_extra_cryptography_libs(NATIVE_LIBS) diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index 4bb50f98bb8b7c..944e791e1d7d02 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -13,7 +13,7 @@ $(ArtifactsObjDir)$(OutputRID).$(Configuration)\ $(ArtifactsObjDir)_version.h - $(ArtifactsObjDir)_version.c + $(ArtifactsObjDir)_version.c diff --git a/src/native/libs/build-native.cmd b/src/native/libs/build-native.cmd index 13e7334a73c534..5ccd7fe0a4230a 100644 --- a/src/native/libs/build-native.cmd +++ b/src/native/libs/build-native.cmd @@ -49,6 +49,7 @@ if /i [%1] == [icudir] ( set __icuDir=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [usepthreads] ( set __usePThreads=1&&shift&goto Arg_Loop) if /i [%1] == [-fsanitize] ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLR_CMAKE_ENABLE_SANITIZERS=$2"&&shift&&shift&goto Arg_Loop) +if /i [%1] == [-os] ( set __TargetOS=%2%&&shift&&shift&goto Arg_Loop) shift goto :Arg_Loop @@ -61,7 +62,11 @@ if NOT [%errorlevel%] == [0] goto :Failure echo Commencing build of native components echo. -call "%__engNativeDir%\version\copy_version_files.cmd" +if /i not "%__TargetOS%" == "android" ( + call "%__repoRoot%\eng\native\version\copy_version_files.cmd" +) else ( + call powershell -NoProfile -ExecutionPolicy ByPass -File "%__repoRoot%\eng\native\version\copy_version_files.ps1" +) :: cmake requires forward slashes in paths set __cmakeRepoRoot=%__repoRoot:\=/% @@ -100,6 +105,14 @@ set MSBUILD_EMPTY_PROJECT_CONTENT= ^ echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.props" echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.targets" +if /i "%__TargetOS%" == "android" ( + set __ExtraCmakeParams=%__ExtraCmakeParams% "-DANDROID_STL=none" +) + +if /i "%__TargetOS%" == "linux-bionic" ( + set __ExtraCmakeParams=%__ExtraCmakeParams% "-DFORCE_ANDROID_OPENSSL=1" "-DANDROID_STL=none" "-DANDROID_FORCE_ICU_DATA_DIR=1" +) + :: Regenerate the VS solution call "%__repoRoot%\eng\native\gen-buildsys.cmd" "%__sourceRootDir%" "%__IntermediatesDir%" %__VSVersion% %__BuildArch% %__TargetOS% %__ExtraCmakeParams% diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index 29b0e7f7efca5d..ab1f4a09033d8c 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -2,7 +2,7 @@ $(ArtifactsObjDir)_version.h - $(ArtifactsObjDir)_version.c + $(ArtifactsObjDir)_version.c .NET Runtime <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic @@ -73,6 +73,17 @@ + + + $(ArtifactsObjDir)_version.h + + + + + $(ArtifactsObjDir)_version.c + + + /// Scan android SDK for build tools (ignore preview versions) /// diff --git a/src/tasks/Common/AndroidSdkHelper.cs b/src/tasks/Common/AndroidSdkHelper.cs index e56e7d65699d2d..cc3dafc006b65b 100644 --- a/src/tasks/Common/AndroidSdkHelper.cs +++ b/src/tasks/Common/AndroidSdkHelper.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Linq; +using System.Runtime.InteropServices; internal sealed class AndroidSdkHelper { @@ -43,7 +44,7 @@ public AndroidSdkHelper( public string AndroidJarPath => Path.Combine(_androidSdkPath, "platforms", $"android-{_buildApiLevel}", "android.jar"); public bool HasD8 => File.Exists(D8Path); - public string D8Path => getToolPath("d8"); + public string D8Path => Utils.IsWindows() ? getToolPath("d8.bat") : getToolPath("d8"); public string DxPath => getToolPath("dx"); private string getToolPath(string tool) diff --git a/src/tasks/MobileBuildTasks/Android/AndroidProject.cs b/src/tasks/MobileBuildTasks/Android/AndroidProject.cs index a71c39add20b02..03cded62277e44 100644 --- a/src/tasks/MobileBuildTasks/Android/AndroidProject.cs +++ b/src/tasks/MobileBuildTasks/Android/AndroidProject.cs @@ -33,7 +33,7 @@ public AndroidProject(string projectName, string runtimeIdentifier, TaskLoggingH public AndroidProject(string projectName, string runtimeIdentifier, string androidNdkPath, TaskLoggingHelper logger) { - androidToolchainPath = Path.Combine(androidNdkPath, "build", "cmake", "android.toolchain.cmake"); + androidToolchainPath = Path.Combine(androidNdkPath, "build", "cmake", "android.toolchain.cmake").Replace('\\', '/'); abi = DetermineAbi(runtimeIdentifier); targetArchitecture = GetTargetArchitecture(runtimeIdentifier); From 6d4d71abcda75f0fe25e3ce3bde805e24d22a7d8 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 7 Feb 2025 12:30:30 -0500 Subject: [PATCH 2/9] Bring in Alex's appbuilder changes and note gen-buildsys.cmd in Directory.Build.props --- Directory.Build.props | 1 + eng/native/gen-buildsys.cmd | 2 +- .../sample/Android/AndroidSampleApp.csproj | 5 +- src/tasks/AndroidAppBuilder/ApkBuilder.cs | 132 ++++-------------- src/tasks/Common/AndroidSdkHelper.cs | 16 ++- src/tasks/Common/JavaCompiler.cs | 2 +- .../Android/AndroidProject.cs | 4 +- .../TestExclusionListTasks.csproj | 1 + 8 files changed, 50 insertions(+), 113 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 5eeb3ed7f86822..de425256609e38 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -56,6 +56,7 @@ Minimum target OS versions, keep in sync with: - eng/native/configurecompiler.cmake - eng/native/build-commons.sh + - eng/native/gen-buildsys.cmd - src/native/libs/build-native.sh - src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/MachObjectWriter.cs - src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 7ea24262015070..1aebdc826c4e09 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -88,7 +88,7 @@ if /i "%__Os%" == "android" ( exit /B 1 ) - set __ExtraCmakeParams=!__ExtraCmakeParams! "-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_ROOT:/=\%/build/cmake/android.toolchain.cmake" + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DCMAKE_TOOLCHAIN_FILE=""%ANDROID_NDK_ROOT:/=\%/build/cmake/android.toolchain.cmake""" set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_BUILD=1" "-C %__repoRoot%/eng/native/tryrun.cmake" "-DANDROID_CPP_FEATURES='no-rtti exceptions'" set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_PLATFORM=android-!__ANDROID_API_LEVEL!" "-DANDROID_NATIVE_API_LEVEL=!__ANDROID_API_LEVEL!" diff --git a/src/mono/sample/Android/AndroidSampleApp.csproj b/src/mono/sample/Android/AndroidSampleApp.csproj index 8917de08365c0e..c10a8ce68ed6e1 100644 --- a/src/mono/sample/Android/AndroidSampleApp.csproj +++ b/src/mono/sample/Android/AndroidSampleApp.csproj @@ -15,6 +15,9 @@ true <_UseAotDataFile Condition="'$(RunAOTCompilation)' == 'true'">false + $(DOTNET_ROOT)/dotnet + ..\..\..\..\dotnet.cmd + ../../../dotnet.sh @@ -28,7 +31,7 @@ Condition="'$(ArchiveTests)' != 'true' and '$(DeployAndRun)' == 'true'" AfterTargets="_AfterAndroidBuild" DependsOnTargets="$(AndroidBuildDependsOn)" > - + = MinApiLevel and BuildApiLevel >= TargetApiLevel // only if these api levels are not "preview" (not integers) - if (int.TryParse(BuildApiLevel, out int intApi)) + if (int.TryParse(androidSdkHelper.BuildApiLevel, out int intApi)) { if (int.TryParse(MinApiLevel, out int intMinApi) && intApi < intMinApi) { - throw new ArgumentException($"BuildApiLevel={BuildApiLevel} < MinApiLevel={MinApiLevel}. " + + throw new ArgumentException($"BuildApiLevel={androidSdkHelper.BuildApiLevel} < MinApiLevel={MinApiLevel}. " + "Make sure you've downloaded some recent build-tools in Android SDK"); } if (int.TryParse(TargetApiLevel, out int intTargetApi) && intApi < intTargetApi) { - throw new ArgumentException($"BuildApiLevel={BuildApiLevel} < TargetApiLevel={TargetApiLevel}. " + + throw new ArgumentException($"BuildApiLevel={androidSdkHelper.BuildApiLevel} < TargetApiLevel={TargetApiLevel}. " + "Make sure you've downloaded some recent build-tools in Android SDK"); } } - string buildToolsFolder = Path.Combine(AndroidSdk, "build-tools", BuildToolsVersion); - if (!Directory.Exists(buildToolsFolder)) - { - throw new ArgumentException($"{buildToolsFolder} was not found."); - } - if (!Enum.TryParse(RuntimeFlavor, true, out parsedRuntimeFlavor)) { throw new ArgumentException($"Unknown RuntimeFlavor value: {RuntimeFlavor}. '{nameof(RuntimeFlavor)}' must be one of: {string.Join(",", Enum.GetNames(typeof(RuntimeFlavorEnum)))}"); @@ -233,24 +222,15 @@ public ApkBuilder(TaskLoggingHelper logger) File.Copy(aotlib, Path.Combine(assetsToZipDirectory, Path.GetFileName(aotlib))); } - bool isWindows = Utils.IsWindows(); - // tools: - string dx = Path.Combine(buildToolsFolder, "dx"); - string d8 = Path.Combine(buildToolsFolder, isWindows ? "d8.bat" : "d8"); - string aapt = Path.Combine(buildToolsFolder, isWindows ? "aapt.exe" : "aapt"); - string zipalign = Path.Combine(buildToolsFolder, isWindows ? "zipalign.exe" : "zipalign"); - string apksigner = Path.Combine(buildToolsFolder, isWindows ? "apksigner.bat" : "apksigner"); - string androidJar = Path.Combine(AndroidSdk, "platforms", "android-" + BuildApiLevel, "android.jar"); + string androidJar = Path.Combine(AndroidSdk, "platforms", "android-" + androidSdkHelper.BuildApiLevel, "android.jar"); string androidToolchain = Path.Combine(AndroidNdk, "build", "cmake", "android.toolchain.cmake"); string javac = "javac"; - var (zip, zipArgs) = GetZipToolWithArgs(Path.Combine("..", "assets", "assets.zip")); - - Utils.RunProcess(logger, zip, workingDir: assetsToZipDirectory, args: zipArgs); + ZipFile.CreateFromDirectory(assetsToZipDirectory, Path.Combine(OutputDir, "assets", "assets.zip"), CompressionLevel.SmallestSize, includeBaseDirectory: false); Directory.Delete(assetsToZipDirectory, true); if (!File.Exists(androidJar)) - throw new ArgumentException($"API level={BuildApiLevel} is not downloaded in Android SDK"); + throw new ArgumentException($"API level={androidSdkHelper.BuildApiLevel} is not downloaded in Android SDK"); // 1. Build libmonodroid.so via cmake @@ -338,10 +318,10 @@ public ApkBuilder(TaskLoggingHelper logger) "monodroid-coreclr.c" : (IsLibraryMode) ? "monodroid-librarymode.c" : "monodroid.c"; string cmakeLists = Utils.GetEmbeddedResource("CMakeLists-android.txt") - .Replace("%RuntimeInclude%", runtimeHeaders) - .Replace("%NativeLibrariesToLink%", nativeLibraries) + .Replace("%RuntimeInclude%", NormalizePathToUnix(runtimeHeaders)) + .Replace("%NativeLibrariesToLink%", NormalizePathToUnix(nativeLibraries)) .Replace("%MONODROID_SOURCE%", monodroidSource) - .Replace("%AotSources%", aotSources) + .Replace("%AotSources%", NormalizePathToUnix(aotSources)) .Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.c") .Replace("%APP_LINKER_ARGS%", extraLinkerArgs.ToString()); @@ -430,25 +410,25 @@ public ApkBuilder(TaskLoggingHelper logger) Utils.RunProcess(logger, javac, javaCompilerArgs + javaActivityPath, workingDir: OutputDir); Utils.RunProcess(logger, javac, javaCompilerArgs + monoRunnerPath, workingDir: OutputDir); - if (File.Exists(d8)) + if (androidSdkHelper.HasD8) { string[] classFiles = Directory.GetFiles(Path.Combine(OutputDir, "obj"), "*.class", SearchOption.AllDirectories); if (classFiles.Length == 0) throw new InvalidOperationException("Didn't find any .class files"); - Utils.RunProcess(logger, d8, $"--no-desugaring {string.Join(" ", classFiles)}", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.D8Path, $"--no-desugaring {string.Join(" ", classFiles)}", workingDir: OutputDir); } else { - Utils.RunProcess(logger, dx, "--dex --output=classes.dex obj", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.DxPath, "--dex --output=classes.dex obj", workingDir: OutputDir); } // 3. Generate APK string debugModeArg = StripDebugSymbols ? string.Empty : "--debug-mode"; string apkFile = Path.Combine(OutputDir, "bin", $"{ProjectName}.unaligned.apk"); - Utils.RunProcess(logger, aapt, $"package -f -m -F {apkFile} -A assets -M AndroidManifest.xml -I {androidJar} {debugModeArg}", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.AaptPath, $"package -f -m -F {apkFile} -A assets -M AndroidManifest.xml -I {androidJar} {debugModeArg}", workingDir: OutputDir); var dynamicLibs = new List(); dynamicLibs.Add(Path.Combine(OutputDir, "monodroid", "libmonodroid.so")); @@ -505,9 +485,9 @@ public ApkBuilder(TaskLoggingHelper logger) // NOTE: we can run android-strip tool from NDK to shrink native binaries here even more. File.Copy(dynamicLib, Path.Combine(OutputDir, destRelative), true); - Utils.RunProcess(logger, aapt, $"add {apkFile} {destRelative}", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.AaptPath, $"add {apkFile} {NormalizePathToUnix(destRelative)}", workingDir: OutputDir); } - Utils.RunProcess(logger, aapt, $"add {apkFile} classes.dex", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.AaptPath, $"add {apkFile} classes.dex", workingDir: OutputDir); // Include prebuilt .dex files int sequence = 2; @@ -517,18 +497,18 @@ public ApkBuilder(TaskLoggingHelper logger) var classesFileName = $"classes{sequence++}.dex"; File.Copy(dexFile, Path.Combine(OutputDir, classesFileName)); logger.LogMessage(MessageImportance.High, $"Adding dex file {Path.GetFileName(dexFile)} as {classesFileName}"); - Utils.RunProcess(logger, aapt, $"add {apkFile} {classesFileName}", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.AaptPath, $"add {apkFile} {classesFileName}", workingDir: OutputDir); } // 4. Align APK string alignedApk = Path.Combine(OutputDir, "bin", $"{ProjectName}.apk"); - AlignApk(apkFile, alignedApk, zipalign); + AlignApk(apkFile, alignedApk, androidSdkHelper.ZipalignPath); // we don't need the unaligned one any more File.Delete(apkFile); // 5. Generate key (if needed) & sign the apk - SignApk(alignedApk, apksigner); + SignApk(alignedApk, androidSdkHelper.ApksignerPath); logger.LogMessage(MessageImportance.High, $"\nAPK size: {(new FileInfo(alignedApk).Length / 1000_000.0):0.#} Mb.\n"); @@ -568,21 +548,16 @@ public void ZipAndSignApk(string apkPath) if (string.IsNullOrEmpty(AndroidSdk) || !Directory.Exists(AndroidSdk)) throw new ArgumentException($"Android SDK='{AndroidSdk}' was not found or incorrect (can be set via ANDROID_SDK_ROOT envvar)."); - if (string.IsNullOrEmpty(BuildToolsVersion)) - BuildToolsVersion = GetLatestBuildTools(AndroidSdk); + AndroidSdkHelper androidSdkHelper = new AndroidSdkHelper(AndroidSdk, BuildApiLevel, BuildToolsVersion); if (string.IsNullOrEmpty(MinApiLevel)) MinApiLevel = DefaultMinApiLevel; - string buildToolsFolder = Path.Combine(AndroidSdk, "build-tools", BuildToolsVersion); - string zipalign = Path.Combine(buildToolsFolder, "zipalign"); - string apksigner = Path.Combine(buildToolsFolder, "apksigner"); - string alignedApkPath = $"{apkPath}.aligned"; - AlignApk(apkPath, alignedApkPath, zipalign); + AlignApk(apkPath, alignedApkPath, androidSdkHelper.ZipalignPath); logger.LogMessage(MessageImportance.High, $"\nMoving '{alignedApkPath}' to '{apkPath}'.\n"); File.Move(alignedApkPath, apkPath, overwrite: true); - SignApk(apkPath, apksigner); + SignApk(apkPath, androidSdkHelper.ApksignerPath); } public void ReplaceFileInApk(string file) @@ -593,16 +568,11 @@ public void ReplaceFileInApk(string file) if (string.IsNullOrEmpty(AndroidSdk) || !Directory.Exists(AndroidSdk)) throw new ArgumentException($"Android SDK='{AndroidSdk}' was not found or incorrect (can be set via ANDROID_SDK_ROOT envvar)."); - if (string.IsNullOrEmpty(BuildToolsVersion)) - BuildToolsVersion = GetLatestBuildTools(AndroidSdk); + AndroidSdkHelper androidSdkHelper = new AndroidSdkHelper(AndroidSdk, BuildApiLevel, BuildToolsVersion); if (string.IsNullOrEmpty(MinApiLevel)) MinApiLevel = DefaultMinApiLevel; - string buildToolsFolder = Path.Combine(AndroidSdk, "build-tools", BuildToolsVersion); - string aapt = Path.Combine(buildToolsFolder, "aapt"); - string apksigner = Path.Combine(buildToolsFolder, "apksigner"); - string apkPath; if (string.IsNullOrEmpty(ProjectName)) apkPath = Directory.GetFiles(Path.Combine(OutputDir, "bin"), "*.apk").First(); @@ -612,60 +582,16 @@ public void ReplaceFileInApk(string file) if (!File.Exists(apkPath)) throw new Exception($"{apkPath} was not found"); - Utils.RunProcess(logger, aapt, $"remove -v bin/{Path.GetFileName(apkPath)} {file}", workingDir: OutputDir); - Utils.RunProcess(logger, aapt, $"add -v bin/{Path.GetFileName(apkPath)} {file}", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.AaptPath, $"remove -v bin/{Path.GetFileName(apkPath)} {file}", workingDir: OutputDir); + Utils.RunProcess(logger, androidSdkHelper.AaptPath, $"add -v bin/{Path.GetFileName(apkPath)} {file}", workingDir: OutputDir); // we need to re-sign the apk - SignApk(apkPath, apksigner); - } - - private static (string, string) GetZipToolWithArgs(string destZipPath) - { - string zipTool; - string zipArgs; - - if (Utils.IsWindows()) - { - zipTool = "powershell"; - zipArgs = $"-C \"Compress-Archive -Path * -DestinationPath {destZipPath}\""; - } - else - { - zipTool = "zip"; - zipArgs = $"-q -r {destZipPath} ."; - } - - return (zipTool, zipArgs); - } - - /// - /// Scan android SDK for build tools (ignore preview versions) - /// - private static string GetLatestBuildTools(string androidSdkDir) - { - string? buildTools = Directory.GetDirectories(Path.Combine(androidSdkDir, "build-tools")) - .Select(Path.GetFileName) - .Where(file => !file!.Contains('-')) - .Select(file => { Version.TryParse(Path.GetFileName(file), out Version? version); return version; }) - .OrderByDescending(v => v) - .FirstOrDefault()?.ToString(); - - if (string.IsNullOrEmpty(buildTools)) - throw new ArgumentException($"Android SDK ({androidSdkDir}) doesn't contain build-tools."); - - return buildTools; + SignApk(apkPath, androidSdkHelper.ApksignerPath); } - /// - /// Scan android SDK for api levels (ignore preview versions) - /// - private static string GetLatestApiLevel(string androidSdkDir) + private static string NormalizePathToUnix(string path) { - return Directory.GetDirectories(Path.Combine(androidSdkDir, "platforms")) - .Select(file => int.TryParse(Path.GetFileName(file).Replace("android-", ""), out int apiLevel) ? apiLevel : -1) - .OrderByDescending(v => v) - .FirstOrDefault() - .ToString(); + return path.Replace("\\", "/"); } [GeneratedRegex(@"\.(\d)")] diff --git a/src/tasks/Common/AndroidSdkHelper.cs b/src/tasks/Common/AndroidSdkHelper.cs index cc3dafc006b65b..1d3a942001725a 100644 --- a/src/tasks/Common/AndroidSdkHelper.cs +++ b/src/tasks/Common/AndroidSdkHelper.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Linq; -using System.Runtime.InteropServices; internal sealed class AndroidSdkHelper { @@ -43,12 +42,17 @@ public AndroidSdkHelper( public string AndroidJarPath => Path.Combine(_androidSdkPath, "platforms", $"android-{_buildApiLevel}", "android.jar"); - public bool HasD8 => File.Exists(D8Path); - public string D8Path => Utils.IsWindows() ? getToolPath("d8.bat") : getToolPath("d8"); - public string DxPath => getToolPath("dx"); + public string BuildApiLevel => _buildApiLevel; - private string getToolPath(string tool) - => Path.Combine(_buildToolsPath, tool); + public bool HasD8 => File.Exists(D8Path); + public string D8Path => GetToolPath("d8", isBatToolOnWindows: true); + public string DxPath => GetToolPath("dx", isBatToolOnWindows: true); + public string AaptPath => GetToolPath("aapt"); + public string ZipalignPath => GetToolPath("zipalign"); + public string ApksignerPath => GetToolPath("apksigner", isBatToolOnWindows: true); + + private string GetToolPath(string tool, bool isBatToolOnWindows = false) + => Path.Combine(_buildToolsPath, tool + (Utils.IsWindows() && isBatToolOnWindows ? ".bat" : "")); /// /// Scan android SDK for api levels (ignore preview versions) diff --git a/src/tasks/Common/JavaCompiler.cs b/src/tasks/Common/JavaCompiler.cs index abeb7c6fd91556..235e7b9ee926c5 100644 --- a/src/tasks/Common/JavaCompiler.cs +++ b/src/tasks/Common/JavaCompiler.cs @@ -17,7 +17,7 @@ public JavaCompiler( string workingDir, string javaVersion = "1.8") { - _javaCompilerArgs = $"-classpath src -bootclasspath {androidSdk.AndroidJarPath} -source {javaVersion} -target {javaVersion}"; + _javaCompilerArgs = $"-classpath src -bootclasspath \"{androidSdk.AndroidJarPath}\" -source {javaVersion} -target {javaVersion}"; _workingDir = workingDir; _logger = logger; } diff --git a/src/tasks/MobileBuildTasks/Android/AndroidProject.cs b/src/tasks/MobileBuildTasks/Android/AndroidProject.cs index 03cded62277e44..9b0b6a9b2a3124 100644 --- a/src/tasks/MobileBuildTasks/Android/AndroidProject.cs +++ b/src/tasks/MobileBuildTasks/Android/AndroidProject.cs @@ -57,7 +57,9 @@ public void GenerateCMake(string workingDir, bool stripDebugSymbols) public void GenerateCMake(string workingDir, string apiLevel = DefaultMinApiLevel, bool stripDebugSymbols = false) { - string cmakeGenArgs = $"-DCMAKE_TOOLCHAIN_FILE={androidToolchainPath} -DANDROID_ABI=\"{Abi}\" -DANDROID_STL=none -DTARGETS_ANDROID=1 " + + // force ninja generator on Windows, the VS generator causes issues with the built-in Android support in VS + var generator = Utils.IsWindows() ? "-G Ninja" : ""; + string cmakeGenArgs = $"{generator} -DCMAKE_TOOLCHAIN_FILE={androidToolchainPath} -DANDROID_ABI=\"{Abi}\" -DANDROID_STL=none -DTARGETS_ANDROID=1 " + $"-DANDROID_PLATFORM=android-{apiLevel} -B {projectName}"; if (stripDebugSymbols) diff --git a/src/tasks/TestExclusionListTasks/TestExclusionListTasks.csproj b/src/tasks/TestExclusionListTasks/TestExclusionListTasks.csproj index e5148d3df97f26..ffc0d16e0ea031 100644 --- a/src/tasks/TestExclusionListTasks/TestExclusionListTasks.csproj +++ b/src/tasks/TestExclusionListTasks/TestExclusionListTasks.csproj @@ -11,6 +11,7 @@ + From 46427735162f5c9ab31f0063929df51a8ae446c2 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 7 Feb 2025 13:27:13 -0500 Subject: [PATCH 3/9] Note GenerateNativeVersionFile workaround --- src/coreclr/runtime-prereqs.proj | 6 ++++++ src/native/libs/build-native.proj | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/coreclr/runtime-prereqs.proj b/src/coreclr/runtime-prereqs.proj index e4d1b52f74bbae..a9b63fac2b4b6a 100644 --- a/src/coreclr/runtime-prereqs.proj +++ b/src/coreclr/runtime-prereqs.proj @@ -14,6 +14,12 @@ + + $(ArtifactsObjDir)_version.h diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index ab1f4a09033d8c..e3f9e73c3c0196 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -73,6 +73,11 @@ + $(ArtifactsObjDir)_version.h From 44b4fd55e1dd874698b3b856580e71e6bec0976b Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 7 Feb 2025 15:04:34 -0500 Subject: [PATCH 4/9] Make sure osx condition goes through for tryrun.cmake --- eng/native/tryrun.cmake | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index a818662677be7b..0b981ef3537707 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -34,7 +34,35 @@ if(NOT DEFINED ANDROID_BUILD) endif() endif() -if(DEFINED ANDROID_BUILD OR TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86|x64)$" OR FREEBSD OR ILLUMOS OR TIZEN OR HAIKU) +if(DARWIN AND NOT DEFINED ANDROID_BUILD) + if(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$") + set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1) + set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1) + set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1) + set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1) + set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) + set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0) + set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0) + set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0) + set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1) + set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 1) + set_cache_value(HAVE_PROCFS_CTL_EXITCODE 1) + set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1) + set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1) + set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1) + set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0) + set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0) + set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0) + set_cache_value(MMAP_ANON_IGNORES_PROTECTION_EXITCODE 1) + set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1) + set_cache_value(PTHREAD_CREATE_MODIFIES_ERRNO_EXITCODE 1) + set_cache_value(REALPATH_SUPPORTS_NONEXISTENT_FILES_EXITCODE 1) + set_cache_value(SEM_INIT_MODIFIES_ERRNO_EXITCODE 1) + set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1) + else() + message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!") + endif() +elseif(DEFINED ANDROID_BUILD OR TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86|x64)$" OR FREEBSD OR ILLUMOS OR TIZEN OR HAIKU) set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 0) set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 0) set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) @@ -82,34 +110,6 @@ if(DEFINED ANDROID_BUILD OR TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|lo elseif(ANDROID_BUILD) set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS 0) endif() -elseif(DARWIN) - if(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$") - set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1) - set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1) - set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1) - set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1) - set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) - set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0) - set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0) - set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0) - set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1) - set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 1) - set_cache_value(HAVE_PROCFS_CTL_EXITCODE 1) - set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1) - set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1) - set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1) - set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0) - set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0) - set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0) - set_cache_value(MMAP_ANON_IGNORES_PROTECTION_EXITCODE 1) - set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1) - set_cache_value(PTHREAD_CREATE_MODIFIES_ERRNO_EXITCODE 1) - set_cache_value(REALPATH_SUPPORTS_NONEXISTENT_FILES_EXITCODE 1) - set_cache_value(SEM_INIT_MODIFIES_ERRNO_EXITCODE 1) - set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1) - else() - message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!") - endif() elseif(NOT WIN32) message(FATAL_ERROR "Unsupported platform. OS: ${CMAKE_SYSTEM_NAME}, arch: ${TARGET_ARCH_NAME}") endif() From 778cb358852f60422517477d1482c4bc6b559d2c Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 7 Feb 2025 17:52:41 -0500 Subject: [PATCH 5/9] Bring back TARGET_ARCH_NAME as system.native in mono depends on it --- eng/native/build-commons.sh | 5 +---- eng/native/tryrun.cmake | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index bf17618d972ade..b27eae7765a0d3 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -86,10 +86,7 @@ build_native() exit 1 fi - # cmake cache scripts can't see command line args - export ANDROID_BUILD=1 - - cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs" + cmakeArgs="-DANDROID_BUILD=1 -C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs" cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} -DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} $cmakeArgs" # Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index 0b981ef3537707..2397f8dcc8f209 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -1,6 +1,21 @@ set(CROSS_ROOTFS $ENV{ROOTFS_DIR}) set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH}) +# Also allow building as Android without specifying `-cross`. +if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_BUILD) + if(ANDROID_ABI STREQUAL "arm64-v8a") + set(TARGET_ARCH_NAME "arm64") + elseif(ANDROID_ABI STREQUAL "x86_64") + set(TARGET_ARCH_NAME "x64") + elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(TARGET_ARCH_NAME "arm") + elseif(ANDROID_ABI STREQUAL "x86") + set(TARGET_ARCH_NAME "x86") + else() + message(FATAL_ERROR "ANDROID_ABI ${ANDROID_ABI} not recognized!") + endif() +endif() + macro(set_cache_value) set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE) set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE) From f125549e3da7835fedf8e90e9352b66ecce8a003 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Sat, 8 Feb 2025 15:03:58 -0500 Subject: [PATCH 6/9] Only care about targetos in event scripts when cross compiling --- src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt | 6 +++++- src/coreclr/scripts/genEventing.py | 4 ++++ src/coreclr/vm/eventing/CMakeLists.txt | 6 +++++- src/mono/mono/eventpipe/gen-eventing.cmake | 6 +++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index e7efe26147defd..9445fd4118c434 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -27,9 +27,13 @@ set (EventingHeaders ${GENERATED_INCLUDE_DIR}/clretwallmain.cpp ) +if(CROSS_COMPILING) + set(GEN_EVENTING_TARGETOS --targetos {CLR_CMAKE_TARGET_OS}) +endif() + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --inc ${EVENT_INCLUSION_FILE} --targetos ${CLR_CMAKE_TARGET_OS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h --runtimeflavor nativeaot ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} + COMMAND ${Python_EXECUTABLE} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --inc ${EVENT_INCLUSION_FILE} ${GEN_EVENTING_TARGETOS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h --runtimeflavor nativeaot ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp DEPENDS ${EVENT_MANIFEST} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} VERBATIM diff --git a/src/coreclr/scripts/genEventing.py b/src/coreclr/scripts/genEventing.py index 6a16459fbfe26c..9d39107c8b73b0 100644 --- a/src/coreclr/scripts/genEventing.py +++ b/src/coreclr/scripts/genEventing.py @@ -1166,6 +1166,10 @@ def main(argv): user_events = args.userevents targetOS = args.targetos + if targetOS is None: + if os.name == "nt": + targetOS = "windows" + target_cpp = True if runtimeFlavor.mono: extern = False diff --git a/src/coreclr/vm/eventing/CMakeLists.txt b/src/coreclr/vm/eventing/CMakeLists.txt index a533a428fb8c0e..bca2b8853d267d 100644 --- a/src/coreclr/vm/eventing/CMakeLists.txt +++ b/src/coreclr/vm/eventing/CMakeLists.txt @@ -28,9 +28,13 @@ endif() set(GENEVENTING_SCRIPT ${CLR_DIR}/scripts/genEventing.py) +if(CROSS_COMPILING) + set(GEN_EVENTING_TARGETOS --targetos {CLR_CMAKE_TARGET_OS}) +endif() + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventing_headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GENEVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --targetos ${CLR_CMAKE_TARGET_OS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} ${USEREVENTS_ARG} + COMMAND ${Python_EXECUTABLE} ${GENEVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} ${GEN_EVENTING_TARGETOS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} ${USEREVENTS_ARG} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventing_headers.timestamp DEPENDS ${EVENT_MANIFEST} ${GENEVENTING_SCRIPT} VERBATIM diff --git a/src/mono/mono/eventpipe/gen-eventing.cmake b/src/mono/mono/eventpipe/gen-eventing.cmake index e3421048114201..906aaeccc5d663 100644 --- a/src/mono/mono/eventpipe/gen-eventing.cmake +++ b/src/mono/mono/eventpipe/gen-eventing.cmake @@ -51,9 +51,13 @@ if(ENABLE_PERFTRACING) set(GEN_ETW_PROVIDER_COMMAND "") endif() + if(CROSS_COMPILING) + set(GEN_EVENTING_TARGETOS --targetos {CLR_CMAKE_TARGET_OS}) + endif() + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-gen-headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GEN_EVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${MONO_EVENTPIPE_GEN_INCLUDE_PATH} --inc ${EVENT_INCLUSION_FILE} --dummy ${MONO_EVENTPIPE_GEN_INCLUDE_PATH}/etmdummy.h --runtimeflavor mono ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} + COMMAND ${Python_EXECUTABLE} ${GEN_EVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${MONO_EVENTPIPE_GEN_INCLUDE_PATH} --inc ${EVENT_INCLUSION_FILE} ${GEN_EVENTING_TARGETOS} --dummy ${MONO_EVENTPIPE_GEN_INCLUDE_PATH}/etmdummy.h --runtimeflavor mono ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} COMMAND ${GEN_ETW_PROVIDER_COMMAND} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-gen-headers.timestamp DEPENDS ${GEN_EVENTING_SCRIPT} ${EVENT_MANIFEST} ${EVENT_EXCLUSION_FILE} From 4d250a42a9ffa775d57ca5376ece1fab3e87df57 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Sun, 9 Feb 2025 20:28:57 -0500 Subject: [PATCH 7/9] Rearrange cmake variable order and build more subsets --- eng/Subsets.props | 4 ++-- eng/native/gen-buildsys.cmd | 5 +++-- src/coreclr/build-runtime.cmd | 2 +- .../nativeaot/Runtime/eventpipe/CMakeLists.txt | 7 ++++--- src/coreclr/scripts/genEventing.py | 6 +++--- src/coreclr/vm/eventing/CMakeLists.txt | 7 ++++--- src/native/corehost/corehost.proj | 16 ++++++++++++++++ 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index 4e243d9458a3ce..08597ec63a3472 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -60,7 +60,7 @@ clr+mono+libs+tools+host+packs mono+libs+packs - clr.runtime+clr.alljits+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+mono+libs+host+packs + clr+mono+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+packs clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+libs+packs @@ -100,7 +100,7 @@ clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools+host.native clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools - clr.runtime+clr.alljits+clr.corelib+clr.nativecorelib+clr.tools+clr.packages + clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools clr.iltools+clr.packages diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 1aebdc826c4e09..c198ec33d05edb 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -88,8 +88,7 @@ if /i "%__Os%" == "android" ( exit /B 1 ) - set __ExtraCmakeParams=!__ExtraCmakeParams! "-DCMAKE_TOOLCHAIN_FILE=""%ANDROID_NDK_ROOT:/=\%/build/cmake/android.toolchain.cmake""" - set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_BUILD=1" "-C %__repoRoot%/eng/native/tryrun.cmake" "-DANDROID_CPP_FEATURES='no-rtti exceptions'" + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_BUILD=1" "-DANDROID_CPP_FEATURES='no-rtti exceptions'" set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_PLATFORM=android-!__ANDROID_API_LEVEL!" "-DANDROID_NATIVE_API_LEVEL=!__ANDROID_API_LEVEL!" if "%__Arch%" == "x64" ( @@ -104,6 +103,8 @@ if /i "%__Os%" == "android" ( if "%__Arch%" == "x64" ( set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=armeabi-v7a" ) + + set __ExtraCmakeParams=!__ExtraCmakeParams! "-DCMAKE_TOOLCHAIN_FILE='%ANDROID_NDK_ROOT:\=/%/build/cmake/android.toolchain.cmake'" "-C %__repoRoot%/eng/native/tryrun.cmake" ) :loop diff --git a/src/coreclr/build-runtime.cmd b/src/coreclr/build-runtime.cmd index af18fd9e7247e6..2406883a9d974f 100644 --- a/src/coreclr/build-runtime.cmd +++ b/src/coreclr/build-runtime.cmd @@ -381,7 +381,7 @@ if %__BuildNative% EQU 1 ( if /i not "%__HostOS%" == "%__TargetOS%" ( if /i "%__HostOS%" == "" ( - set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_TARGET_OS=%__TargetOS%" + set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_TARGET_ARCH=%__TargetArch%" "-DCLR_CMAKE_TARGET_OS=%__TargetOS%" ) ) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index 9445fd4118c434..6b55b13b76ae19 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -27,13 +27,14 @@ set (EventingHeaders ${GENERATED_INCLUDE_DIR}/clretwallmain.cpp ) -if(CROSS_COMPILING) - set(GEN_EVENTING_TARGETOS --targetos {CLR_CMAKE_TARGET_OS}) +if(CMAKE_CROSSCOMPILING) + set(GEN_EVENTING_TARGETOS --targetos) + set(GEN_EVENTING_TARGETOS_ARG ${CLR_CMAKE_TARGET_OS}) endif() add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --inc ${EVENT_INCLUSION_FILE} ${GEN_EVENTING_TARGETOS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h --runtimeflavor nativeaot ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} + COMMAND ${Python_EXECUTABLE} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} --inc ${EVENT_INCLUSION_FILE} ${GEN_EVENTING_TARGETOS} ${GEN_EVENTING_TARGETOS_ARG} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h --runtimeflavor nativeaot ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp DEPENDS ${EVENT_MANIFEST} ${GENERATE_PLAT_AGNOSTIC_SCRIPT} VERBATIM diff --git a/src/coreclr/scripts/genEventing.py b/src/coreclr/scripts/genEventing.py index 9d39107c8b73b0..e545f788d9baf4 100644 --- a/src/coreclr/scripts/genEventing.py +++ b/src/coreclr/scripts/genEventing.py @@ -467,7 +467,7 @@ def parseTemplateNodes(templateNodes): return allTemplates -def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, write_xplatheader, providerName, inclusionList, generatedFileType, user_events): +def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is_windows, write_xplatheader, providerName, inclusionList, generatedFileType, user_events): clrallEvents = [] for eventNode in eventNodes: eventName = eventNode.getAttribute('symbol') @@ -495,7 +495,7 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, wr clrallEvents.append("EventPipeEventEnabled" + eventName + "()") if runtimeFlavor.coreclr or write_xplatheader or runtimeFlavor.nativeaot: - if os.name == 'posix': + if not is_windows: if user_events and runtimeFlavor.coreclr: clrallEvents.append(" || UserEventsEventEnabled" + eventName + "()") # native AOT does not support non-windows eventing other than via event pipe @@ -929,7 +929,7 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventNodes = providerNode.getElementsByTagName('event') #vm header: - Clrallevents.write(generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, write_xplatheader, providerName, inclusion_list, generatedFileType, user_events)) + Clrallevents.write(generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is_windows, write_xplatheader, providerName, inclusion_list, generatedFileType, user_events)) providerName = providerNode.getAttribute('name') providerSymbol = providerNode.getAttribute('symbol') diff --git a/src/coreclr/vm/eventing/CMakeLists.txt b/src/coreclr/vm/eventing/CMakeLists.txt index bca2b8853d267d..d6879610e7a0d1 100644 --- a/src/coreclr/vm/eventing/CMakeLists.txt +++ b/src/coreclr/vm/eventing/CMakeLists.txt @@ -28,13 +28,14 @@ endif() set(GENEVENTING_SCRIPT ${CLR_DIR}/scripts/genEventing.py) -if(CROSS_COMPILING) - set(GEN_EVENTING_TARGETOS --targetos {CLR_CMAKE_TARGET_OS}) +if(CMAKE_CROSSCOMPILING) + set(GEN_EVENTING_TARGETOS --targetos) + set(GEN_EVENTING_TARGETOS_ARG ${CLR_CMAKE_TARGET_OS}) endif() add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventing_headers.timestamp - COMMAND ${Python_EXECUTABLE} ${GENEVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} ${GEN_EVENTING_TARGETOS} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} ${USEREVENTS_ARG} + COMMAND ${Python_EXECUTABLE} ${GENEVENTING_SCRIPT} --man ${EVENT_MANIFEST} --incdir ${GENERATED_INCLUDE_DIR} ${GEN_EVENTING_TARGETOS} ${GEN_EVENTING_TARGETOS_ARG} --dummy ${GENERATED_INCLUDE_DIR}/etmdummy.h ${NONEXTERN_ARG} ${NOXPLATHEADER_ARG} ${USEREVENTS_ARG} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventing_headers.timestamp DEPENDS ${EVENT_MANIFEST} ${GENEVENTING_SCRIPT} VERBATIM diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index 944e791e1d7d02..e9a581f3fb3b8a 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -91,6 +91,22 @@ + + + + $(ArtifactsObjDir)_version.h + + + + + $(ArtifactsObjDir)_version.c + + + Date: Mon, 10 Feb 2025 08:50:01 -0500 Subject: [PATCH 8/9] Cleanup genEventing --- src/coreclr/scripts/genEventing.py | 40 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/coreclr/scripts/genEventing.py b/src/coreclr/scripts/genEventing.py index e545f788d9baf4..b7439e2b4f7d68 100644 --- a/src/coreclr/scripts/genEventing.py +++ b/src/coreclr/scripts/genEventing.py @@ -467,7 +467,7 @@ def parseTemplateNodes(templateNodes): return allTemplates -def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is_windows, write_xplatheader, providerName, inclusionList, generatedFileType, user_events): +def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is_host_windows, write_xplatheader, providerName, inclusionList, generatedFileType, user_events): clrallEvents = [] for eventNode in eventNodes: eventName = eventNode.getAttribute('symbol') @@ -495,7 +495,7 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is clrallEvents.append("EventPipeEventEnabled" + eventName + "()") if runtimeFlavor.coreclr or write_xplatheader or runtimeFlavor.nativeaot: - if not is_windows: + if not is_host_windows: if user_events and runtimeFlavor.coreclr: clrallEvents.append(" || UserEventsEventEnabled" + eventName + "()") # native AOT does not support non-windows eventing other than via event pipe @@ -872,8 +872,7 @@ def getKeywordsMaskCombined(keywords, keywordsToMask): return mask -def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, clrallevents, inclusion_list, generatedFileType, user_events): - is_windows = targetOS == "windows" +def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, clrallevents, inclusion_list, generatedFileType, user_events): with open_for_update(clrallevents) as Clrallevents: Clrallevents.write(stdprolog) if generatedFileType=="header-impl": @@ -907,17 +906,17 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, Clrallevents.write('#endif\n\n') # define DOTNET_TRACE_CONTEXT depending on the platform - if is_windows and not runtimeFlavor.nativeaot: + if is_host_windows and not runtimeFlavor.nativeaot: Clrallevents.write(eventpipe_trace_context_typedef) # define EVENTPIPE_TRACE_CONTEXT if runtimeFlavor.coreclr or write_xplatheader: Clrallevents.write(dotnet_trace_context_typedef_windows + "\n") else: Clrallevents.write("\n") - if not is_windows and runtimeFlavor.coreclr: + if not is_host_windows and runtimeFlavor.coreclr: Clrallevents.write(user_events_trace_context_typedef) - if not is_windows and not write_xplatheader and not runtimeFlavor.nativeaot: + if not is_host_windows and not write_xplatheader and not runtimeFlavor.nativeaot: Clrallevents.write(eventpipe_trace_context_typedef) # define EVENTPIPE_TRACE_CONTEXT Clrallevents.write("\n") @@ -929,22 +928,22 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventNodes = providerNode.getElementsByTagName('event') #vm header: - Clrallevents.write(generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is_windows, write_xplatheader, providerName, inclusion_list, generatedFileType, user_events)) + Clrallevents.write(generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, is_host_windows, write_xplatheader, providerName, inclusion_list, generatedFileType, user_events)) providerName = providerNode.getAttribute('name') providerSymbol = providerNode.getAttribute('symbol') eventpipeProviderCtxName = providerSymbol + "_EVENTPIPE_Context" - if is_windows and not (write_xplatheader or runtimeFlavor.nativeaot): + if is_host_windows and not (write_xplatheader or runtimeFlavor.nativeaot): Clrallevents.write(('constexpr ' if target_cpp else 'static const ') + 'EVENTPIPE_TRACE_CONTEXT ' + eventpipeProviderCtxName + ' = { W("' + providerName + '"), 0, false, 0 };\n') - if not is_windows and not write_xplatheader and not runtimeFlavor.nativeaot: + if not is_host_windows and not write_xplatheader and not runtimeFlavor.nativeaot: Clrallevents.write('__attribute__((weak)) EVENTPIPE_TRACE_CONTEXT ' + eventpipeProviderCtxName + ' = { W("' + providerName + '"), 0, false, 0 };\n') if generatedFileType == "header": Clrallevents.write("#endif // __CLR_ETW_ALL_MAIN_H__\n") -def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, targetOS, inclusion_list, user_events): +def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, inclusion_list, user_events): generateEtmDummyHeader(sClrEtwAllMan,etmDummyFile) tree = DOM.parse(sClrEtwAllMan) @@ -1014,16 +1013,14 @@ def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern #endif // DOTNET_TRACE_CONTEXT_DEF """ - is_windows = targetOS == "windows" - # Write the main source(s) for FireETW* functions # nativeaot requires header and source file to be separated as well as a noop implementation if runtimeFlavor.nativeaot: - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.cpp"), inclusion_list, "source-impl", user_events) - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header", user_events) - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "disabledclretwallmain.cpp"), inclusion_list, "source-impl-noop", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.cpp"), inclusion_list, "source-impl", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "disabledclretwallmain.cpp"), inclusion_list, "source-impl-noop", user_events) else: - updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, targetOS, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header-impl", user_events) + updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, eventpipe_trace_context_typedef, dotnet_trace_context_typedef_windows, user_events_trace_context_typedef, tree, os.path.join(incDir, "clretwallmain.h"), inclusion_list, "header-impl", user_events) if write_xplatheader: clrproviders = os.path.join(incDir, "clrproviders.h") @@ -1035,7 +1032,7 @@ def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern ULONGLONG const Keyword; } EVENT_DESCRIPTOR; """) - if not is_windows and not runtimeFlavor.nativeaot: + if not is_host_windows and not runtimeFlavor.nativeaot: Clrproviders.write(eventpipe_trace_context_typedef) # define EVENTPIPE_TRACE_CONTEXT Clrproviders.write(lttng_trace_context_typedef) # define LTTNG_TRACE_CONTEXT Clrproviders.write(user_events_trace_context_typedef) @@ -1050,7 +1047,7 @@ def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern providerSymbol = str(providerNode.getAttribute('symbol')) nbProviders += 1 nbKeywords = 0 - if not is_windows and not runtimeFlavor.nativeaot: + if not is_host_windows and not runtimeFlavor.nativeaot: eventpipeProviderCtxName = providerSymbol + "_EVENTPIPE_Context" Clrproviders.write('__attribute__((weak)) EVENTPIPE_TRACE_CONTEXT ' + eventpipeProviderCtxName + ' = { W("' + providerName + '"), 0, false, 0 };\n') lttngProviderCtxName = providerSymbol + "_LTTNG_Context" @@ -1077,7 +1074,7 @@ def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern allProviders.append("&" + providerSymbol + "_LTTNG_Context") # define and initialize runtime providers' DOTNET_TRACE_CONTEXT depending on the platform - if not is_windows and not runtimeFlavor.nativeaot: + if not is_host_windows and not runtimeFlavor.nativeaot: Clrproviders.write('#define NB_PROVIDERS ' + str(nbProviders) + '\n') Clrproviders.write(('constexpr ' if target_cpp else 'static const ') + 'LTTNG_TRACE_CONTEXT * ALL_LTTNG_PROVIDERS_CONTEXT[NB_PROVIDERS] = { ') Clrproviders.write(', '.join(allProviders)) @@ -1170,6 +1167,7 @@ def main(argv): if os.name == "nt": targetOS = "windows" + is_host_windows = targetOS == "windows" target_cpp = True if runtimeFlavor.mono: extern = False @@ -1178,7 +1176,7 @@ def main(argv): inclusion_list = parseInclusionList(inclusion_filename) - generatePlatformIndependentFiles(sClrEtwAllMan, incdir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, targetOS, inclusion_list, user_events) + generatePlatformIndependentFiles(sClrEtwAllMan, incdir, etmDummyFile, extern, write_xplatheader, target_cpp, runtimeFlavor, is_host_windows, inclusion_list, user_events) if __name__ == '__main__': return_code = main(sys.argv[1:]) From ef6f8870862030cc1c525bed8f1b237e13c3687c Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 10 Feb 2025 15:48:36 -0500 Subject: [PATCH 9/9] Update src/coreclr/generateredefinesfile.ps1 Co-authored-by: Jeremy Koritzinsky --- src/coreclr/generateredefinesfile.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/generateredefinesfile.ps1 b/src/coreclr/generateredefinesfile.ps1 index aedc41510a7355..1a37c661d0c5cd 100644 --- a/src/coreclr/generateredefinesfile.ps1 +++ b/src/coreclr/generateredefinesfile.ps1 @@ -32,9 +32,9 @@ Get-Content $filename | ForEach-Object { # Only process the entries that begin with "#" if ($line -match '^#.*$') { $line = $line -replace '^#', '' - Write-Host "LEAF_ENTRY ${prefix1}${line}, _TEXT" - Write-Host " ${jump} EXTERNAL_C_FUNC(${prefix2}${line})" - Write-Host "LEAF_END ${prefix1}${line}, _TEXT" - Write-Host "" + Write-Output "LEAF_ENTRY ${prefix1}${line}, _TEXT" + Write-Output " ${jump} EXTERNAL_C_FUNC(${prefix2}${line})" + Write-Output "LEAF_END ${prefix1}${line}, _TEXT" + Write-Output "" } }