Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cross-compile Wasm cross-compilers for ARM64 machines #74428

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c00ffb7
Initial changes.
directhex Aug 22, 2022
714f344
Rearchitect LLVM package inclusion, so cross-compiled cross-compilers…
directhex Aug 22, 2022
452bce6
Offsets tool should use host arch libclang
directhex Aug 23, 2022
52b4fba
Fix Wasm
directhex Aug 23, 2022
66e5a15
Add debug output to llvm-init.proj
directhex Aug 23, 2022
377833b
Work with PackageReference manipulation directly, to avoid context is…
directhex Aug 23, 2022
8d39d0a
Revert "Work with PackageReference manipulation directly, to avoid co…
directhex Aug 23, 2022
5351c28
Revert "Revert "Work with PackageReference manipulation directly, to …
directhex Aug 23, 2022
1a8d2b2
Deduplicate
directhex Aug 23, 2022
379b62c
Skip compiler init on Android
directhex Aug 23, 2022
07ba253
Hack to deal with osx-10.12 vs osx-11.0 host OS on arm64 LLVM
directhex Aug 23, 2022
d313bc8
ItemGroup crimes
directhex Aug 23, 2022
0786b79
No LLVM for mac-arm
directhex Aug 23, 2022
4cf2ee2
Typo
directhex Aug 23, 2022
be82b60
Never use llvm-config. Our cross-compiler mess is too complex.
directhex Aug 23, 2022
056c7fd
Merge branch 'yo-dawg-i-heard-you-like-cross-compilers-so-i-cross-com…
directhex Aug 23, 2022
f782186
Special-case wasm LLVM libs check
directhex Aug 24, 2022
54f427e
fix wrong arch LLVM used during AOT compilers on linux
directhex Aug 24, 2022
5e3999f
Always use compiler-init on Windows, even when we disable it for Linu…
directhex Aug 24, 2022
c1f43ca
Move the LLVM cheese
directhex Aug 24, 2022
3864f12
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Aug 25, 2022
16340da
Duplicate more of llvm-config into cmake
directhex Aug 25, 2022
b446a8c
Tweak ItemGroup conditional
directhex Aug 25, 2022
f3571d6
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Aug 25, 2022
e5d3084
Ensure we pass through real arch during LLVM restore
directhex Aug 25, 2022
b9e6cd1
Always initialize compiler when cross-compiling cross-compiler
directhex Aug 25, 2022
a533b62
Generate cross-compiler packages on arm64
directhex Aug 25, 2022
155ef11
don't constantly re-copy LLVM
directhex Aug 25, 2022
fc817bd
Revert "don't constantly re-copy LLVM"
directhex Aug 25, 2022
71d602b
Fix Linux WASM
directhex Aug 25, 2022
a8e6f3b
Fix building browser-wasm for osx-arm64 on osx-x64
directhex Aug 25, 2022
a1663d0
Get rid of debug output
directhex Aug 26, 2022
cb8edf8
Merge branch 'yo-dawg-i-heard-you-like-cross-compilers-so-i-cross-com…
directhex Aug 26, 2022
4c83acc
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Aug 26, 2022
14bfd80
Let's not kid ourselves: Mono doesn't work on Windows ARM64 at all
directhex Aug 26, 2022
73cc736
Add what works to CI
directhex Aug 26, 2022
55184de
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Sep 26, 2022
fd58630
Merge errors
directhex Sep 26, 2022
36e20b9
Build wasm offsets
directhex Sep 26, 2022
c45b4eb
Patch from Ankit to enable workload build testing
directhex Sep 27, 2022
f2df10e
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Sep 27, 2022
b2f6892
Merge branch 'main' into yo-dawg-i-heard-you-like-cross-compilers-so-…
directhex Dec 20, 2022
2b90252
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Jan 3, 2023
6d845db
Reconcile change from #77304
directhex Jan 3, 2023
4f75c02
Fix up Versions.props issues for LLVM on ARM Mac
directhex Jan 3, 2023
8e47d22
Reconcile more changes from osx.11.0-arm64->osx-arm64 change
directhex Jan 3, 2023
ae07704
Add missing offset generation job
directhex Jan 3, 2023
3cfaebe
Exclude arm32 LLVM, as well as x86
directhex Jan 3, 2023
241ccbc
This seems to work better
directhex Jan 4, 2023
e5f99b2
Merge remote-tracking branch 'origin/main' into yo-dawg-i-heard-you-l…
directhex Jan 5, 2023
0830b80
Urgh
directhex Jan 5, 2023
2b32858
Point Browser osx-arm64 workload at osx-arm64 cross compiler package
directhex Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- 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