Skip to content

Commit

Permalink
add cibuildwheel
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Nov 28, 2024
1 parent 1fb48f2 commit 3acb739
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 53 deletions.
11 changes: 7 additions & 4 deletions .github/actions/setup_base/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ runs:
id: canonicalize-cache-dir
shell: bash
run: |
if [[ "${{ inputs.os }}" == "almalinux" ]]; then
if [[ "${{ inputs.os }}" == "almalinux" ]] || [[ "${{ inputs.os }}" == "ubuntu" ]]; then
echo "cache-dir=/tmp/.container-cache" >> $GITHUB_OUTPUT
elif [[ "${{ inputs.os }}" == "macos" ]]; then
echo "cache-dir=/tmp/.container-cache" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -85,18 +85,18 @@ runs:
- name: "Install Python"
uses: actions/setup-python@v4
if: ${{ startsWith(inputs.os, 'macos') || startsWith(inputs.os, 'windows') }}
if: ${{ startsWith(inputs.os, 'macos') || startsWith(inputs.os, 'windows') || startsWith(inputs.os, 'ubuntu') }}
with:
python-version: ${{ inputs.python-version }}

- name: "Setup compiler/toolchain"
uses: aminya/setup-cpp@v1
if: ${{ startsWith(inputs.os, 'almalinux') || startsWith(inputs.os, 'windows') }}
if: ${{ startsWith(inputs.os, 'almalinux') || startsWith(inputs.os, 'ubuntu') || startsWith(inputs.os, 'windows') }}
with:
compiler: llvm-18
cmake: true
ninja: true
ccache: ${{ startsWith(inputs.os, 'windows') }}
ccache: ${{ startsWith(inputs.os, 'windows') || startsWith(inputs.os, 'ubuntu') }}
vcvarsall: ${{ startsWith(inputs.os, 'windows') }}

- name: "Set CC/CXX"
Expand All @@ -105,6 +105,9 @@ runs:
if [[ "${{ inputs.os }}" == "almalinux" ]]; then
echo "CC=/github/home/llvm/bin/clang" >> $GITHUB_ENV
echo "CXX=/github/home/llvm/bin/clang++" >> $GITHUB_ENV
elif [[ "${{ inputs.os }}" == "ubuntu" ]]; then
echo "CC=/usr/lib/llvm-18/bin/clang" >> $GITHUB_ENV
echo "CXX=/usr/lib/llvm-18/bin/clang++" >> $GITHUB_ENV
elif [[ "${{ inputs.os }}" == "windows" ]]; then
echo "CC=/C/Users/runneradmin/llvm/bin/clang-cl.exe" >> $GITHUB_ENV
echo "CXX=/C/Users/runneradmin/llvm/bin/clang-cl.exe" >> $GITHUB_ENV
Expand Down
55 changes: 43 additions & 12 deletions .github/workflows/build_test_eudsl.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Build and test EUDSL"
name: "Build and test and release EUDSL"

on:
workflow_dispatch:
Expand Down Expand Up @@ -38,10 +38,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: "manylinux_x86_64"
- name: "ubuntu_x86_64"
runs-on: "ubuntu-22.04"
container: "quay.io/pypa/manylinux_2_28_x86_64"
os: "almalinux"
os: "ubuntu"
- name: "windows_x86_64"
runs-on: "windows-2019"
os: "windows"
Expand Down Expand Up @@ -90,7 +89,12 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
export RELEASE_PREFIX="mlir_${{ matrix.name }}"
if [[ "${{ matrix.os }}" == "almalinux" ]] || [[ "${{ matrix.os }}" == "ubuntu" ]]; then
export RELEASE_PREFIX="mlir_manylinux_x86_64"
else
export RELEASE_PREFIX="mlir_${{ matrix.name }}"
fi
RELEASE_URL=$(gh release view latest --json assets -q '.assets |= sort_by(.createdAt) | .assets | map(select(.name | contains(env.RELEASE_PREFIX))) | .[-1] | .url')
curl -sLO $RELEASE_URL
tar xf $RELEASE_PREFIX*.tar.gz
Expand All @@ -99,10 +103,9 @@ jobs:
- name: "Build eudsl-tblgen"
id: build
run: |
pip install cibuildwheel
export EUDSL_SRC_DIR="$PWD/projects/eudsl"
ccache -z
$python3_command -m pip wheel "$EUDSL_SRC_DIR/eudsl-tblgen" -w wheelhouse
ccache -s
$python3_command -m cibuildwheel "$EUDSL_SRC_DIR/eudsl-tblgen" --output-dir wheelhouse
- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand All @@ -123,7 +126,7 @@ jobs:
uses: mxschmitt/[email protected]
with:
limit-access-to-actor: true
install-dependencies: ${{ startsWith(matrix.runs-on, 'macos') || startsWith(matrix.runs-on, 'windows') }}
install-dependencies: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'windows') || startsWith(matrix.os, 'ubuntu') }}

test-eudsl-tblgen:

Expand All @@ -133,10 +136,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: "manylinux_x86_64"
- name: "ubuntu_x86_64"
runs-on: "ubuntu-22.04"
container: "quay.io/pypa/manylinux_2_28_x86_64"
os: "almalinux"
os: "ubuntu"
- name: "windows_x86_64"
runs-on: "windows-2019"
os: "windows"
Expand Down Expand Up @@ -188,3 +190,32 @@ jobs:
else
$python3_command -m pytest --capture=tee-sys projects/eudsl/eudsl-tblgen/tests
fi
release-eudsl-tblgen:
if: ${{ github.event_name == 'workflow_dispatch' }}
needs: [test-eudsl-tblgen]
runs-on: "ubuntu-22.04"
name: "Release eudsl-tblgen"

