Skip to content

Commit

Permalink
build bolt together with llvmdev
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Jul 24, 2024
1 parent e51d279 commit bc22902
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 69 deletions.
36 changes: 31 additions & 5 deletions recipes/bolt/bld.bat
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
@echo on

:: until https://github.com/llvm/llvm-project/pull/97130 lands,
:: follow https://github.com/conda-forge/llvmdev-feedstock/blob/main/recipe/build.sh,
:: minus the tests and plus LLVM_ENABLE_PROJECTS="bolt" / LLVM_TARGETS_TO_BUILD=...

mkdir build
cd build

set CC=cl.exe
set CXX=cl.exe
REM remove GL flag for now
set "CXXFLAGS=-MD"
set "CC=cl.exe"
set "CXX=cl.exe"

cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE="Release" ^
-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX% ^
%SRC_DIR%/bolt
-DCMAKE_INSTALL_PREFIX:PATH=%LIBRARY_PREFIX% ^
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL ^
-DLLVM_USE_INTEL_JITEVENTS=ON ^
-DLLVM_ENABLE_DUMP=ON ^
-DLLVM_ENABLE_LIBXML2=FORCE_ON ^
-DLLVM_ENABLE_PROJECTS="bolt" ^
-DLLVM_ENABLE_RTTI=ON ^
-DLLVM_ENABLE_ZLIB=FORCE_ON ^
-DLLVM_ENABLE_ZSTD=FORCE_ON ^
-DLLVM_INCLUDE_BENCHMARKS=OFF ^
-DLLVM_INCLUDE_DOCS=OFF ^
-DLLVM_INCLUDE_EXAMPLES=OFF ^
-DLLVM_INCLUDE_TESTS=ON ^
-DLLVM_INCLUDE_UTILS=ON ^
-DLLVM_INSTALL_UTILS=ON ^
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" ^
-DLLVM_USE_SYMLINKS=OFF ^
-DLLVM_UTILS_INSTALL_DIR=libexec\llvm ^
-DLLVM_BUILD_LLVM_C_DYLIB=ON ^
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly ^
-DCMAKE_POLICY_DEFAULT_CMP0111=NEW ^
%SRC_DIR%/llvm
if %ERRORLEVEL% neq 0 exit 1

cmake --build . --target install
cmake --build .
if %ERRORLEVEL% neq 0 exit 1
64 changes: 59 additions & 5 deletions recipes/bolt/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,69 @@
#!/bin/bash
set -ex

# until https://github.com/llvm/llvm-project/pull/97130 lands,
# follow https://github.com/conda-forge/llvmdev-feedstock/blob/main/recipe/build.sh,
# minus the tests and plus LLVM_ENABLE_PROJECTS="bolt" / LLVM_TARGETS_TO_BUILD=...

# Make osx work like linux.
sed -i.bak "s/NOT APPLE AND ARG_SONAME/ARG_SONAME/g" llvm/cmake/modules/AddLLVM.cmake
sed -i.bak "s/NOT APPLE AND NOT ARG_SONAME/NOT ARG_SONAME/g" llvm/cmake/modules/AddLLVM.cmake

mkdir build
cd build

