Skip to content

Commit

Permalink
Merge pull request #184 from googlefan256/main
Browse files Browse the repository at this point in the history
Pythonビルドの修正
  • Loading branch information
googlefan256 authored Feb 23, 2025
2 parents baebe4e + 28e116e commit 38c5471
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/CI.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ubuntu:latest
RUN apt update && apt install openssl libssl-dev curl pkg-config software-properties-common -y && add-apt-repository ppa:deadsnakes/ppa && apt update && apt install python3.7 python3.8 python3.9 python3.10 python3.11 python3.12 python3.13 python3-pip python3 -y
ENV PIP_BREAK_SYSTEM_PACKAGES=1
RUN mkdir -p /root/.cache/sbv2 && curl https://huggingface.co/neody/sbv2-api-assets/resolve/main/dic/all.bin -o /root/.cache/sbv2/all.bin -L
47 changes: 29 additions & 18 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
# This file is autogenerated by maturin v1.7.1
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read
contents: write
id-token: write
packages: write

jobs:
linux:
python-linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
- runner: ubuntu-24.04-arm
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: docker build . -f .github/workflows/CI.Dockerfile --tag ci
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
container: ci
working-directory: ./crates/sbv2_bindings
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: ./crates/sbv2_bindings/dist

windows:
python-windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
Expand All @@ -75,7 +71,7 @@ jobs:
name: wheels-windows-${{ matrix.platform.target }}
path: ./crates/sbv2_bindings/dist

macos:
python-macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
Expand All @@ -100,7 +96,7 @@ jobs:
name: wheels-macos-${{ matrix.platform.target }}
path: ./crates/sbv2_bindings/dist

sdist:
python-sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -115,22 +111,37 @@ jobs:
with:
name: wheels-sdist
path: ./crates/sbv2_bindings/dist
python-wheel:
name: Wheel Upload
runs-on: ubuntu-latest
needs: [python-linux, python-windows, python-macos, python-sdist]
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- run: gh run download ${{ github.run_id }} -p wheels-*
- name: release
run: |
gh release create commit-${GITHUB_SHA:0:8} --prerelease wheels-*/*
release:
python-release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
needs: [python-linux, python-windows, python-macos, python-sdist]
environment: release
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/download-artifact@v4
- uses: actions/checkout@v4
- run: gh run download ${{ github.run_id }} -p wheels-*
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*

build:
docker:
runs-on: ${{ matrix.machine.runner }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -177,10 +188,10 @@ jobs:
tags: |
ghcr.io/${{ github.repository }}:latest-${{ matrix.tag }}-${{ matrix.machine.platform }}
merge:
docker-merge:
runs-on: ubuntu-latest
needs:
- build
- docker
steps:
- name: Download digests
uses: actions/download-artifact@v4
Expand Down
39 changes: 39 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sbv2_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ aivmx = ["npyz", "base64"]
base64 = ["dep:base64"]

[build-dependencies]
dirs = "6.0.0"
ureq = "3.0.6"
15 changes: 10 additions & 5 deletions crates/sbv2_core/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use dirs::home_dir;
use std::env;
use std::fs;
use std::io::copy;
use std::path::Path;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR")?;
let out_path = Path::new(&out_dir).join("all.bin");
if !out_path.exists() {
let static_path = home_dir().unwrap().join(".cache/sbv2/all.bin");
let out_path = PathBuf::from(&env::var("OUT_DIR").unwrap()).join("all.bin");
println!("cargo:rerun-if-changed=build.rs");
if static_path.exists() {
if fs::hard_link(&static_path, &out_path).is_err() {
fs::copy(static_path, out_path).unwrap();
};
} else {
println!("cargo:warning=Downloading dictionary file...");
let mut response =
ureq::get("https://huggingface.co/neody/sbv2-api-assets/resolve/main/dic/all.bin")
Expand All @@ -15,6 +21,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut file = fs::File::create(&out_path)?;
copy(&mut response, &mut file)?;
}
println!("cargo:rerun-if-changed=build.rs");
Ok(())
}

0 comments on commit 38c5471

Please sign in to comment.