Skip to content

Commit

Permalink
Cross-compile Wasm cross-compilers for ARM64 machines (#74428)
Browse files Browse the repository at this point in the history
This change enables building arbitrary cross-compilers for non-x64 hosts. Right now, only osx-arm64->browser-wasm and linux-arm64->browser-wasm are actually enabled, as runtime bugs prevent us from building any arm64->x86 or arm64->x64 cross-compilers. Getting this framework in will unblock workload work related to "native" wasm on M1 Mac.

== BREAKING CHANGE FOR DEVELOPERS ==
MonoAOTLLVMDir no longer exists.

Old:
`/p:MonoLLVMDir=/path/to/llvm` specifies the directory with LLVM binaries compiled for `$(TargetArchitecture)`, for compiling the Mono JIT on that target architecture
`/p:MonoAOTLLVMDir=/path/to/llvm` specifies the directory with LLVM binaries compiled for `$(BuildArchitecture)`, for compiling the mono-aot-cross executable
```

New:
`/p:MonoLLVMDir=/path/to/llvm` specifies a parent-level directory with LLVM binaries compiled for relevant architectures - e.g. `$(MonoLLVMDir)\x64` contains LLVM built for `x64`, current OS. `$(MonoLLVMDir)\arm64 contains LLVM built for arm64`, current OS.

You do not need to specify `/p:MonoLLVMDir=` manually, unless you are a developer who may be using custom, non-nupkg LLVM.

This change is necessary to stop hardcoding the assumptions that a) `$(BuildArchitecture)` is always `x64` and b) AOT binaries should be compiled for $(BuildArchitecture)

Closes: #74175
  • Loading branch information
directhex committed Jan 5, 2023
1 parent 1928cd2 commit 81724f1
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 112 deletions.
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<DefaultNativeAotSubsets>clr.alljits+clr.tools+clr.nativeaotlibs+clr.nativeaotruntime</DefaultNativeAotSubsets>

<DefaultMonoSubsets Condition="'$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(MonoAOTEnableLLVM)' == 'true' and '$(MonoAOTLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(MonoAOTEnableLLVM)' == 'true' and '$(MonoLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(TargetOS)' == 'Browser'">$(DefaultMonoSubsets)mono.wasmruntime+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(TargetOS)' == 'wasi'">$(DefaultMonoSubsets)mono.wasiruntime+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(MonoCrossAOTTargetOS)' != ''">$(DefaultMonoSubsets)mono.aotcross+</DefaultMonoSubsets>
Expand Down
8 changes: 8 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@
<Uri>https://github.com/dotnet/llvm-project</Uri>
<Sha>ec1fd7b45b2751ce9abf204b03871f471b903609</Sha>
</Dependency>
<Dependency Name="runtime.osx-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk" Version="14.0.0-alpha.1.22626.2">
<Uri>https://github.com/dotnet/llvm-project</Uri>
<Sha>ec1fd7b45b2751ce9abf204b03871f471b903609</Sha>
</Dependency>
<Dependency Name="runtime.osx-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools" Version="14.0.0-alpha.1.22626.2">
<Uri>https://github.com/dotnet/llvm-project</Uri>
<Sha>ec1fd7b45b2751ce9abf204b03871f471b903609</Sha>
</Dependency>
<Dependency Name="runtime.osx-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk" Version="14.0.0-alpha.1.22626.2">
<Uri>https://github.com/dotnet/llvm-project</Uri>
<Sha>ec1fd7b45b2751ce9abf204b03871f471b903609</Sha>
Expand Down
2 changes: 2 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
<runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>14.0.0-alpha.1.22626.2</runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
<runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>14.0.0-alpha.1.22626.2</runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
<runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>14.0.0-alpha.1.22626.2</runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
<runtimeosxarm64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>14.0.0-alpha.1.22626.2</runtimeosxarm64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
<runtimeosxarm64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>14.0.0-alpha.1.22626.2</runtimeosxarm64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
<runtimeosxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>14.0.0-alpha.1.22626.2</runtimeosxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
<runtimeosxx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>14.0.0-alpha.1.22626.2</runtimeosxx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
<!-- emscripten / Node -->
Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/common/evaluate-default-paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ jobs:
- eng/Versions.props
- eng/testing/scenarios/BuildWasmAppsJobsList.txt
- eng/testing/workloads-testing.targets
- src/installer/pkg/sfx/Microsoft.NETCore.App/*
- src/libraries/sendtohelix*
- src/libraries/System.Net.WebSockets.Client/*
- src/libraries/System.Runtime.InteropServices/*
- src/libraries/System.Runtime.InteropServices.JavaScript/*
- src/mono/mono/*
- src/mono/monoaotcross.proj
- src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/*
- src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/*
- src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/*
Expand Down
42 changes: 42 additions & 0 deletions eng/pipelines/runtime-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@ extends:
extraStepsParameters:
name: MonoRuntimePacks

- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
runtimeFlavor: mono
buildConfig: release
platforms:
- Linux_arm64
jobParameters:
buildArgs: -s mono+packs -c $(_BuildConfig)
/p:MonoCrossAOTTargetOS=Browser /p:SkipMonoCrossJitConfigure=true /p:BuildMonoAOTCrossCompilerOnly=true
nameSuffix: CrossAOT_Mono
runtimeVariant: crossaot
dependsOn:
- mono_browser_offsets
monoCrossAOTTargetOS:
- Browser
isOfficialBuild: ${{ variables.isOfficialBuild }}
extraStepsTemplate: /eng/pipelines/common/upload-intermediate-artifacts-step.yml
extraStepsParameters:
name: MonoRuntimePacks

- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
Expand Down Expand Up @@ -269,6 +290,27 @@ extends:
extraStepsParameters:
name: MonoRuntimePacks

- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
runtimeFlavor: mono
buildConfig: release
platforms:
- OSX_arm64
jobParameters:
buildArgs: -s mono+packs -c $(_BuildConfig)
/p:MonoCrossAOTTargetOS=Browser /p:SkipMonoCrossJitConfigure=true /p:BuildMonoAOTCrossCompilerOnly=true
nameSuffix: CrossAOT_Mono
runtimeVariant: crossaot
dependsOn:
- mono_browser_offsets
monoCrossAOTTargetOS:
- Browser
isOfficialBuild: ${{ variables.isOfficialBuild }}
extraStepsTemplate: /eng/pipelines/common/upload-intermediate-artifacts-step.yml
extraStepsParameters:
name: MonoRuntimePacks

#
# Build Mono LLVM runtime packs
#
Expand Down
32 changes: 26 additions & 6 deletions eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ extends:
buildConfig: release
platforms:
- Android_x64
#- Browser_wasm - unused
- Browser_wasm
- tvOS_arm64
- iOS_arm64
- MacCatalyst_x64
Expand Down Expand Up @@ -670,10 +670,10 @@ extends:
runtimeVariant: crossaot
dependsOn:
- mono_android_offsets
#- mono_browser_offsets - unused
- mono_browser_offsets
monoCrossAOTTargetOS:
- Android
#- Browser - unused
- Browser
condition: >-
or(
eq(dependencies.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
Expand All @@ -691,19 +691,39 @@ extends:
runtimeVariant: crossaot
dependsOn:
- mono_android_offsets
#- mono_browser_offsets - unused
- mono_browser_offsets
- mono_tvos_offsets
- mono_ios_offsets
- mono_maccatalyst_offsets
monoCrossAOTTargetOS:
- Android
#- Browser - unused
- Browser
- tvOS
- iOS
- MacCatalyst
condition: >-
or(
eq(dependencies.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
eq(dependencies.evaluate_paths.outputs['SetPathVars_mono.containsChange'], true),
eq(dependencies.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
eq(variables['isRollingBuild'], true))
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/mono/templates/build-job.yml
runtimeFlavor: mono
buildConfig: release
platforms:
- Linux_arm64
- OSX_arm64
jobParameters:
runtimeVariant: crossaot
dependsOn:
- mono_browser_offsets
monoCrossAOTTargetOS:
- Browser
condition: >-
or(
eq(dependencies.evaluate_paths.outputs['SetPathVars_mono.containsChange'], true),
eq(dependencies.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
eq(variables['isRollingBuild'], true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OverridePackageId>Microsoft.NETCore.App.Runtime.AOT.$(RuntimeIdentifier).Cross.$(TargetCrossRid)</OverridePackageId>
<ArchiveName>dotnet-monocrossaot</ArchiveName>
<SharedFrameworkHostFileNameOverride>monocrossaot</SharedFrameworkHostFileNameOverride>
<RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;linux-arm64;osx-x64;osx-arm64;win-x64</RuntimeIdentifiers>
<GenerateInstallers>false</GenerateInstallers>
<PublishReadyToRun>false</PublishReadyToRun>
<HostJsonTargetPath>tools/</HostJsonTargetPath>
Expand Down
92 changes: 38 additions & 54 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -564,71 +564,55 @@ if(LLVM_PREFIX)
message(FATAL_ERROR "FIXME: ${TARGET_ARCH}")
endif()

if(CMAKE_CROSSCOMPILING)
# Can't run llvm-config, hardcode results
set(llvm_config_path "${LLVM_PREFIX}/include/llvm/Config/llvm-config.h")

# llvm-config --mono-api-version
file(STRINGS ${llvm_config_path} llvm_api_version_line REGEX "MONO_API_VERSION ")
string(REGEX REPLACE ".*MONO_API_VERSION ([0-9]+)" "\\1" llvm_api_version ${llvm_api_version_line})

# llvm-config --libs analysis core bitwriter mcjit orcjit
set(MONO_llvm_core_libs "LLVMOrcJIT" "LLVMPasses" "LLVMCoroutines" "LLVMipo" "LLVMInstrumentation" "LLVMVectorize" "LLVMScalarOpts" "LLVMLinker" "LLVMIRReader" "LLVMAsmParser" "LLVMInstCombine" "LLVMFrontendOpenMP" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMJITLink" "LLVMMCJIT" "LLVMExecutionEngine" "LLVMTarget" "LLVMRuntimeDyld" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMBinaryFormat" "LLVMSupport" "LLVMDemangle")
if(${llvm_api_version} LESS 1200)
set(MONO_llvm_core_libs ${MONO_llvm_core_libs} "LLVMOrcError" "LLVMDebugInfoMSF")
else()
set(MONO_llvm_core_libs ${MONO_llvm_core_libs} "LLVMObjCARCOpts" "LLVMMCDisassembler" "LLVMOrcTargetProcess" "LLVMOrcShared" "LLVMDebugInfoDWARF")
endif()

# llvm-config --libs x86codegen
set(MONO_llvm_extra_libs_x86codegen "LLVMX86CodeGen" "LLVMCFGuard" "LLVMGlobalISel" "LLVMX86Desc" "LLVMX86Info" "LLVMMCDisassembler" "LLVMSelectionDAG" "LLVMAsmPrinter" "LLVMDebugInfoDWARF" "LLVMCodeGen" "LLVMTarget" "LLVMScalarOpts" "LLVMInstCombine" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMDebugInfoMSF" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMBinaryFormat" "LLVMSupport" "LLVMDemangle")
set(llvm_config_path "${LLVM_PREFIX}/include/llvm/Config/llvm-config.h")

# llvm-config --libs armcodegen
set(MONO_llvm_extra_libs_armcodegen "LLVMARMCodeGen" "LLVMCFGuard" "LLVMGlobalISel" "LLVMSelectionDAG" "LLVMAsmPrinter" "LLVMDebugInfoDWARF" "LLVMCodeGen" "LLVMTarget" "LLVMScalarOpts" "LLVMInstCombine" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMARMDesc" "LLVMMCDisassembler" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMDebugInfoMSF" "LLVMBinaryFormat" "LLVMARMUtils" "LLVMARMInfo" "LLVMSupport" "LLVMDemangle")
# llvm-config --mono-api-version
file(STRINGS ${llvm_config_path} llvm_api_version_line REGEX "MONO_API_VERSION ")
string(REGEX REPLACE ".*MONO_API_VERSION ([0-9]+)" "\\1" llvm_api_version ${llvm_api_version_line})

# llvm-config --libs aarch64codegen
set(MONO_llvm_extra_libs_aarch64codegen "LLVMAArch64CodeGen" "LLVMCFGuard" "LLVMGlobalISel" "LLVMSelectionDAG" "LLVMAsmPrinter" "LLVMDebugInfoDWARF" "LLVMCodeGen" "LLVMTarget" "LLVMScalarOpts" "LLVMInstCombine" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMAArch64Desc" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMDebugInfoMSF" "LLVMBinaryFormat" "LLVMAArch64Utils" "LLVMAArch64Info" "LLVMSupport" "LLVMDemangle")
# llvm-config --libs analysis core bitwriter mcjit orcjit
set(MONO_llvm_core_libs "LLVMOrcJIT" "LLVMPasses" "LLVMCoroutines" "LLVMipo" "LLVMInstrumentation" "LLVMVectorize" "LLVMScalarOpts" "LLVMLinker" "LLVMIRReader" "LLVMAsmParser" "LLVMInstCombine" "LLVMFrontendOpenMP" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMJITLink" "LLVMMCJIT" "LLVMExecutionEngine" "LLVMTarget" "LLVMRuntimeDyld" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMBinaryFormat" "LLVMSupport" "LLVMDemangle")
if(${llvm_api_version} LESS 1200)
set(MONO_llvm_core_libs ${MONO_llvm_core_libs} "LLVMOrcError" "LLVMDebugInfoMSF")
else()
set(MONO_llvm_core_libs ${MONO_llvm_core_libs} "LLVMObjCARCOpts" "LLVMMCDisassembler" "LLVMOrcTargetProcess" "LLVMOrcShared" "LLVMDebugInfoDWARF")
endif()

# llvm-config --libs x86codegen
set(MONO_llvm_extra_libs_x86codegen "LLVMX86CodeGen" "LLVMCFGuard" "LLVMGlobalISel" "LLVMX86Desc" "LLVMX86Info" "LLVMMCDisassembler" "LLVMSelectionDAG" "LLVMAsmPrinter" "LLVMDebugInfoDWARF" "LLVMCodeGen" "LLVMTarget" "LLVMScalarOpts" "LLVMInstCombine" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMDebugInfoMSF" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMBinaryFormat" "LLVMSupport" "LLVMDemangle")

# llvm-config --cflags
set(llvm_cflags "")
set(llvm_cxxflags "")
set(llvm_includedir "${LLVM_PREFIX}/include")
# llvm-config --libs armcodegen
set(MONO_llvm_extra_libs_armcodegen "LLVMARMCodeGen" "LLVMCFGuard" "LLVMGlobalISel" "LLVMSelectionDAG" "LLVMAsmPrinter" "LLVMDebugInfoDWARF" "LLVMCodeGen" "LLVMTarget" "LLVMScalarOpts" "LLVMInstCombine" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMARMDesc" "LLVMMCDisassembler" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMDebugInfoMSF" "LLVMBinaryFormat" "LLVMARMUtils" "LLVMARMInfo" "LLVMSupport" "LLVMDemangle")

# llvm-config --system-libs
set(llvm_system_libs "-lz" "-lrt" "-ldl" "-lpthread" "-lm")
# llvm-config --libs aarch64codegen
set(MONO_llvm_extra_libs_aarch64codegen "LLVMAArch64CodeGen" "LLVMCFGuard" "LLVMGlobalISel" "LLVMSelectionDAG" "LLVMAsmPrinter" "LLVMDebugInfoDWARF" "LLVMCodeGen" "LLVMTarget" "LLVMScalarOpts" "LLVMInstCombine" "LLVMAggressiveInstCombine" "LLVMTransformUtils" "LLVMBitWriter" "LLVMAnalysis" "LLVMProfileData" "LLVMObject" "LLVMTextAPI" "LLVMMCParser" "LLVMBitReader" "LLVMCore" "LLVMRemarks" "LLVMBitstreamReader" "LLVMAArch64Desc" "LLVMMC" "LLVMDebugInfoCodeView" "LLVMDebugInfoMSF" "LLVMBinaryFormat" "LLVMAArch64Utils" "LLVMAArch64Info" "LLVMSupport" "LLVMDemangle")

# llvm-config --libs analysis core bitwriter mcjit orcjit
set(llvm_core_libs ${MONO_llvm_core_libs})
# llvm-config --cflags
set(llvm_cflags "-I${LLVM_PREFIX}/include -D__STDC_CONSTANT_MACROS -D__STD_FORMAT_MACROS -D__STDC_LIMIT_MACROS")
set(llvm_cxxflags "-I${LLVM_PREFIX}/include -std=c++14 -fno-exceptions -fno-rtti -D__STDC_CONSTANT_MACROS -D__STD_FORMAT_MACROS -D__STDC_LIMIT_MACROS")
set(llvm_includedir "${LLVM_PREFIX}/include")

# Check codegen libs and add needed libraries.
set(llvm_extra ${MONO_llvm_extra_libs_${llvm_codegen_libs}})
if("${llvm_extra}" STREQUAL "")
message(FATAL_ERROR "FIXME: ${TARGET_ARCH}")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# llvm-config --system-libs
set(llvm_system_libs "-lz" "-lrt" "-ldl" "-lpthread" "-lm")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# llvm-config --system-libs
set(llvm_system_libs "-lz" "-lm")
endif()

set(llvm_libs ${llvm_core_libs} ${llvm_extra})
list(TRANSFORM llvm_libs PREPEND "${LLVM_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}")
list(TRANSFORM llvm_libs APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}")
else()
set(LLVM_CONFIG ${LLVM_PREFIX}/bin/llvm-config${EXE_SUFFIX})
if (NOT EXISTS ${LLVM_CONFIG})
message(FATAL_ERROR "LLVM executable '${LLVM_CONFIG}' not found.")
endif()
# llvm-config --libs analysis core bitwriter mcjit orcjit
set(llvm_core_libs ${MONO_llvm_core_libs})

execute_process(COMMAND ${LLVM_CONFIG} --mono-api-version RESULT_VARIABLE llvm_config_res OUTPUT_VARIABLE llvm_api_version OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT ${llvm_config_res} EQUAL 0)
message(FATAL_ERROR "'${LLVM_CONFIG} --mono-api-version' failed. Use the llvm fork at https://github.com/dotnet/llvm-project.")
endif()
execute_process(COMMAND ${LLVM_CONFIG} --cflags OUTPUT_VARIABLE llvm_cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --cxxflags OUTPUT_VARIABLE llvm_cxxflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --includedir OUTPUT_VARIABLE llvm_includedir OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE llvm_system_libs_space_separated OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --libfiles analysis core bitwriter mcjit orcjit ${llvm_codegen_libs} OUTPUT_VARIABLE llvm_libs_space_separated OUTPUT_STRIP_TRAILING_WHITESPACE)
separate_arguments(llvm_system_libs NATIVE_COMMAND ${llvm_system_libs_space_separated})
separate_arguments(llvm_libs NATIVE_COMMAND ${llvm_libs_space_separated})
# Check codegen libs and add needed libraries.
set(llvm_extra ${MONO_llvm_extra_libs_${llvm_codegen_libs}})
if("${llvm_extra}" STREQUAL "" AND NOT "${TARGET_ARCH}" STREQUAL "wasm")
message(FATAL_ERROR "FIXME: ${TARGET_ARCH}")
endif()

set(llvm_libs ${llvm_core_libs} ${llvm_extra})
list(TRANSFORM llvm_libs PREPEND "${LLVM_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}")
list(TRANSFORM llvm_libs APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}")

if (${llvm_api_version} LESS 1100)
message(FATAL_ERROR "LLVM version too old.")
endif()
Expand Down
6 changes: 2 additions & 4 deletions src/mono/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@
<MonoAOTEnableLLVM Condition="'$(TargetsMacCatalyst)' == 'true'">true</MonoAOTEnableLLVM>
<MonoAOTEnableLLVM Condition="'$(TargetsBrowser)' == 'true'">true</MonoAOTEnableLLVM>
<MonoAOTEnableLLVM Condition="'$(TargetsAndroid)' == 'true'">true</MonoAOTEnableLLVM>
<_MonoUseLLVMPackage Condition="'$(MonoLLVMDir)' == '' and '$(MonoEnableLLVM)' == 'true'">true</_MonoUseLLVMPackage>
<_MonoUseAOTLLVMPackage Condition="'$(MonoAOTLLVMDir)' == '' and '$(MonoAOTEnableLLVM)' == 'true'">true</_MonoUseAOTLLVMPackage>
<MonoLLVMDir Condition="'$(MonoLLVMDir)' == '' and '$(MonoEnableLLVM)' == 'true'">$([MSBuild]::NormalizeDirectory('$(MonoObjDir)', 'llvm'))</MonoLLVMDir>
<MonoAOTLLVMDir Condition="'$(MonoAOTLLVMDir)' == '' and '$(MonoAOTEnableLLVM)' == 'true'">$([MSBuild]::NormalizeDirectory('$(MonoObjDir)', 'cross', 'llvm'))</MonoAOTLLVMDir>
<_MonoUseLLVMPackage Condition="'$(MonoLLVMDir)' == '' and ('$(MonoEnableLLVM)' == 'true' or $(MonoAOTEnableLLVM) == 'true')">true</_MonoUseLLVMPackage>
<MonoLLVMDir Condition="'$(MonoLLVMDir)' == '' or '$(_MonoUseLLVMPackage)' == 'true'">$([MSBuild]::NormalizeDirectory('$(MonoObjDir)', 'llvm'))</MonoLLVMDir>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading

0 comments on commit 81724f1

Please sign in to comment.