Skip to content

Commit 16632e6

Browse files
author
t3tra
authored
Merge pull request #34 from t3tra-dev/feat/ci-workflow
2 parents 63f5034 + a1cbfdb commit 16632e6

File tree

11 files changed

+388
-243
lines changed

11 files changed

+388
-243
lines changed

.github/workflows/ci.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
ci:
11+
name: CI
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
submodules: recursive
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v4
27+
28+
- name: Install Dependencies
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y clang cmake ninja-build
32+
wget https://github.com/sharkdp/hyperfine/releases/download/v1.20.0/hyperfine_1.20.0_amd64.deb
33+
sudo dpkg -i hyperfine_1.20.0_amd64.deb
34+
pip install nanobind pybind11
35+
uv sync
36+
37+
- name: Cache LLVM/MLIR build
38+
id: cache-llvm
39+
uses: actions/cache@v4
40+
with:
41+
path: third_party/llvm-project/build
42+
key: llvm-mlir-${{ runner.os }}-${{ hashFiles('third_party/CMakeLists.txt', 'third_party/llvm-project/llvm/CMakeLists.txt') }}
43+
44+
- name: Build LLVM/MLIR
45+
if: steps.cache-llvm.outputs.cache-hit != 'true'
46+
run: |
47+
cmake -B third_party/build -S third_party
48+
cmake --build third_party/build
49+
50+
- name: Vendor MLIR Python modules
51+
run: |
52+
cmake \
53+
-DSRC_DIR=third_party/llvm-project/build/tools/mlir/python_packages/mlir_core/mlir \
54+
-DDEST_DIR=src/lython/mlir \
55+
-P third_party/cmake/vendor_mlir.cmake
56+
57+
- name: Build Lython
58+
run: |
59+
export pybind11_DIR=$(python -c "import pybind11; print(pybind11.get_cmake_dir())")
60+
uv run cmake -B build -S . -Dpybind11_DIR=$pybind11_DIR
61+
uv run cmake --build build
62+
63+
- name: Test
64+
run: |
65+
./build/bin/lyc jit examples/hello.py
66+
./build/bin/lyc jit examples/oop.py
67+
68+
- name: Benchmarks
69+
run: |
70+
./build/bin/lyc examples/fib.py -o fib_aot
71+
./build/bin/lyc examples/fib_prim.py -o fib_prim_aot
72+
hyperfine -w 1 -r 5 "python3 examples/fib.py" "./build/bin/lyc jit examples/fib.py" "./fib_aot" "./fib_prim_aot"

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

1111
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1212

13-
set(MLIR_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/build/lib/cmake/mlir")
14-
set(LLVM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/build/lib/cmake/llvm")
13+
find_package(Python3 3.12 EXACT REQUIRED COMPONENTS Interpreter Development)
14+
message(STATUS "Python3_EXECUTABLE: ${Python3_EXECUTABLE}")
15+
message(STATUS "Python3_VERSION: ${Python3_VERSION}")
16+
17+
if(NOT Python3_VERSION_MAJOR EQUAL 3 OR NOT Python3_VERSION_MINOR EQUAL 12)
18+
message(FATAL_ERROR "Python 3.12 is required, but found ${Python3_VERSION}")
19+
endif()
20+
21+
set(LLVM_PROJECT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/build")
22+
set(MLIR_DIR "${LLVM_PROJECT_BUILD_DIR}/lib/cmake/mlir")
23+
set(LLVM_DIR "${LLVM_PROJECT_BUILD_DIR}/lib/cmake/llvm")
24+
25+
set(LLVM_TABLEGEN_EXE "${LLVM_PROJECT_BUILD_DIR}/bin/llvm-tblgen" CACHE FILEPATH "llvm-tblgen executable")
26+
set(MLIR_TABLEGEN_EXE "${LLVM_PROJECT_BUILD_DIR}/bin/mlir-tblgen" CACHE FILEPATH "mlir-tblgen executable")
1527

1628
find_package(MLIR REQUIRED CONFIG)
1729
find_package(LLVM REQUIRED CONFIG)

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,38 @@
99

1010
---
1111

12-
セットアップ
12+
## セットアップ
13+
14+
### 必要なもの
15+
16+
- Python 3.12
17+
- CMake 3.20+
18+
- Ninja
19+
- C++17 対応コンパイラ
20+
- uv (Python パッケージマネージャ)
21+
- nanobind, pybind11
22+
23+
### ビルド手順
1324

1425
```bash
1526
git clone --recurse-submodules https://github.com/t3tra-dev/lython.git
1627
cd lython
1728
uv sync
18-
source ./.venv/bin/activate
19-
./build_mlir.sh
20-
./build.sh
21-
./vendor_mlir.sh
22-
uv build
29+
30+
# LLVM/MLIR (初回のみ、時間がかかります)
31+
uv run cmake -B third_party/build -S third_party
32+
uv run cmake --build third_party/build
33+
34+
# Lython 本体
35+
uv run cmake -B build -S .
36+
uv run cmake --build build
37+
```
38+
39+
### 実行
40+
41+
```bash
42+
./build/bin/lyc jit examples/hello.py
43+
./build/bin/lyc jit examples/fib.py
2344
```
2445

2546
---

build.sh

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

build_mlir.sh

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

src/lython/dialects/binding/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
set(PYBIND11_FINDPYTHON ON)
1+
set(PYBIND11_FINDPYTHON OFF)
2+
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
3+
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
4+
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
5+
set(PYBIND11_PYTHON_VERSION ${Python3_VERSION})
6+
27
find_package(pybind11 CONFIG REQUIRED)
38

9+
message(STATUS "Building PyDialectInitializer for Python ${Python3_VERSION} (${Python3_EXECUTABLE})")
10+
411
pybind11_add_module(PyDialectInitializer MODULE
512
PyDialectPythonBindings.cpp
613
)
@@ -12,9 +19,17 @@ set_target_properties(PyDialectInitializer
1219
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/src/lython/mlir/_mlir_libs"
1320
)
1421

22+
set(MLIR_PYTHON_CAPI_LIB "${CMAKE_SOURCE_DIR}/src/lython/mlir/_mlir_libs")
23+
1524
target_link_libraries(PyDialectInitializer
1625
PRIVATE
1726
PyDialect
27+
"${MLIR_PYTHON_CAPI_LIB}/libMLIRPythonCAPI${CMAKE_SHARED_LIBRARY_SUFFIX}"
28+
)
29+
30+
set_target_properties(PyDialectInitializer PROPERTIES
31+
BUILD_RPATH "${MLIR_PYTHON_CAPI_LIB}"
32+
INSTALL_RPATH "${MLIR_PYTHON_CAPI_LIB}"
1833
)
1934

2035
target_include_directories(PyDialectInitializer

src/lython/runtime/lyrt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <cstdint>
44

5+
#include "objects/bool.h"
6+
#include "objects/dict.h"
57
#include "objects/float.h"
68
#include "objects/function.h"
79
#include "objects/long.h"

0 commit comments

Comments
 (0)