From f54f41930fcbdea9fdc74b310d9aa2c4db6e36a8 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:47:40 +0800 Subject: [PATCH] Bump version 0.1.2 --- .github/workflows/install-cross.sh | 11 ++++ .github/workflows/publish-exe.yml | 85 ++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 28 ++++++++++ .gitignore | 1 + Cargo.toml | 2 +- build-apple.sh | 45 ++++++++++++++++ cbindgen.toml | 3 ++ src/lib.rs | 11 ++-- 8 files changed, 179 insertions(+), 7 deletions(-) create mode 100755 .github/workflows/install-cross.sh create mode 100644 .github/workflows/publish-exe.yml create mode 100644 .github/workflows/rust.yml create mode 100755 build-apple.sh create mode 100644 cbindgen.toml diff --git a/.github/workflows/install-cross.sh b/.github/workflows/install-cross.sh new file mode 100755 index 0000000..95b5c04 --- /dev/null +++ b/.github/workflows/install-cross.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +curl -s https://api.github.com/repos/cross-rs/cross/releases/latest \ + | grep cross-x86_64-unknown-linux-gnu.tar.gz \ + | cut -d : -f 2,3 \ + | tr -d \" \ + | wget -qi - + +tar -zxvf cross-x86_64-unknown-linux-gnu.tar.gz -C /usr/bin +rm -f cross-x86_64-unknown-linux-gnu.tar.gz + diff --git a/.github/workflows/publish-exe.yml b/.github/workflows/publish-exe.yml new file mode 100644 index 0000000..d927ddb --- /dev/null +++ b/.github/workflows/publish-exe.yml @@ -0,0 +1,85 @@ +on: + push: + tags: + - "v*.*.*" + +name: Publish Releases + +jobs: + build_publish: + name: Publishing Tasks + strategy: + matrix: + target: + - x86_64-unknown-linux-gnu + - x86_64-unknown-linux-musl + - i686-unknown-linux-musl + - aarch64-unknown-linux-gnu + - armv7-unknown-linux-gnueabihf + - x86_64-apple-darwin + - aarch64-apple-darwin + - x86_64-pc-windows-msvc + - i686-pc-windows-msvc + + include: + - target: x86_64-unknown-linux-gnu + host_os: ubuntu-latest + - target: x86_64-unknown-linux-musl + host_os: ubuntu-latest + - target: i686-unknown-linux-musl + host_os: ubuntu-latest + - target: aarch64-unknown-linux-gnu + host_os: ubuntu-latest + - target: armv7-unknown-linux-gnueabihf + host_os: ubuntu-latest + - target: x86_64-apple-darwin + host_os: macos-latest + - target: aarch64-apple-darwin + host_os: macos-latest + - target: x86_64-pc-windows-msvc + host_os: windows-latest + - target: i686-pc-windows-msvc + host_os: windows-latest + + runs-on: ${{ matrix.host_os }} + steps: + - uses: actions/checkout@v3 + + - name: Prepare + shell: bash + run: | + mkdir mypubdir4 + rustup target add ${{ matrix.target }} + if [[ "${{ matrix.host_os }}" == "ubuntu-latest" ]]; then + sudo .github/workflows/install-cross.sh + fi + + - name: Build + shell: bash + run: | + if [[ "${{ matrix.host_os }}" == "ubuntu-latest" ]]; then + cross build --all-features --release --target ${{ matrix.target }} + else + cargo build --all-features --release --target ${{ matrix.target }} + fi + cbindgen --config cbindgen.toml -l C -o target/dns2socks-ffi.h + if [[ "${{ matrix.host_os }}" == "windows-latest" ]]; then + powershell -Command "(Get-Item README.md).LastWriteTime = Get-Date" + powershell Compress-Archive -Path target/${{ matrix.target }}/release/dns2socks.exe, README.md, target/dns2socks-ffi.h, target/${{ matrix.target }}/release/dns2socks.dll -DestinationPath mypubdir4/dns2socks-${{ matrix.target }}.zip + elif [[ "${{ matrix.host_os }}" == "macos-latest" ]]; then + zip -j mypubdir4/dns2socks-${{ matrix.target }}.zip target/${{ matrix.target }}/release/dns2socks README.md target/dns2socks-ffi.h target/${{ matrix.target }}/release/libdns2socks.dylib + if [[ "${{ matrix.target }}" == "x86_64-apple-darwin" ]]; then + ./build-apple.sh + zip -r mypubdir4/dns2socks-apple-xcframework.zip ./dns2socks.xcframework/ + fi + elif [[ "${{ matrix.host_os }}" == "ubuntu-latest" ]]; then + zip -j mypubdir4/dns2socks-${{ matrix.target }}.zip target/${{ matrix.target }}/release/dns2socks README.md target/dns2socks-ffi.h target/${{ matrix.target }}/release/libdns2socks.so + fi + + - name: Publish + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: mypubdir4/* + diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..cee061d --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,28 @@ +name: Push or PR + +on: + [push, pull_request] + +env: + CARGO_TERM_COLOR: always + +jobs: + build_n_test: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + - name: rustfmt + run: | + rustc --version + cargo fmt --all -- --check + - name: check + run: cargo check --verbose + - name: clippy + run: cargo clippy --all-targets --all-features -- -D warnings + - name: Build + run: cargo build --verbose --tests --all-features diff --git a/.gitignore b/.gitignore index 9d70320..7889bbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +dns2socks.xcframework/ Cargo.lock .vscode/ .VSCodeCounter/ diff --git a/Cargo.toml b/Cargo.toml index 09eeaa0..3b820cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dns2socks" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "MIT" repository = "https://github.com/ssrlive/dns2socks" diff --git a/build-apple.sh b/build-apple.sh new file mode 100755 index 0000000..bc5d3b3 --- /dev/null +++ b/build-apple.sh @@ -0,0 +1,45 @@ +#! /bin/sh + +echo "Setting up the rust environment..." +rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios x86_64-apple-darwin aarch64-apple-darwin +cargo install cbindgen + +echo "Building..." +cargo build --release --target x86_64-apple-darwin +cargo build --release --target aarch64-apple-darwin +cargo build --release --target aarch64-apple-ios +cargo build --release --target x86_64-apple-ios +cargo build --release --target aarch64-apple-ios-sim + +echo "Generating includes..." +mkdir -p target/include/ +cbindgen --config cbindgen.toml -l C -o target/include/dns2socks.h +cat > target/include/module.modulemap <