forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/enumerable-to_a-block
- Loading branch information
Showing
103 changed files
with
14,596 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
param( | ||
[Parameter(Mandatory)] [string] $BuildTree, | ||
[Parameter(Mandatory)] [string] $Version, | ||
[Parameter(Mandatory)] [string[]] $TargetsToBuild, | ||
[switch] $Dynamic | ||
) | ||
|
||
if (-not $Dynamic) { | ||
Write-Host "Error: Building LLVM as a static library is not supported yet" -ForegroundColor Red | ||
Exit 1 | ||
} | ||
|
||
. "$(Split-Path -Parent $MyInvocation.MyCommand.Path)\setup.ps1" | ||
|
||
[void](New-Item -Name (Split-Path -Parent $BuildTree) -ItemType Directory -Force) | ||
Setup-Git -Path $BuildTree -Url https://github.com/llvm/llvm-project.git -Ref llvmorg-$Version | ||
|
||
Run-InDirectory $BuildTree\build { | ||
$args = "-Thost=x64 -DLLVM_TARGETS_TO_BUILD=""$($TargetsToBuild -join ';')"" -DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_ZSTD=OFF" | ||
if ($Dynamic) { | ||
$args = "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL $args" | ||
} else { | ||
$args = "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DLLVM_BUILD_LLVM_C_DYLIB=OFF $args" | ||
} | ||
& $cmake ..\llvm $args.split(' ') | ||
& $cmake --build . --config Release --target llvm-config --target LLVM-C | ||
if (-not $?) { | ||
Write-Host "Error: Failed to build LLVM" -ForegroundColor Red | ||
Exit 1 | ||
} | ||
} | ||
|
||
if ($Dynamic) { | ||
mv -Force $BuildTree\build\Release\lib\LLVM-C.lib libs\llvm-dynamic.lib | ||
mv -Force $BuildTree\build\Release\bin\LLVM-C.dll dlls\ | ||
} else { | ||
# TODO (probably never) | ||
} | ||
|
||
Add-Content libs\llvm_VERSION $(& "$BuildTree\build\Release\bin\llvm-config.exe" --version) | ||
Add-Content libs\llvm_VERSION $(& "$BuildTree\build\Release\bin\llvm-config.exe" --targets-built) | ||
Add-Content libs\llvm_VERSION $(& "$BuildTree\build\Release\bin\llvm-config.exe" --system-libs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#! /usr/bin/env crystal | ||
# | ||
# This script generates the `lib/llvm_VERSION` file from LLVM-C.dll, needed for | ||
# dynamically linking against LLVM on Windows. This is only needed when using an | ||
# LLVM installation different from the one bundled with Crystal. | ||
|
||
require "c/libloaderapi" | ||
|
||
# The list of supported targets are hardcoded in: | ||
# https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt | ||
LLVM_ALL_TARGETS = %w( | ||
AArch64 | ||
AMDGPU | ||
ARM | ||
AVR | ||
BPF | ||
Hexagon | ||
Lanai | ||
LoongArch | ||
Mips | ||
MSP430 | ||
NVPTX | ||
PowerPC | ||
RISCV | ||
Sparc | ||
SystemZ | ||
VE | ||
WebAssembly | ||
X86 | ||
XCore | ||
ARC | ||
CSKY | ||
DirectX | ||
M68k | ||
SPIRV | ||
Xtensa | ||
) | ||
|
||
def find_dll_in_env_path | ||
ENV["PATH"]?.try &.split(Process::PATH_DELIMITER, remove_empty: true) do |path| | ||
dll_path = File.join(path, "LLVM-C.dll") | ||
return dll_path if File.exists?(File.join(path, "LLVM-C.dll")) | ||
end | ||
end | ||
|
||
unless dll_fname = ARGV.shift? || find_dll_in_env_path | ||
abort "Error: Cannot locate LLVM-C.dll, pass its absolute path as a command-line argument or ensure it is available in the PATH environment variable" | ||
end | ||
|
||
unless dll = LibC.LoadLibraryExW(dll_fname.check_no_null_byte.to_utf16, nil, 0) | ||
abort "Error: Failed to load DLL at #{dll_fname}" | ||
end | ||
|
||
begin | ||
unless llvm_get_version = LibC.GetProcAddress(dll, "LLVMGetVersion") | ||
abort "Error: Failed to resolve LLVMGetVersion" | ||
end | ||
|
||
llvm_get_version = Proc(LibC::UInt*, LibC::UInt*, LibC::UInt*, Nil).new(llvm_get_version, Pointer(Void).null) | ||
major = uninitialized LibC::UInt | ||
minor = uninitialized LibC::UInt | ||
patch = uninitialized LibC::UInt | ||
llvm_get_version.call(pointerof(major), pointerof(minor), pointerof(patch)) | ||
|
||
targets_built = LLVM_ALL_TARGETS.select do |target| | ||
LibC.GetProcAddress(dll, "LLVMInitialize#{target}Target") && LibC.GetProcAddress(dll, "LLVMInitialize#{target}TargetInfo") | ||
end | ||
|
||
# The list of required system libraries are hardcoded in: | ||
# https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/CMakeLists.txt | ||
# There is no way to infer them from `dumpbin /dependents` alone, because that | ||
# command lists DLLs only, whereas some of these libraries are purely static. | ||
system_libs = %w(psapi shell32 ole32 uuid advapi32) | ||
# https://github.com/llvm/llvm-project/commit/a5ffabce98a4b2e9d69009fa3e60f2b154100860 | ||
system_libs << "ws2_32" if {major, minor, patch} >= {18, 0, 0} | ||
|
||
puts "#{major}.#{minor}.#{patch}" | ||
puts targets_built.join(' ') | ||
puts system_libs.join(' ', &.+ ".lib") | ||
ensure | ||
LibC.FreeLibrary(dll) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.