if [[ "$target_platform" == "linux-64" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DLLVM_USE_INTEL_JITEVENTS=ON"
elif [[ "$target_platform" == osx-* ]]; then
# only supported on osx, see
# https://github.com/llvm/llvm-project/blob/llvmorg-16.0.6/llvm/tools/llvm-shlib/CMakeLists.txt#L82-L85
# currently off though, because it doesn't build yet
# CMAKE_ARGS="${CMAKE_ARGS} -DLLVM_BUILD_LLVM_C_DYLIB=ON"
true
fi

if [[ "$CC_FOR_BUILD" != "" && "$CC_FOR_BUILD" != "$CC" ]]; then
NATIVE_FLAGS="-DCMAKE_C_COMPILER=$CC_FOR_BUILD;-DCMAKE_CXX_COMPILER=$CXX_FOR_BUILD;-DCMAKE_C_FLAGS=-O2;-DCMAKE_CXX_FLAGS=-O2"
NATIVE_FLAGS="${NATIVE_FLAGS};-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,${BUILD_PREFIX}/lib;-DCMAKE_MODULE_LINKER_FLAGS=;-DCMAKE_SHARED_LINKER_FLAGS="
NATIVE_FLAGS="${NATIVE_FLAGS};-DCMAKE_STATIC_LINKER_FLAGS=;-DLLVM_INCLUDE_BENCHMARKS=OFF"
NATIVE_FLAGS="${NATIVE_FLAGS};-DLLVM_ENABLE_ZSTD=OFF;-DLLVM_ENABLE_LIBXML2=OFF;-DLLVM_ENABLE_ZLIB=OFF;"
CMAKE_ARGS="${CMAKE_ARGS} -DCROSS_TOOLCHAIN_FLAGS_NATIVE=${NATIVE_FLAGS}"
fi

# disable -fno-plt due to https://bugs.llvm.org/show_bug.cgi?id=51863 due to some GCC bug
if [[ "$target_platform" == "linux-ppc64le" ]]; then
CFLAGS="$(echo $CFLAGS | sed 's/-fno-plt //g')"
CXXFLAGS="$(echo $CXXFLAGS | sed 's/-fno-plt //g')"
fi

cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DCMAKE_LIBRARY_PATH="${PREFIX}" \
-DLLVM_ENABLE_BACKTRACES=ON \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_LIBXML2=FORCE_ON \
-DLLVM_ENABLE_PROJECTS="bolt" \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_ZLIB=FORCE_ON \
-DLLVM_ENABLE_ZSTD=FORCE_ON \
-DLLVM_DEFAULT_TARGET_TRIPLE=${CONDA_TOOLCHAIN_HOST} \
-DLLVM_HOST_TRIPLE=${CONDA_TOOLCHAIN_HOST} \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_GO_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=ON \
-DLLVM_INCLUDE_UTILS=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_TARGETS_TO_BUILD=X86;AArch64 \
-DLLVM_UTILS_INSTALL_DIR=libexec/llvm \
-DLLVM_BUILD_LLVM_DYLIB=yes \
-DLLVM_LINK_LLVM_DYLIB=yes \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \
${CMAKE_ARGS} \
../bolt
../llvm

cmake --build .
cmake --install .
ninja -j${CPU_COUNT}
4 changes: 0 additions & 4 deletions recipes/bolt/conda_build_config.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions recipes/bolt/install_bolt.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo on

:: temporary prefix to be able to install files more granularly
mkdir temp_prefix

if "%PKG_NAME%" == "libbolt" (
cmake --install ./build --prefix=./temp_prefix
if %ERRORLEVEL% neq 0 exit 1
REM only bolt libraries
mkdir %LIBRARY_LIB%
move .\temp_prefix\lib\LLVMBOLT*.lib %LIBRARY_LIB%
) else (
REM bolt: everything else
cmake --install .\build --prefix=%LIBRARY_PREFIX%
if %ERRORLEVEL% neq 0 exit 1
)

rmdir /s /q temp_prefix
19 changes: 19 additions & 0 deletions recipes/bolt/install_bolt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -ex

# temporary prefix to be able to install files more granularly
mkdir temp_prefix

if [[ "${PKG_NAME}" == "libbolt" ]]; then
cmake --install ./build --prefix=./temp_prefix
# only bolt libraries
mkdir -p $PREFIX/lib
mv ./temp_prefix/lib/libLLVMBOLT* $PREFIX/lib
# only on linux-64
mv ./temp_prefix/lib/libbolt* $PREFIX/lib || true
else
# bolt: install everything else
cmake --install ./build --prefix=$PREFIX
fi

rm -rf temp_prefix
94 changes: 83 additions & 11 deletions recipes/bolt/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,46 +1,118 @@
{% set version = "17.0.6" %}
{% set major_ver = version.split(".")[0] %}

# as of LLVM 17, we expect an "rc" suffix for the release candidates
{% set extra = "rc" if version.split(".")[-1] not in "0123456789" else "" %}
{% set extra = "git" if version.split(".")[-1] == "dev0" else extra %}

package:
name: llvm-bolt
name: bolt-split
version: {{ version }}

source:
url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version.replace(".rc", "-rc") }}/llvm-project-{{ version.replace(".rc", "rc") }}.src.tar.xz
sha256: 58a8818c60e6627064f312dbf46c02d9949956558340938b71cf731ad8bc0813
# matching https://github.com/conda-forge/llvmdev-feedstock/tree/main/recipe/patches,
# since we rebuild llvmdev here (until https://github.com/llvm/llvm-project/pull/97130)
patches:
- patches/0001-minimal-changes-to-make-bolt-build-standalone.patch
- patches/0002-module-path-code-from-lld.patch
- patches/0001-pass-through-QEMU_LD_PREFIX-SDKROOT.patch
# backports patch for issues with LLJIT, see
# https://github.com/llvm/llvm-project/commit/122ebe3b500190b1f408e2e6db753853e297ba28
- patches/0002-ORC-Use-EPC-bootstrap-symbols-to-communicate-eh-fram.patch