permissions:
id-token: write
contents: write

steps:

- uses: actions/download-artifact@v4
with:
path: wheelhouse

- name: Release current commit
uses: ncipollo/[email protected]
with:
artifacts: "wheelhouse/eudsl_tblgen*.whl"
token: "${{ secrets.GITHUB_TOKEN }}"
tag: "latest"
name: "latest"
removeArtifacts: false
allowUpdates: true
replacesArtifacts: true
makeLatest: true
omitBody: true
13 changes: 8 additions & 5 deletions projects/eudsl/eudsl-tblgen/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[build-system]
requires = ["scikit-build-core>=0.10.7", "nanobind>=2.2.0"]
requires = ["scikit-build-core>=0.10.7", "nanobind>=2.2.0", "typing_extensions>=4.12.2"]
build-backend = "scikit_build_core.build"

[project]
name = "eudsl-tblgen"
version = "0.0.1"
requires-python = ">=3.8"
requires-python = ">=3.9"

[project.urls]
Homepage = "https://github.com/llvm/eudsl"
Expand All @@ -22,9 +22,12 @@ CMAKE_CXX_VISIBILITY_PRESET = "hidden"

[tool.cibuildwheel]
build-verbosity = 1
test-command = "pytest {project}/tests"
test-requires = "pytest"
test-skip="cp38-macosx_*:arm64"
skip = ["*-manylinux_i686", "*-musllinux*", "*-pypy*"]
manylinux-x86_64-image = "manylinux_2_28"
environment-pass = [
"LLVM_DIR",
"CMAKE_GENERATOR"
]

[tool.cibuildwheel.macos.environment]
MACOSX_DEPLOYMENT_TARGET = "10.14"
1 change: 1 addition & 0 deletions projects/eudsl/eudsl-tblgen/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(CMAKE_CXX_STANDARD 17)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
include(HandleLLVMOptions)

find_package(Python 3.8
REQUIRED COMPONENTS Interpreter Development.Module
Expand Down
69 changes: 37 additions & 32 deletions projects/eudsl/eudsl-tblgen/src/eudsl_tblgen_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,34 +361,25 @@ NB_MODULE(eudsl_tblgen_ext, m) {
})
.def_prop_ro("is_used", &RecordVal::isUsed);

nb::class_<ArrayRef<RecordVal>>(m, "ArrayRefofRecordVal");
struct RecordValues {};
auto valuesCl =
nb::class_<RecordValues>(m, "RecordValues", nb::dynamic_attr())
.def("__init__",
[](nb::object &self, ArrayRef<RecordVal> values) {
for (const RecordVal &recordVal : values) {
nb::setattr(self, recordVal.getName().str().c_str(),
nb::borrow(nb::cast(recordVal)));
}
})
.def("__repr__", [](const nb::object &self) {
nb::str s{"RecordValues("};
auto dic = nb::cast<nb::dict>(nb::getattr(self, "__dict__"));
int i = 0;
for (auto [key, value] : dic) {
s += key + nb::str("=") +
nb::str(nb::cast<RecordVal>(value)
.getValue()
->getAsUnquotedString()
.c_str());
if (i < dic.size() - 1)
s += nb::str(", ");
++i;
}
s += nb::str(")");
return s;
});
nb::class_<RecordValues>(m, "RecordValues", nb::dynamic_attr())
.def("__repr__", [](const nb::object &self) {
nb::str s{"RecordValues("};
auto dic = nb::cast<nb::dict>(nb::getattr(self, "__dict__"));
int i = 0;
for (auto [key, value] : dic) {
s += key + nb::str("=") +
nb::str(nb::cast<RecordVal>(value)
.getValue()
->getAsUnquotedString()
.c_str());
if (i < dic.size() - 1)
s += nb::str(", ");
++i;
}
s += nb::str(")");
return s;
});

nb::class_<Record>(m, "Record")
.def_prop_ro("direct_super_classes",
Expand Down Expand Up @@ -429,11 +420,25 @@ NB_MODULE(eudsl_tblgen_ext, m) {
"field_name"_a, nb::rv_policy::reference_internal)
.def("get_value_init", &Record::getValueInit, "field_name"_a,
nb::rv_policy::reference_internal)
.def_prop_ro("values",
[&valuesCl](Record &self) {
ArrayRef<RecordVal> values = self.getValues();
return valuesCl(values);
})
.def_prop_ro(
"values",
[](Record &self) {
// you can't just call the class_->operator()
nb::handle recordValsInstTy = nb::type<RecordValues>();
assert(recordValsInstTy.is_valid() &&
nb::type_check(recordValsInstTy));
nb::object recordValsInst = nb::inst_alloc(recordValsInstTy);
assert(nb::inst_check(recordValsInst) &&
recordValsInst.type().is(recordValsInstTy) &&
!nb::inst_ready(recordValsInst));

std::vector<RecordVal> values = self.getValues();
for (const RecordVal &recordVal : values) {
nb::setattr(recordValsInst, recordVal.getName().str().c_str(),
nb::borrow(nb::cast(recordVal)));
}
return recordValsInst;
})
.def("has_direct_super_class", &Record::hasDirectSuperClass,
"super_class"_a)
.def_prop_ro("is_anonymous", &Record::isAnonymous)
Expand Down

0 comments on commit 3acb739

Please sign in to comment.