Skip to content

Commit c17e8c0

Browse files
committed
patch libLLVM/libMLIR rpaths
1 parent e0bb34b commit c17e8c0

File tree

10 files changed

+229
-189
lines changed

10 files changed

+229
-189
lines changed

.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
BasedOnStyle: LLVM
22
AlwaysBreakTemplateDeclarations: Yes
3-
ReflowComments: false

.github/workflows/build_test_release_eudsl.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ jobs:
124124
$python3_command -m cibuildwheel "$PWD/projects/eudsl-tblgen" --output-dir wheelhouse
125125
126126
- name: "Build eudsl-py"
127+
if: ${{ ! startsWith(matrix.os, 'windows') }}
127128
run: |
128129
$python3_command -m cibuildwheel "$PWD/projects/eudsl-py" --output-dir wheelhouse
129130
@@ -239,11 +240,13 @@ jobs:
239240
strategy:
240241
fail-fast: false
241242
matrix:
242-
runs-on: ["ubuntu-22.04", "macos-14", "macos-13", "windows-2019"]
243+
runs-on: ["ubuntu-22.04", "macos-14", "macos-13",
244+
# "windows-2019"
245+
]
243246
python-version: ["3.9", "3.10", "3.11", "3.12"]
244247
include: [
245248
{runs-on: "ubuntu-22.04", name: "ubuntu_x86_64", os: "ubuntu"},
246-
{runs-on: "windows-2019", name: "windows_x86_64", os: "windows"},
249+
# {runs-on: "windows-2019", name: "windows_x86_64", os: "windows"},
247250
{runs-on: "macos-14", name: "macos_arm64", os: "macos"},
248251
{runs-on: "macos-13", name: "macos_x86_64", os: "macos"},
249252
]
@@ -269,7 +272,7 @@ jobs:
269272

270273
- uses: actions/download-artifact@v4
271274
with:
272-
name: eudsl_py_${{ matrix.name }}_artifact
275+
name: eudsl_${{ matrix.name }}_artifact
273276
path: wheelhouse
274277

275278
- name: "Install eudsl-py"

build_tools/build_llvm.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ cmake_options=(
4545
-DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}"
4646
)
4747

48+
if [ -x "$(command -v ccache)" ]; then
49+
echo 'using ccache' >&2
50+
export CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime,time_macros
51+
export CCACHE_CPP2=true
52+
export CCACHE_UMASK=002
53+
cmake_options+=(
54+
-DCMAKE_C_COMPILER_LAUNCHER=ccache
55+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
56+
)
57+
fi
58+
4859
# last so that C/CXX flags get set first
4960
cmake_options+=(-C "$TD/cmake/llvm_cache.cmake")
5061

build_tools/cmake/llvm_cache.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
1414
# (but doesn't work on windows)
1515
if (NOT WIN32)
1616
set(LLVM_LINK_LLVM_DYLIB ON CACHE BOOL "")
17+
set(MLIR_LINK_MLIR_DYLIB ON CACHE BOOL "")
1718
endif()
18-
set(MLIR_LINK_MLIR_DYLIB OFF CACHE BOOL "")
1919