build:
number: 0
merge_build_host: false

requirements:
build:
- {{ stdlib('c') }}
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- cmake
- ninja
- clangdev =={{ version }} # [build_platform != target_platform]
- llvmdev =={{ version }} # [build_platform != target_platform]
- libcxx {{ cxx_compiler_version }} # [osx]
host:
- clangdev =={{ version }}
- llvmdev =={{ version }}
- libcxx {{ cxx_compiler_version }} # [osx]
# needs aarch/ppc/arm (re)build of conda-forge/backtrace-feedstock
- backtrace # [unix and x86]
- libxml2
- zlib
- zstd

test:
commands:
- llvm-bolt --version
outputs:
# Contains bolt support libraries
- name: libbolt
script: install_bolt.sh # [unix]
script: install_bolt.bat # [win]
build:
activate_in_script: true
requirements:
build:
- {{ stdlib('c') }}
- {{ compiler('cxx') }}
- cmake
- ninja
- libcxx {{ cxx_compiler_version }} # [osx]
run_constrained:
- llvm {{ version }}
- llvmdev {{ version }}
- clang {{ version }}
- clang-tools {{ version }}
test:
commands:
{% for each_lib in [
"Core", "Passes", "Profile", "Rewrite", "RuntimeLibs",
"TargetAArch64", "TargetX86", "Utils"
] %}
- test -f $PREFIX/lib/libLLVMBOLT{{ each_lib }}.a # [unix]
- if not exist %LIBRARY_LIB%\LLVMBOLT{{ each_lib }}.lib exit 1 # [win]
{% endfor %}
# only on linux-64
- test -f $PREFIX/lib/libbolt_rt_hugify.a # [linux64]
- test -f $PREFIX/lib/libbolt_rt_instr.a # [linux64]

# Contains bolt
- name: bolt
script: install_bolt.sh # [unix]
script: install_bolt.bat # [win]
build:
activate_in_script: true
requirements:
build:
- {{ stdlib('c') }}
- {{ compiler('cxx') }}
- cmake
- ninja
- libcxx {{ cxx_compiler_version }} # [osx]
host:
- libcxx {{ cxx_compiler_version }} # [osx]
# ensure we don't pick up stuff already packaged in llvmdev
- llvmdev {{ version }}
- zlib
- zstd
run:
- {{ pin_subpackage("libbolt", exact=True) }}
run_constrained:
- llvm {{ version }}
- llvmdev {{ version }}
- clang {{ version }}
- clang-tools {{ version }}
test:
commands:
- llvm-bolt -version
- llvm-boltdiff -version
- llvm-bolt-heatmap -version
- perf2bolt -version

about:
home: https://github.com/llvm/llvm-project/tree/main/bolt
license: Apache-2.0 WITH LLVM-exception
license_file: bolt/LICENSE.TXT
license_family: Apache
summary: BOLT is a post-link optimizer developed to speed up large applications.
dev_url: https://github.com/llvm/llvm-project/

extra:
recipe-maintainers:
- h-vetinari
feedstock-name: bolt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From f2ee4893b93c254d97fd51fe6f6ee605934cf6a9 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <[email protected]>
Date: Tue, 4 Aug 2020 21:06:30 -0500
Subject: [PATCH 1/2] pass through QEMU_LD_PREFIX & SDKROOT

---
llvm/utils/lit/lit/TestingConfig.py | 2 ++
1 file changed, 2 insertions(+)

diff --git a/llvm/utils/lit/lit/TestingConfig.py b/llvm/utils/lit/lit/TestingConfig.py
index 76fd66502009..3009e921b621 100644
--- a/llvm/utils/lit/lit/TestingConfig.py
+++ b/llvm/utils/lit/lit/TestingConfig.py
@@ -25,6 +25,8 @@ class TestingConfig(object):
"LD_LIBRARY_PATH",
"SYSTEMROOT",
"TERM",
+ "QEMU_LD_PREFIX",
+ "SDKROOT",
"CLANG",
"LLDB",
"LD_PRELOAD",
Loading

0 comments on commit bc22902

Please sign in to comment.