Pact with the devil: LLVM

This commit is contained in:
David Gonzalez Martin 2024-10-21 05:49:23 -06:00 committed by David
parent f7c1077706
commit 3bdc01ab0a
5 changed files with 70 additions and 20 deletions

View File

@ -16,7 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt install -y ninja-build
run: sudo apt install -y ninja-build mold
- name: System information
run: |
uname -a
@ -32,7 +32,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt install -y ninja-build
run: sudo apt install -y ninja-build mold
- name: System information
run: |
uname -a
@ -48,7 +48,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt install -y ninja-build
run: sudo apt install -y ninja-build mold
- name: System information
run: |
uname -a
@ -64,7 +64,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt install -y ninja-build
run: sudo apt install -y ninja-build mold
- name: System information
run: |
uname -a
@ -144,13 +144,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: choco install ninja
run: |
choco install ninja
pwsh ./fetch-llvm.ps1
# - name: System information
# run: |
# systeminfo
# clang -v
- name: Build and test
run: pwsh ./project.ps1 "build_type=Debug" test all
run: pwsh ./project.ps1 "-DCMAKE_PREFIX_PATH=clang+llvm-19.1.2-x86_64-pc-windows-msvc" "build_type=Debug" test all
env:
LANG: en_US.UTF-8 # Ensure UTF-8 encoding
windows_MinSizeRel:
@ -160,13 +162,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: choco install ninja
run: |
choco install ninja
pwsh ./fetch-llvm.ps1
# - name: System information
# run: |
# systeminfo
# clang -v
- name: Build and test
run: pwsh ./project.ps1 "build_type=MinSizeRel" test all
run: pwsh ./project.ps1 "-DCMAKE_PREFIX_PATH=clang+llvm-19.1.2-x86_64-pc-windows-msvc" "build_type=MinSizeRel" test all
env:
LANG: en_US.UTF-8 # Ensure UTF-8 encoding
windows_RelWithDebInfo:
@ -176,13 +180,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: choco install ninja
run: |
choco install ninja
pwsh ./fetch-llvm.ps1
# - name: System information
# run: |
# systeminfo
# clang -v
- name: Build and test
run: pwsh ./project.ps1 "build_type=RelWithDebInfo" test all
run: pwsh ./project.ps1 "-DCMAKE_PREFIX_PATH=clang+llvm-19.1.2-x86_64-pc-windows-msvc" "build_type=RelWithDebInfo" test all
env:
LANG: en_US.UTF-8 # Ensure UTF-8 encoding
windows_Release:
@ -192,12 +198,14 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: choco install ninja
run: |
choco install ninja
pwsh ./fetch-llvm.ps1
# - name: System information
# run: |
# systeminfo
# clang -v
- name: Build and test
run: pwsh ./project.ps1 "build_type=Release" test all
run: pwsh ./project.ps1 "-DCMAKE_PREFIX_PATH=clang+llvm-19.1.2-x86_64-pc-windows-msvc" "build_type=Release" test all
env:
LANG: en_US.UTF-8 # Ensure UTF-8 encoding

View File