2020
# useful things
2121
set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
@@ -103,7 +103,6 @@ set(LLVM_MlirDevelopment_DISTRIBUTION_COMPONENTS
103103

104104
FileCheck
105105
not
106-
MLIR
107106
MLIRPythonModules
108107
# triggers MLIRMlirDevelopmentTargets.cmake
109108
mlir-mlirdevelopment-cmake-exports

projects/eudsl-py/src/CMakeLists.txt renamed to projects/eudsl-py/CMakeLists.txt

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.29)
22
set(CMAKE_CXX_STANDARD 17)
33
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
6-
include(AddEUDSL)
75
set(LLVM_SUBPROJECT_TITLE "EUDSLPY")
86
set(EUDSLPY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
97

@@ -81,10 +79,12 @@ if(NOT TARGET LLVMSupport)
8179
message(FATAL_ERROR "LLVMSupport not found")
8280
endif()
8381

82+
set(EUDSLPY_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake")
83+
find_package(EUDSLPY CONFIG REQUIRED)
8484
add_eudslpygen(eudslpy-gen EUDSLPY
8585
DESTINATION "${CMAKE_INSTALL_BINDIR}"
8686
EXPORT ${LLVM_SUBPROJECT_TITLE}
87-
eudslpy-gen.cpp
87+
src/eudslpy-gen.cpp
8888
)
8989

9090
eudslpygen(EUDSLGenArith
@@ -93,8 +93,6 @@ eudslpygen(EUDSLGenArith
9393
NAMESPACES mlir::arith mlir::arith::detail
9494
)
9595

96-
97-
9896
execute_process(
9997
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
10098
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_DIR)
@@ -112,34 +110,70 @@ set(nanobind_options
112110
$<$<PLATFORM_ID:Windows>:/EHsc /GR>
113111
)
114112

113+
set(EUDSLPY_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src")
114+
115115
nanobind_add_module(eudslpy_ext
116116
NB_STATIC
117117
NB_DOMAIN eudsl
118-
eudslpy_ext.cpp
118+
src/eudslpy_ext.cpp
119119
)
120120
set_target_properties(eudslpy_ext
121121
PROPERTIES
122-
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/eudsl"
122+
LIBRARY_OUTPUT_DIRECTORY "${EUDSLPY_SRC_DIR}/eudsl"
123123
)
124124
target_link_libraries(eudslpy_ext PRIVATE MLIR)
125+
126+
# hack so we can move libMLIR and libLLVM into the wheel
127+
# see AddLLVM.cmake#llvm_setup_rpath
128+
if(APPLE OR UNIX)
129+
set(_origin_prefix "\$ORIGIN")
130+
if(APPLE)
131+
set(_origin_prefix "@loader_path")
132+
endif()
133+
if (EUDSLPY_STANDALONE_BUILD)
134+
get_target_property(_mlir_loc MLIR LOCATION)
135+
get_target_property(_llvm_loc LLVM LOCATION)
136+
else()
137+
set(_mlir_loc "$<TARGET_FILE:MLIR>")
138+
set(_llvm_loc "$<TARGET_FILE:LLVM>")
139+
endif()
140+
set(_old_rpath "${_origin_prefix}/../lib${LLVM_LIBDIR_SUFFIX}")
141+
if(APPLE)
142+
execute_process(COMMAND install_name_tool -rpath "${_old_rpath}" ${_origin_prefix} "${_mlir_loc}" ERROR_VARIABLE rpath_err)
143+
execute_process(COMMAND install_name_tool -rpath "${_old_rpath}" ${_origin_prefix} "${_llvm_loc}" ERROR_VARIABLE rpath_err)
144+
# maybe already updated...
145+
if (rpath_err AND NOT rpath_err MATCHES "no LC_RPATH load command with path: ${_old_rpath}")
146+
message(FATAL_ERROR "couldn't update rpath because: ${rpath_err}")
147+
endif()
148+
else()
149+
# sneaky sneaky - undocumented
150+
file(RPATH_CHANGE FILE "${_mlir_loc}" OLD_RPATH "${_old_rpath}" NEW_RPATH "${_origin_prefix}")
151+
file(RPATH_CHANGE FILE "${_llvm_loc}" OLD_RPATH "${_old_rpath}" NEW_RPATH "${_origin_prefix}")
152+
endif()
153+
set_target_properties(eudslpy_ext PROPERTIES INSTALL_RPATH "${_origin_prefix}")
154+
endif()
155+
# copy libMLIR into the ext dir for wheels
156+
install(IMPORTED_RUNTIME_ARTIFACTS MLIR LLVM LIBRARY DESTINATION eudsl)
157+
125158
target_compile_options(eudslpy_ext PRIVATE ${nanobind_options})
126159
target_compile_options(nanobind-static PRIVATE ${nanobind_options})
127160
add_dependencies(eudslpy_ext EUDSLGenArith)
128161

129-
set(NB_STUBGEN_CMD "${Python_EXECUTABLE}" "-m" "nanobind.stubgen" -m eudsl -r)
130-
set(NB_STUBGEN_OUTPUTS ${CMAKE_CURRENT_LIST_DIR}/eudsl/__init__.pyi)
162+
set(NB_STUBGEN_CMD "${Python_EXECUTABLE}" "-m" "nanobind.stubgen" --module eudslpy_ext --recursive --include-private --output-dir .)
163+
set(NB_STUBGEN_OUTPUTS "eudslpy_ext.pyi")
131164
add_custom_command(
132165
OUTPUT ${NB_STUBGEN_OUTPUTS}
133166
COMMAND ${NB_STUBGEN_CMD}
134-
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
167+
WORKING_DIRECTORY "${EUDSLPY_SRC_DIR}/eudsl"
135168
DEPENDS eudslpy_ext
136169
)
137170
add_custom_target(eudslpy_ext_stub ALL DEPENDS ${NB_STUBGEN_OUTPUTS})
138171

139172
install(TARGETS eudslpy_ext LIBRARY DESTINATION eudsl)
140173
install(
141-
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/eudsl
174+
DIRECTORY "${EUDSLPY_SRC_DIR}/eudsl"
142175
DESTINATION ${CMAKE_INSTALL_PREFIX}
176+
PATTERN "*.pyc" EXCLUDE
143177
PATTERN "*.so" EXCLUDE
144178
PATTERN "*.a" EXCLUDE
145179
PATTERN ".gitignore" EXCLUDE

projects/eudsl-py/src/cmake/AddEUDSL.cmake renamed to projects/eudsl-py/cmake/EUDSLPYConfig.cmake

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,30 @@ function(eudslpygen target inputFile outputFileName)
5353
# this could be smarter by asking people to list td targets or something but that's too onerous
5454
file(GLOB_RECURSE global_tds "${MLIR_INCLUDE_DIR}/mlir/*.td")
5555
# use cc -MM to collect all transitive headers
56+
set(_depfile ${CMAKE_CURRENT_BINARY_DIR}/${outputFileName}.d)
5657
file(RELATIVE_PATH outputFileName_rel
57-
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${outputFileName})
58-
set(clang_command ${CMAKE_CXX_COMPILER} -xc++ "-std=c++${CMAKE_CXX_STANDARD}" -MM ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE}
59-
${eudslpygen_includes} -MT ${outputFileName_rel} -o ${outputFileName_rel}.d)
58+
"${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${outputFileName}")
59+
set(clang_command ${CMAKE_CXX_COMPILER} -v -xc++ "-std=c++${CMAKE_CXX_STANDARD}" -MM ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE}
60+
${eudslpygen_includes} -MT ${outputFileName_rel} -o ${_depfile})
6061
execute_process(COMMAND ${clang_command} RESULT_VARIABLE had_error COMMAND_ECHO STDERR)
61-
if(had_error OR NOT EXISTS "${outputFileName_rel}.d")
62-
message(WARNING "couldn't build depfile")
62+
if(had_error OR NOT EXISTS "${_depfile}")
63+
set(additional_cmdline -o "${outputFileName_rel}")
6364
else()
6465
# Use depfile instead of globbing arbitrary *.td(s) for Ninja.
6566
if(CMAKE_GENERATOR MATCHES "Ninja")
66-
# Make output path relative to build.ninja, assuming located on
67-
# ${CMAKE_BINARY_DIR}.
67+
# Make output path relative to build.ninja, assuming located on ${CMAKE_BINARY_DIR}.
6868
# CMake emits build targets as relative paths but Ninja doesn't identify
6969
# absolute path (in *.d) as relative path (in build.ninja)
7070
# Note that eudslpygen is executed on ${CMAKE_BINARY_DIR} as working directory.
71-
set(additional_cmdline
72-
-o ${outputFileName_rel}
73-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
74-
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${outputFileName}.d
75-
)
71+
set(additional_cmdline -o "${outputFileName_rel}" DEPFILE "${_depfile}")
7672
else()
7773
# the length of the first line in the depfile...
7874
string(LENGTH "${outputFileName_rel}: \\" depfile_offset)
79-
file(READ ${CMAKE_CURRENT_BINARY_DIR}/${outputFileName}.d local_headers OFFSET ${depfile_offset})
75+
file(READ ${_depfile} local_headers OFFSET ${depfile_offset})
8076
string(REPLACE "\\" ";" local_headers "${local_headers}")
8177
string(REGEX REPLACE "[ \t\r\n]" "" local_headers "${local_headers}")
8278
list(REMOVE_ITEM local_headers "")
83-
set(additional_cmdline -o ${CMAKE_CURRENT_BINARY_DIR}/${outputFileName})
79+
set(additional_cmdline -o "${outputFileName_rel}")
8480
endif()
8581
endif()
8682

@@ -112,6 +108,7 @@ function(eudslpygen target inputFile outputFileName)
112108
${eudslpygen_includes}
113109
${eudslpygen_defines}
114110
${additional_cmdline}
111+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
115112
# The file in EUDSLPYGEN_TARGET_DEFINITIONS may be not in the current
116113
# directory and local_headers may not contain it, so we must
117114
# explicitly list it here:

projects/eudsl-py/pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ Homepage = "https://github.com/llvm/eudsl"
2222
minimum-version = "0.4"
2323
build-dir = "build/{wheel_tag}"
2424
wheel.py-api = "cp312"
25-
cmake.source-dir = "src"
25+
cmake.source-dir = "."
2626

2727
[tool.scikit-build.cmake.define]
2828
LLVM_DIR = {env="LLVM_DIR", default="EMPTY"}
2929
MLIR_DIR = {env="MLIR_DIR", default="EMPTY"}
3030
Clang_DIR = {env="Clang_DIR", default="EMPTY"}
31+
CMAKE_PREFIX_PATH = {env="CMAKE_PREFIX_PATH", default="EMPTY"}
3132
CMAKE_CXX_VISIBILITY_PRESET = "hidden"
3233
CMAKE_VERBOSE_MAKEFILE = "ON"
3334

@@ -40,5 +41,6 @@ environment-pass = [
4041
"LLVM_DIR",
4142
"MLIR_DIR",
4243
"Clang_DIR",
43-
"CMAKE_GENERATOR"
44+
"CMAKE_GENERATOR",
45+
"CMAKE_PREFIX_PATH"
4446
]

projects/eudsl-py/src/eudsl/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)