Skip to content

Commit 1de295f

Browse files
committed
root CMakeLists.txt
1 parent 21b03c4 commit 1de295f

File tree

11 files changed

+382
-177
lines changed

11 files changed

+382
-177
lines changed

.github/workflows/build_test_release_eudsl.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ jobs:
131131
echo MACOSX_DEPLOYMENT_TARGET=13.7 >> $GITHUB_ENV
132132
fi
133133
134+
# prevent OOM on free GHA
135+
echo "EUDSLPY_DISABLE_COMPILE_OPT=${{ inputs.eudslpy_disable_compile_opt == 'true' && 'ON' || 'OFF' }}" >> $GITHUB_ENV
136+
134137
pip install cibuildwheel
135138
136139
- name: "Build eudsl-tblgen"
@@ -139,7 +142,6 @@ jobs:
139142
$python3_command -m cibuildwheel "$PWD/projects/eudsl-tblgen" --output-dir wheelhouse
140143
141144
- name: "Build eudsl-nbgen"
142-
if: ${{ ! startsWith(matrix.os, 'windows') }}
143145
run: |
144146
145147
$python3_command -m cibuildwheel "$PWD/projects/eudsl-nbgen" --output-dir wheelhouse
@@ -148,10 +150,16 @@ jobs:
148150
if: ${{ ! startsWith(matrix.os, 'windows') }}
149151
run: |
150152
151-
# prevent OOM on free GHA
152-
export EUDSLPY_DISABLE_COMPILE_OPT="${{ inputs.eudslpy_disable_compile_opt == 'true' && 'ON' || 'OFF' }}"
153153
$python3_command -m cibuildwheel "$PWD/projects/eudsl-py" --output-dir wheelhouse
154154
155+
# just to/make sure total build continues to work
156+
- name: "Build all of eudsl"
157+
run: |
158+
159+
pip install -r requirements.txt
160+
cmake -B $PWD/eudsl-build -S $PWD -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/eudsl-install
161+
cmake --build "$PWD/eudsl-build" --target install
162+
155163
- name: "Save cache"
156164
uses: actions/cache/save@v3
157165
if: ${{ !cancelled() && github.event_name == 'push' && github.ref_name == 'main' }}

CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
# Copyright (c) 2024.
5+
6+
cmake_minimum_required(VERSION 3.29)
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
9+
10+
set(LLVM_SUBPROJECT_TITLE "EUDSL")
11+
set(EUDSL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
12+
13+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
14+
message("Building ${LLVM_SUBPROJECT_TITLE} as a standalone project.")
15+
project(${LLVM_SUBPROJECT_TITLE} CXX C)
16+
set(EUDSL_STANDALONE_BUILD ON)
17+
else()
18+
enable_language(CXX C)
19+
set(EUDSL_STANDALONE_BUILD OFF)
20+
endif()
21+
22+
if(EUDSL_STANDALONE_BUILD)
23+
find_package(LLVM REQUIRED CONFIG)
24+
find_package(MLIR REQUIRED CONFIG)
25+
find_package(Clang REQUIRED CONFIG PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
26+
27+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
28+
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
29+
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")
30+
31+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
32+
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
33+
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
34+
35+
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
36+
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
37+
list(APPEND CMAKE_MODULE_PATH "${CLANG_CMAKE_DIR}")
38+
39+
include(TableGen)
40+
include(AddLLVM)
41+
include(AddMLIR)
42+
include(AddClang)
43+
44+
set(MLIR_INCLUDE_DIR ${MLIR_INCLUDE_DIRS})
45+
else()
46+
# turning LLVM -DLLVM_OPTIMIZED_TABLEGEN=ON builds some stuff in the NATIVE dir
47+
# but not everything so LLVM_BINARY_DIR isn't correct
48+
string(REPLACE "NATIVE" "" LLVM_BINARY_DIR "${LLVM_BINARY_DIR}")
49+
# Build via external projects mechanism
50+
set(LLVM_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
51+
set(LLVM_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/include)
52+
set(LLVM_INCLUDE_DIRS "${LLVM_INCLUDE_DIR};${LLVM_GENERATED_INCLUDE_DIR}")
53+
54+
set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir)
55+
set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include)
56+
set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
57+
set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
58+
59+
set(CLANG_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../clang)
60+
set(CLANG_INCLUDE_DIR ${CLANG_MAIN_SRC_DIR}/include)
61+
set(CLANG_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/clang/include)
62+
set(CLANG_INCLUDE_DIRS "${CLANG_INCLUDE_DIR};${CLANG_GENERATED_INCLUDE_DIR}")
63+
endif()
64+
65+
include_directories(${LLVM_INCLUDE_DIRS})
66+
include_directories(${MLIR_INCLUDE_DIRS})
67+
include_directories(${CLANG_INCLUDE_DIRS})
68+
link_directories(${LLVM_BUILD_LIBRARY_DIR})
69+
add_definitions(${LLVM_DEFINITIONS})
70+
71+
if(NOT TARGET LLVMSupport)
72+
message(FATAL_ERROR "LLVMSupport not found")
73+
endif()
74+
75+
add_subdirectory(projects)

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,68 @@
77
This repository contains the source code for `EUDSL`, a toolkit for the construction of
88
embedded DSLs, in arbitrary languages, for targeting [MLIR](https://mlir.llvm.org).
99

10+
FYI: this project is currently "alpha" quality.
11+
12+
Currently there are three components:
13+
14+
1. [eudsl-tblgen](./projects/eudsl-tblgen): Python bindings to [MLIR's TableGen library](https://github.com/llvm/llvm-project/tree/main/mlir/lib/TableGen);
15+
2. [eudsl-nbgen](./projects/eudsl-nbgen): A source-to-source translator that translates MLIR headers[^1] into direct `nanobind` bindings;
16+
3. [eudsl-py](./projects/eudsl-py): Direct Python bindings to MLIR, generated using `eudsl-nbgen`;
17+
* Currently only TableGen outputs (various `*.h.inc` files generated by `mlir-tblgen`) are automatically translated but the `eudsl-nbgen` tool can be manually run to translate any MLIR header (to varying degrees of success);
18+
* See [projects/eudsl-py/tests](./projects/eudsl-py/tests) for a few examples of what these bindings look like.
19+
1020
## Getting started
1121

12-
Coming soon...
22+
Python wheels of all the tools are available at the [`latest` release page](https://github.com/llvm/eudsl/releases/tag/latest).
23+
They are also `pip install`-able with .e.g
24+
25+
```shell
26+
$ cd <EUDSL_CHECKOUT_DIR>
27+
$ pip install eudsl-py -f https://github.com/llvm/eudsl/releases/expanded_assets/latest
28+
```
29+
30+
`eudsl-py` has a slowly growing set of tests @ [projects/eudsl-py/tests](./projects/eudsl-py/tests).
31+
32+
If you don't want to install locally, here is a [colab notebook minimal working example](https://colab.research.google.com/drive/1l-6rVnsUM3ypn7rKcaF_V6XVdopEM4Df?usp=sharing).
33+
34+
## Developing/building
35+
36+
**Strong recommendation**: check the CI scripts @ [.github/workflows](.github/workflows) - they do a fresh checkout and build on every commit and are written to be read by a non-CI expert.
37+
38+
Firstly, you need a distribution of LLVM. You can build LLVM from source using our submodule by doing (on Mac/Linux or mingw):
39+
40+
```shell
41+
$ cd <EUDSL_CHECKOUT_DIR>
42+
$ ./build_tools/build_llvm.sh
43+
```
44+
45+
Alternatively you can download a distribution for your platform from the [`llvm` release page](https://github.com/llvm/eudsl/releases/tag/llvm).
46+
47+
Then each of the above tools can both be built as a conventional, standalone, CMake project and as a Python wheel.
48+
The wheel build looks something like:
49+
50+
```shell
51+
$ cd <EUDSL_CHECKOUT_DIR>
52+
$ export CMAKE_PREFIX_PATH=$PWD/llvm-install
53+
$ pip wheel projects/eudsl-nbgen -w wheelhouse -v
54+
$ pip wheel projects/eudsl-py -w wheelhouse -v --find-links $PWD/wheelhouse
55+
```
56+
57+
Note, the trailing `--find-links $PWD/wheelhouse` on `pip wheel projects/eudsl-py` is because `eudsl-nbgen` is a dependency of `eudsl-py` (that can be satisfied using the `eudsl-nbgen` wheel).
58+
59+
If you want to build an individual tool via CMake you can do something like:
60+
61+
```shell
62+
$ cd <EUDSL_CHECKOUT_DIR>
63+
$ pip install -r requirements.txt
64+
$ export CMAKE_PREFIX_PATH=$PWD/llvm-install
65+
$ cmake -B $PWD/eudsl-nbgen-build -S $PWD/projects/eudsl-nbgen -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/eudsl-nbgen-install
66+
$ cmake --build "$PWD/eudsl-build" --target install
67+
```
68+
69+
If you want to build all the tools at once using CMake you can use the root [`CMakeLists.txt`](./CMakeLists.txt).
70+
Note, in this case, `eudsl-nbgen` will automatically be built prior to `eudsl-py`.
71+
72+
## Footnotes
73+
74+
[^1]: Yes C++ headers...

projects/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
# Copyright (c) 2024.
5+
6+
if(NOT WIN32)
7+
add_subdirectory(eudsl-py)
8+
endif()
9+
add_subdirectory(eudsl-nbgen)
10+
add_subdirectory(eudsl-tblgen)

projects/eudsl-nbgen/CMakeLists.txt

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,7 @@ if(EUDSL_NBGEN_STANDALONE_BUILD)
3030
include(TableGen)
3131
include(AddLLVM)
3232
include(AddClang)
33-
# TODO(max): probably don't need this anymore after landing the nanobind fix?
34-
# technically we need this on windows too but our LLVM is compiled without exception handling
35-
# and that breaks windows
36-
if(NOT WIN32)
37-
include(HandleLLVMOptions)
38-
endif()
39-
else()
40-
# turning LLVM -DLLVM_OPTIMIZED_TABLEGEN=ON builds some stuff in the NATIVE dir
41-
# but not everything so LLVM_BINARY_DIR isn't correct
42-
string(REPLACE "NATIVE" "" LLVM_BINARY_DIR "${LLVM_BINARY_DIR}")
43-
# Build via external projects mechanism
44-
set(LLVM_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
45-
set(LLVM_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/include)
46-
set(LLVM_INCLUDE_DIRS "${LLVM_INCLUDE_DIR};${LLVM_GENERATED_INCLUDE_DIR}")
47-
48-
set(CLANG_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../clang)
49-
set(CLANG_INCLUDE_DIR ${CLANG_MAIN_SRC_DIR}/include)
50-
set(CLANG_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/clang/include)
51-
set(CLANG_INCLUDE_DIRS "${CLANG_INCLUDE_DIR};${CLANG_GENERATED_INCLUDE_DIR}")
33+
include(HandleLLVMOptions)
5234
endif()
5335

5436
include_directories(${LLVM_INCLUDE_DIRS})
@@ -72,14 +54,25 @@ target_link_libraries(eudsl-nbgen
7254
)
7355

7456
string(TOLOWER ${LLVM_SUBPROJECT_TITLE} EUDSL_NBGEN_INSTALL_DATADIR)
75-
# https://github.com/scikit-build/scikit-build-core/blob/a887a9b6c057b4ce9d3cfd53ae24e73caf1395a2/docs/build.md?plain=1#L139-L148
76-
# actually installs to venv/bin
77-
install(TARGETS eudsl-nbgen RUNTIME DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}.data/scripts")
78-
# this actually installs into venv/lib
79-
install(IMPORTED_RUNTIME_ARTIFACTS LLVM LIBRARY DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}.data/data/lib")
57+
if (NOT "$ENV{PIP_BUILD_TRACKER}" STREQUAL "")
58+
# pip install
59+
# actually installs to venv/bin
60+
# https://github.com/scikit-build/scikit-build-core/blob/a887a9b6c057b4ce9d3cfd53ae24e73caf1395a2/docs/build.md?plain=1#L139-L148
61+
install(TARGETS eudsl-nbgen RUNTIME DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}.data/scripts")
62+
if (NOT WIN32)
63+
# this actually installs into venv/lib
64+
install(IMPORTED_RUNTIME_ARTIFACTS LLVM LIBRARY DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}.data/data/lib")
65+
endif()
66+
else()
67+
# pip cmake install
68+
install(TARGETS eudsl-nbgen RUNTIME DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}/bin")
69+
if (NOT WIN32)
70+
install(IMPORTED_RUNTIME_ARTIFACTS LLVM LIBRARY DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}/lib")
71+
endif()
72+
endif()
8073

8174
install(
82-
DIRECTORY src/
75+
DIRECTORY src
8376
DESTINATION "${EUDSL_NBGEN_INSTALL_DATADIR}"
8477
FILES_MATCHING PATTERN "*\.py"
8578
)

0 commit comments

Comments
 (0)