@ -14,9 +14,12 @@ add_compile_options(
)
include_directories("bootstrap/include")
find_package(LLVM REQUIRED CONFIG)
set(LIBRARY_NAME "std")
set(RUNNER_NAME "runner")
set(COMPILER_NAME "nest")
add_library("${LIBRARY_NAME}"
"bootstrap/std/base.c"
"bootstrap/std/string.c"
@ -27,10 +30,15 @@ add_library("${LIBRARY_NAME}"
"bootstrap/std/sha1.c"
)
add_executable("${RUNNER_NAME}" "bootstrap/runner/runner.c")
target_link_libraries(${RUNNER_NAME} ${LIBRARY_NAME})
target_link_libraries(${RUNNER_NAME} PRIVATE ${LIBRARY_NAME})
add_executable("${COMPILER_NAME}"
"bootstrap/src/main.c"
"bootstrap/src/pdb_image.c"
)
target_link_libraries(${COMPILER_NAME} ${LIBRARY_NAME})
target_compile_definitions(${COMPILER_NAME} PRIVATE ${LLVM_DEFINITIONS})
target_include_directories(${COMPILER_NAME} PRIVATE ${LLVM_INCLUDE_DIRS})
target_link_directories(${COMPILER_NAME} PRIVATE ${LLVM_LIBRARY_DIRS})
target_link_libraries(${COMPILER_NAME} PRIVATE ${LIBRARY_NAME} ${LLVM_LIBRARIES})

14
fetch-llvm.ps1 Normal file
View File

@ -0,0 +1,14 @@
Set-StrictMode -Version Latest
Set-PSDebug -Trace 2
$LLVM_VERSION="19.1.2"
$BASE_DOWNLOAD_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION"
$LLVM_DOWNLOAD_FILE_BASENAME="clang+llvm-$LLVM_VERSION-x86_64-pc-windows-msvc"
$LLVM_DOWNLOAD_FILE="$LLVM_DOWNLOAD_FILE_BASENAME.tar.xz"
$LLVM_DOWNLOAD_URL="$BASE_DOWNLOAD_URL/$LLVM_DOWNLOAD_FILE"
Invoke-WebRequest -Uri "$LLVM_DOWNLOAD_URL" -OutFile "$LLVM_DOWNLOAD_FILE"
7z x $LLVM_DOWNLOAD_FILE
7z x "$LLVM_DOWNLOAD_FILE_BASENAME.tar"
dir

View File

@ -1,25 +1,33 @@
Set-StrictMode -Version Latest
Set-PSDebug -Trace 2
$previous_error_action_preference = $global:ErrorActionPreference
$global:ErrorActionPreference = 'Stop'
$myargs=$args
$build_dir="build"
$release_mode="Debug"
$build_type_prefix="build_type="
$cmake_prefix_path_prefix="-DCMAKE_PREFIX_PATH="
$cmake_prefix_path=""
& {
try
{
$global:ErrorActionPreference = 'Stop'
if ($($myargs.Length) -ne 0 -and $myargs[0].StartsWith($build_type_prefix))
foreach ($arg in $myargs)
{
$release_mode = $myargs[0].Substring($build_type_prefix.Length)
if ($arg.StartsWith($build_type_prefix))
{
$release_mode = $arg.Substring($build_type_prefix.Length)
}
if ($arg.StartsWith($cmake_prefix_path_prefix))
{
$cmake_prefix_path = $arg.Substring($cmake_prefix_path_prefix.Length);
}
}
Write-Output "Build type: $release_mode"
New-Item -Path $build_dir -ItemType Directory -Force
cmake . "-B$build_dir" -G Ninja "-DCMAKE_BUILD_TYPE=$release_mode" -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++"
cmake . "-B$build_dir" -G Ninja "-DCMAKE_BUILD_TYPE=$release_mode" -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" "-DCMAKE_PREFIX_PATH=$cmake_prefix_path"
pushd $build_dir
ninja
popd

View File

@ -7,7 +7,19 @@ fi
echo "Build type: $release_mode"
build_dir=build
mkdir -p $build_dir
cmake . -B$build_dir -G Ninja -DCMAKE_BUILD_TYPE="$release_mode" -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++"
case "$OSTYPE" in
linux*) CLANG_PREFIX="/usr/bin" ;;
darwin*) CLANG_PREFIX="/opt/homebrew/opt/llvm/bin" ;;
*) exit 1 ;;
esac
case "$OSTYPE" in
linux*) cmake . -B$build_dir -G Ninja -DCMAKE_BUILD_TYPE="$release_mode" -DCMAKE_C_COMPILER="$CLANG_PREFIX/clang" -DCMAKE_CXX_COMPILER="$CLANG_PREFIX/clang++" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=mold" ;;
darwin*) cmake . -B$build_dir -G Ninja -DCMAKE_BUILD_TYPE="$release_mode" -DCMAKE_C_COMPILER="$CLANG_PREFIX/clang" -DCMAKE_CXX_COMPILER="$CLANG_PREFIX/clang++" -DCMAKE_PREFIX_PATH=$(brew --prefix llvm) ;;
*) exit 1 ;;
esac
original_dir=$PWD
cd $build_dir
ninja