From f04a96d69f83d974414be31c011f055d6591b7bb Mon Sep 17 00:00:00 2001 From: iHsin Date: Fri, 12 Apr 2024 21:34:46 +0800 Subject: [PATCH] refactor(ci): use cross (#368) * refactor: use cross * ci: change job name * ci: add static-crt builds * ci: add missing tokio_unstable * build: remove eyre * ci: fix cv mistake * ci: replace armv7 static-crt with musl * cI: change cache key * ci: remove old files --- .cargo/config | 15 - .github/release.yaml | 11 - .github/workflows/ci.yml | 310 ++++++++++++++---- Cargo.lock | 180 ++-------- Cross.toml | 9 + clash_lib/Cargo.toml | 4 +- clash_lib/src/common/errors.rs | 7 +- clash_lib/src/proxy/utils/test_utils/mod.rs | 4 +- .../src/proxy/vmess/vmess_impl/stream.rs | 9 +- scripts/build.sh | 172 ---------- scripts/cmake/aarch64-musl.cmake | 3 - scripts/cmake/arm-musl.cmake | 3 - scripts/cmake/armhf-musl.cmake | 3 - scripts/cmake/armv7-musl.cmake | 3 - scripts/cmake/armv7hf-musl.cmake | 3 - scripts/cmake/x86_64-musl.cmake | 3 - 16 files changed, 294 insertions(+), 445 deletions(-) delete mode 100644 .github/release.yaml create mode 100644 Cross.toml delete mode 100644 scripts/build.sh delete mode 100644 scripts/cmake/aarch64-musl.cmake delete mode 100644 scripts/cmake/arm-musl.cmake delete mode 100644 scripts/cmake/armhf-musl.cmake delete mode 100644 scripts/cmake/armv7-musl.cmake delete mode 100644 scripts/cmake/armv7hf-musl.cmake delete mode 100644 scripts/cmake/x86_64-musl.cmake diff --git a/.cargo/config b/.cargo/config index 3420c1fc8..13c84ae1c 100644 --- a/.cargo/config +++ b/.cargo/config @@ -4,18 +4,3 @@ rustflags = ["--cfg", "tokio_unstable"] [env] RUST_LOG = { value = "clash=trace" } - -[target.aarch64-unknown-linux-gnu] -linker = "/usr/bin/aarch64-linux-gnu-gcc" - -[target.armv7-unknown-linux-gnueabihf] -linker = "/usr/bin/arm-linux-gnueabihf-gcc" - -[target.armv7-unknown-linux-gnueabi] -linker = "/usr/bin/arm-linux-gnueabi-gcc" - -[target.arm-unknown-linux-gnueabihf] -linker = "/usr/bin/arm-linux-gnueabihf-gcc" - -[target.arm-unknown-linux-gnueabi] -linker = "/usr/bin/arm-linux-gnueabi-gcc" \ No newline at end of file diff --git a/.github/release.yaml b/.github/release.yaml deleted file mode 100644 index 7aa8ef72b..000000000 --- a/.github/release.yaml +++ /dev/null @@ -1,11 +0,0 @@ -changelog: - categories: - - title: 🏕 Features - labels: - - '*' - exclude: - labels: - - dependencies - - title: 👒 Dependencies - labels: - - dependencies diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5756a387..bc03d0f83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,71 +3,261 @@ name: Build/Test/Release on: push: tags: [ "v*" ] + branches: [ "master" ] pull_request: branches: [ "master" ] +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + PACKAGE: "clash" + jobs: - test: - name: test ${{ matrix.platforms.target }} on ${{ matrix.platforms.os }} static - ${{ matrix.static }} + compile: + name: ${{ matrix.release-name || matrix.target || 'Unknown' }} + permissions: + contents: write + runs-on: ${{ matrix.os || 'ubuntu-latest' }} strategy: + fail-fast: false matrix: - static: [true, false] - platforms: [ - {os: ubuntu-22.04, target: x86_64-unknown-linux-gnu}, - {os: ubuntu-22.04, target: aarch64-unknown-linux-gnu}, - {os: ubuntu-22.04, target: armv7-unknown-linux-gnueabihf}, - {os: ubuntu-22.04, target: armv7-unknown-linux-gnueabi}, - {os: macos-13, target: aarch64-apple-darwin}, - {os: macos-13, target: x86_64-apple-darwin}, - {os: windows-2022, target: x86_64-pc-windows-msvc}, - ] - runs-on: ${{ matrix.platforms.os }} + include: + # Example + # when not set, default will be used (except target, cross) + # - os: ubuntu-latest + # target: x86_64-unknown-linux-gnu + # release-name: x86_64-linux + # toolchain: stable + # cross: true + # postfix: "" + # extra-args: "" + # components: "" + # rustflags: "" + + # Linux x86 + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + cross: true + extra-args: "--all-features" + - os: ubuntu-latest + target: i686-unknown-linux-gnu + cross: true + extra-args: "--all-features" + # Linux x86 static-crt + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + release-name: x86_64-unknown-linux-gnu-static-crt + cross: true + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + - os: ubuntu-latest + target: i686-unknown-linux-gnu + release-name: i686-unknown-linux-gnu-static-crt + cross: true + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + # Linux arm + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + cross: true + extra-args: "--all-features" + - os: ubuntu-latest + target: armv7-unknown-linux-gnueabi + cross: true + extra-args: "--all-features" + - os: ubuntu-latest + target: armv7-unknown-linux-gnueabihf + cross: true + extra-args: "--all-features" + # Linux arm static-crt + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + release-name: aarch64-unknown-linux-gnu-static-crt + cross: true + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + - os: ubuntu-latest + target: armv7-unknown-linux-gnueabi + release-name: armv7-unknown-linux-gnueabi-static-crt + cross: true + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + - os: ubuntu-latest + target: armv7-unknown-linux-musleabihf + cross: true + extra-args: "--all-features" + rustflags: "--cfg tokio_unstable" + # Windows + - os: windows-latest + target: x86_64-pc-windows-msvc + cross: false + postfix: ".exe" + extra-args: "--all-features" + - os: windows-latest + target: i686-pc-windows-msvc + cross: false + postfix: ".exe" + extra-args: "--all-features" + # Windows static-crt + - os: windows-latest + target: x86_64-pc-windows-msvc + release-name: x86_64-pc-windows-msvc-static-crt + cross: false + postfix: ".exe" + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + - os: windows-latest + target: i686-pc-windows-msvc + release-name: i686-pc-windows-msvc-static-crt + cross: false + postfix: ".exe" + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + # MacOSX + - os: macos-12 + target: x86_64-apple-darwin + cross: false + extra-args: "--all-features" + - os: macos-14 + target: aarch64-apple-darwin + cross: false + extra-args: "--all-features" + # MacOSX static-crt + - os: macos-12 + target: x86_64-apple-darwin + release-name: x86_64-apple-darwin-static-crt + cross: false + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + - os: macos-14 + target: aarch64-apple-darwin + release-name: aarch64-apple-darwin-static-crt + cross: false + extra-args: "--all-features" + rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable" + # Linux mips: tier-3, pity + # Linux risc-v: needs update rustls + # Windows gnu: tokio dont work + # Windows aarch: todo + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ matrix.release-name || matrix.target }}-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + ${{ matrix.release-name || matrix.target }} + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.toolchain || 'stable' }} + target: ${{ matrix.target }} + components: ${{ matrix.components || 'rustfmt, clippy' }} + + - name: Cargo fmt + uses: clechasseur/rs-cargo@v2 + with: + use-cross: ${{ matrix.cross }} + command: fmt + args: --all -- --check + + - name: Cargo clippy + uses: clechasseur/rs-cargo@v2 + with: + use-cross: ${{ matrix.cross }} + command: clippy + args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }} -- -D warnings + env: + RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }} + - name: Cargo test + uses: clechasseur/rs-cargo@v2 + if: startsWith(matrix.os, 'ubuntu') + with: + use-cross: ${{ matrix.cross }} + command: test + args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }} + env: + CROSS_CONTAINER_OPTS: "--network host" + RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }} + + - name: Cargo test (no docker test) + uses: clechasseur/rs-cargo@v2 + if: ${{ !startsWith(matrix.os, 'ubuntu') }} + with: + use-cross: ${{ matrix.cross }} + command: test + args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }} + env: + CLASH_RS_CI: "true" + RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }} + + - name: Cargo build + uses: clechasseur/rs-cargo@v2 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --release --target ${{ matrix.target }} ${{ matrix.extra-args }} + env: + RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }} + + - name: Rename binary + run: mv target/${{ matrix.target }}/release/${{ env.PACKAGE }}${{ matrix.postfix }} ${{ env.PACKAGE }}-${{ matrix.release-name || matrix.target }}${{ matrix.postfix }} + + - name: Upload binaries + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.release-name || matrix.target }} + path: ${{ env.PACKAGE }}-${{ matrix.release-name || matrix.target }}${{ matrix.postfix }} + + release: + name: Release + + needs: [compile] + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - uses: ilammy/setup-nasm@v1 - if : ${{ matrix.platforms.os == 'windows-2022' }} - - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: rustfmt, clippy - - name: Run cargo fmt - run: cargo fmt --all -- --check - - name: Run cargo check - run: cargo check --all --all-features - - name: Run cargo clippy - run: cargo clippy --all --all-features -- -D warnings - - name: Run cargo test on Linux - if: ${{ matrix.platforms.os == 'ubuntu-22.04' }} - run: cargo test --all --all-features - - name: Run cargo test on non LInux - env: # this is a bit counter intuitive - some tests relies on Docker to run and are marked not(ci), but macos runner doesn't have Docker installed, so we make it "ci" to bypass those tests - CLASH_RS_CI: 'true' - if: ${{ matrix.platforms.os != 'ubuntu-22.04' }} - run: cargo test --all --all-features - - name: Build artifacts - run: sh ./scripts/build.sh "${{ matrix.platforms.target }}" "${{ matrix.static }}" - - name: Stash artifacts - uses: actions/upload-artifact@v4 - with: - name: clash-${{ matrix.platforms.os }}-${{ matrix.platforms.target }}-${{ matrix.static }} - path: target/artifacts/ - - - - name: Create Release - if: contains(github.ref, 'tags/v') - id: create_release - uses: softprops/action-gh-release@v2 - with: - generate_release_notes: true - - name: Upload Release Asset - if: contains(github.ref, 'tags/v') - id: upload-release-asset - uses: dwenegar/upload-release-assets@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - release_id: ${{ steps.create_release.outputs.id }} - assets_path: target/artifacts + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Merge binaries + uses: actions/upload-artifact/merge@v4 + with: + name: binaries + pattern: '*' + retention-days: 1 + + - name: Download binaries + uses: actions/download-artifact@v4 + with: + name: binaries + path: ./packages + + - name: Github stable release + uses: "mathieucarbou/marvinpinto-action-automatic-releases@master" + if: startsWith(github.ref, 'refs/tags/v') + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false + files: | + packages/* + LICENSE + + - name: Github nightly release + uses: "mathieucarbou/marvinpinto-action-automatic-releases@master" + if: startsWith(github.ref, 'refs/heads/master') + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: true + automatic_release_tag: "latest" + files: | + packages/* + LICENSE diff --git a/Cargo.lock b/Cargo.lock index c1f84875a..a6bb4f26d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -160,15 +160,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.13" @@ -386,17 +377,6 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.2.0" @@ -565,15 +545,13 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bindgen" -version = "0.59.2" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ "bitflags 1.3.2", "cexpr", "clang-sys", - "clap 2.34.0", - "env_logger", "lazy_static", "lazycell", "log", @@ -583,6 +561,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "syn 1.0.109", "which", ] @@ -734,7 +713,7 @@ dependencies = [ "ip_network_table", "libc", "nix", - "parking_lot 0.12.1", + "parking_lot", "rand_core", "ring 0.17.8", "tracing", @@ -953,21 +932,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", -] - [[package]] name = "clap" version = "4.5.4" @@ -1012,7 +976,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" name = "clash" version = "0.1.15" dependencies = [ - "clap 4.5.4", + "clap", "clash_lib", ] @@ -1267,7 +1231,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.5.4", + "clap", "criterion-plot", "futures", "is-terminal", @@ -1508,7 +1472,7 @@ dependencies = [ "hashbrown 0.14.3", "lock_api", "once_cell", - "parking_lot_core 0.9.9", + "parking_lot_core", ] [[package]] @@ -1886,19 +1850,6 @@ dependencies = [ "syn 2.0.55", ] -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -1977,7 +1928,7 @@ checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall", "windows-sys 0.52.0", ] @@ -2380,15 +2331,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -2464,7 +2406,7 @@ dependencies = [ "ipconfig", "lru-cache", "once_cell", - "parking_lot 0.12.1", + "parking_lot", "rand", "resolv-conf", "rustls 0.21.8", @@ -2868,15 +2810,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "integer-encoding" version = "3.0.4" @@ -2950,7 +2883,7 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", "windows-sys 0.52.0", ] @@ -3080,7 +3013,7 @@ checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ "bitflags 2.5.0", "libc", - "redox_syscall 0.4.1", + "redox_syscall", ] [[package]] @@ -3472,7 +3405,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", ] @@ -3722,17 +3655,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3740,21 +3662,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.9", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -3765,7 +3673,7 @@ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall", "smallvec", "windows-targets 0.48.5", ] @@ -3970,7 +3878,7 @@ dependencies = [ "atomic", "crossbeam-queue", "futures", - "parking_lot 0.12.1", + "parking_lot", "pin-project", "static_assertions", "thiserror", @@ -4308,15 +4216,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -4871,7 +4770,7 @@ dependencies = [ "futures", "lazy_static", "log", - "parking_lot 0.12.1", + "parking_lot", "serial_test_derive", ] @@ -5163,12 +5062,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -5283,30 +5176,12 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "termtree" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.58" @@ -5435,7 +5310,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -6548,15 +6423,14 @@ dependencies = [ [[package]] name = "tracing-oslog" version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bc58223383423483e4bc056c7e7b3f77bdee924a9d33834112c69ead06dc847" +source = "git+https://github.com/Absolucy/tracing-oslog.git?branch=main#2207764b7edd3a5c059f4c3e8837fe72127067f9" dependencies = [ - "bindgen 0.59.2", + "bindgen 0.64.0", "cc", "cfg-if", "fnv", "once_cell", - "parking_lot 0.11.2", + "parking_lot", "tracing-core", "tracing-subscriber", ] @@ -6656,7 +6530,7 @@ source = "git+https://github.com/Itsusinn/tuic.git?rev=82fab62#82fab626d6344f69f dependencies = [ "bytes", "futures-util", - "parking_lot 0.12.1", + "parking_lot", "register-count", "thiserror", "uuid", @@ -6753,12 +6627,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" - [[package]] name = "universal-hash" version = "0.5.1" @@ -6852,12 +6720,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 000000000..47efca849 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,9 @@ + +[build] +# zig = "2.17" +# pre-build = "./.github/prebuild.sh" + +[build.env] +# Docker in docker +volumes = ["/var/run/docker.sock=/var/run/docker.sock"] +# passthrough = ["VAR1_ARG", "VAR2_ARG=VALUE"] \ No newline at end of file diff --git a/clash_lib/Cargo.toml b/clash_lib/Cargo.toml index dfe7a277a..d44d14d77 100644 --- a/clash_lib/Cargo.toml +++ b/clash_lib/Cargo.toml @@ -15,7 +15,7 @@ tokio = { version = "1", features = ["full"] } tokio-util = { version = "0.7", features = ["net", "codec", "io", "compat"] } thiserror = "1.0" async-trait = "0.1" -anyhow = "1.0" +anyhow = "1" futures = "0.3" bytes = "1.6" async-recursion = "1" @@ -99,7 +99,7 @@ tokio-tungstenite = "0.21.0" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } -tracing-oslog = "0.1" +tracing-oslog = { branch = "main", git = "https://github.com/Absolucy/tracing-oslog.git" } tracing-appender = "0.2.3" diff --git a/clash_lib/src/common/errors.rs b/clash_lib/src/common/errors.rs index 8b1994f36..fbc23e75a 100644 --- a/clash_lib/src/common/errors.rs +++ b/clash_lib/src/common/errors.rs @@ -4,6 +4,9 @@ pub fn new_io_error(msg: &str) -> io::Error { io::Error::new(io::ErrorKind::Other, msg) } -pub fn map_io_error(err: T) -> io::Error { - io::Error::new(io::ErrorKind::Other, err.to_string()) +pub fn map_io_error(err: T) -> io::Error +where + T: Into + Send, +{ + io::Error::new(io::ErrorKind::Other, format!("{:?}", anyhow::anyhow!(err))) } diff --git a/clash_lib/src/proxy/utils/test_utils/mod.rs b/clash_lib/src/proxy/utils/test_utils/mod.rs index da04bcdac..cee304d15 100644 --- a/clash_lib/src/proxy/utils/test_utils/mod.rs +++ b/clash_lib/src/proxy/utils/test_utils/mod.rs @@ -87,7 +87,7 @@ pub async fn ping_pong_test(handler: Arc, port: u16) -> any .write_all(chunk.as_bytes()) .await .inspect_err(|x| { - tracing::error!("proxy_fn write error: {}", x); + tracing::error!("proxy_fn write error: {x:?}"); })?; } write_half.flush().await?; @@ -96,7 +96,7 @@ pub async fn ping_pong_test(handler: Arc, port: u16) -> any for _ in 0..100 { read_half.read_exact(&mut buf).await.inspect_err(|x| { - tracing::error!("proxy_fn read error: {}", x); + tracing::error!("proxy_fn read error: {x:?}"); })?; assert_eq!(buf, "world".as_bytes().to_owned()); } diff --git a/clash_lib/src/proxy/vmess/vmess_impl/stream.rs b/clash_lib/src/proxy/vmess/vmess_impl/stream.rs index 982b040ce..1e97f6dc3 100644 --- a/clash_lib/src/proxy/vmess/vmess_impl/stream.rs +++ b/clash_lib/src/proxy/vmess/vmess_impl/stream.rs @@ -167,18 +167,19 @@ where } SECURITY_CHACHA20_POLY1305 => { let mut key = [0u8; 32]; - let tmp = utils::md5(&req_body_key); - key.copy_from_slice(&tmp); + key[..16].copy_from_slice(&utils::md5(&req_body_key)); let tmp = utils::md5(&key[..16]); key[16..].copy_from_slice(&tmp); + let write_cipher = VmessSecurity::ChaCha20Poly1305(ChaCha20Poly1305::new_with_slice(&key)); let write_cipher = AeadCipher::new(&req_body_iv, write_cipher); - let tmp = utils::md5(&req_body_key); - key.copy_from_slice(&tmp); + let mut key = [0u8; 32]; + key[..16].copy_from_slice(&utils::md5(&resp_body_key)); let tmp = utils::md5(&key[..16]); key[16..].copy_from_slice(&tmp); + let reader_cipher = VmessSecurity::ChaCha20Poly1305(ChaCha20Poly1305::new_with_slice(&key)); let read_cipher = AeadCipher::new(&resp_body_iv, reader_cipher); diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100644 index d543ef3d9..000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,172 +0,0 @@ -#!/bin/sh - -set -xe - -[ ! -d "target/artifacts" ] && mkdir -p target/artifacts - -os=`uname` -case $os in - Linux) - sudo apt update - sudo apt install -y gcc-multilib gcc make musl-dev musl-tools - ;; -esac - -llvm_version=16 - -install_llvm() { - status=$(command -v -- "clang-$llvm_version" > /dev/null 2>&1; echo $?) - if [ $status -ne 0 ]; then - wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh - chmod +x /tmp/llvm.sh - sudo /tmp/llvm.sh $llvm_version - fi -} - -ROOT_DIR=`git rev-parse --show-toplevel` - - -for TARGET in $1; do - TARGET=`echo "$TARGET" | tr -d '[:space:]' | tr -d '\n' | tr -d '\r'` - echo "building for $TARGET(static: $2)" - rustup target add $TARGET - - case $TARGET in - x86_64-unknown-linux-musl) - install_llvm - export CC=clang-$llvm_version - export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld" - export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/x86_64-musl.cmake - ;; - aarch64-unknown-linux-gnu) - sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu libc6-dev-arm64-cross - export CC=aarch64-linux-gnu-gcc - export CXX=aarch64-linux-gnu-g++ - export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/aarch64-linux-gnu" - ;; - aarch64-unknown-linux-musl) - sudo apt install -y libc6-dev-arm64-cross - install_llvm - export CC=clang-$llvm_version - export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld --sysroot=/usr/aarch64-linux-gnu" - export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/aarch64-linux-gnu" - export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/aarch64-musl.cmake - ;; - arm-unknown-linux-gnueabi | armv7-unknown-linux-gnueabi) - sudo apt install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi binutils-arm-linux-gnueabi libc6-dev-armel-cross - export CC=arm-linux-gnueabi-gcc - export CXX=arm-linux-gnueabi-g++ - ;; - arm-unknown-linux-gnueabihf | armv7-unknown-linux-gnueabihf) - sudo apt install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf binutils-arm-linux-gnueabihf libc6-dev-armhf-cross - export CC=arm-linux-gnueabihf-gcc - export CXX=arm-linux-gnueabihf-g++ - ;; - arm-unknown-linux-musleabi) - sudo apt install -y libc6-dev-armel-cross - install_llvm - export CC=clang-$llvm_version - export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabi" - export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/arm-musl.cmake - ;; - arm-unknown-linux-musleabihf) - sudo apt install -y libc6-dev-armhf-cross - install_llvm - export CC=clang-$llvm_version - export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabihf" - export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/armhf-musl.cmake - ;; - armv7-unknown-linux-musleabi) - sudo apt install -y libc6-dev-armel-cross - install_llvm - export CC=clang-$llvm_version - export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabi" - export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/armv7-musl.cmake - ;; - armv7-unknown-linux-musleabihf) - sudo apt install -y libc6-dev-armhf-cross - install_llvm - export CC=clang-$llvm_version - export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabihf" - export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/armv7hf-musl.cmake - ;; - i686-unknown-linux-gnu) - sudo apt install -y libc6-dev-i386 - ;; - mips-unknown-linux-gnu) - sudo apt install -y gcc-mips-linux-gnu g++-mips-linux-gnu binutils-mips-linux-gnu libc6-dev-mips-cross - export CC=mips-linux-gnu-gcc - export CXX=mips-linux-gnu-g++ - ;; - mipsel-unknown-linux-gnu) - sudo apt install -y gcc-mipsel-linux-gnu g++-mipsel-linux-gnu binutils-mipsel-linux-gnu libc6-dev-mipsel-cross - export CC=mipsel-linux-gnu-gcc - export CXX=mipsel-linux-gnu-g++ - ;; - mips64-unknown-linux-gnuabi64) - sudo apt install -y gcc-mips64-linux-gnuabi64 g++-mips64-linux-gnuabi64 binutils-mips64-linux-gnuabi64 libc6-dev-mips64-cross - export CC=mips64-linux-gnuabi64-gcc - export CXX=mips64-linux-gnuabi64-g++ - ;; - mips64el-unknown-linux-gnuabi64) - sudo apt install -y gcc-mips64el-linux-gnuabi64 g++-mips64el-linux-gnuabi64 binutils-mips64el-linux-gnuabi64 libc6-dev-mips64el-cross - export CC=mips64el-linux-gnuabi64-gcc - export CXX=mips64el-linux-gnuabi64-g++ - ;; - powerpc-unknown-linux-gnu) - sudo apt install -y gcc-powerpc-linux-gnu g++-powerpc-linux-gnu binutils-powerpc-linux-gnu libc6-dev-powerpc-cross - export CC=powerpc-linux-gnu-gcc - export CXX=powerpc-linux-gnu-g++ - ;; - powerpc64-unknown-linux-gnu) - sudo apt install -y gcc-powerpc64-linux-gnu g++-powerpc64-linux-gnu binutils-powerpc64-linux-gnu libc6-dev-powerpc64-cross - export CC=powerpc64-linux-gnu-gcc - export CXX=powerpc64-linux-gnu-g++ - ;; - powerpc64le-unknown-linux-gnu) - sudo apt install -y gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu binutils-powerpc64le-linux-gnu libc6-dev-powerpc64le-cross - export CC=powerpc64le-linux-gnu-gcc - export CXX=powerpc64le-linux-gnu-g++ - ;; - s390x-unknown-linux-gnu) - sudo apt install -y gcc-s390x-linux-gnu g++-s390x-linux-gnu binutils-s390x-linux-gnu libc6-dev-s390x-cross - export CC=s390x-linux-gnu-gcc - export CXX=s390x-linux-gnu-g++ - ;; - riscv64gc-unknown-linux-gnu) - sudo apt install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu binutils-riscv64-linux-gnu libc6-dev-riscv64-cross - export CC=riscv64-linux-gnu-gcc - export CXX=riscv64-linux-gnu-g++ - ;; - esac - - case $TARGET in - *musl*) - if [ "$2" = "true" ]; then - export RUSTFLAGS="-Clinker=rust-lld -Clink-self-contained=yes -Ctarget-feature=+crt-static" - else - export RUSTFLAGS="-Clinker=rust-lld" - fi - ;; - *) - if [ "$2" = "true" ]; then - export RUSTFLAGS="-Ctarget-feature=+crt-static" - fi - ;; - esac - - OUTPUT_BIN=./target/artifacts/clash-$TARGET - if [ "$2" = "true" ]; then - OUTPUT_BIN=$OUTPUT_BIN-static-crt - fi - - cargo build -p clash --target $TARGET --release - ls -l ./target/$TARGET/release/ - mv ./target/$TARGET/release/clash $OUTPUT_BIN -done diff --git a/scripts/cmake/aarch64-musl.cmake b/scripts/cmake/aarch64-musl.cmake deleted file mode 100644 index 7f363ed53..000000000 --- a/scripts/cmake/aarch64-musl.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR aarch64) -set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/arm-musl.cmake b/scripts/cmake/arm-musl.cmake deleted file mode 100644 index 5d825ca5f..000000000 --- a/scripts/cmake/arm-musl.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR arm) -set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/armhf-musl.cmake b/scripts/cmake/armhf-musl.cmake deleted file mode 100644 index c11e52db3..000000000 --- a/scripts/cmake/armhf-musl.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR armhf) -set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/armv7-musl.cmake b/scripts/cmake/armv7-musl.cmake deleted file mode 100644 index 08da48447..000000000 --- a/scripts/cmake/armv7-musl.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR armv7) -set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/armv7hf-musl.cmake b/scripts/cmake/armv7hf-musl.cmake deleted file mode 100644 index 664af8d59..000000000 --- a/scripts/cmake/armv7hf-musl.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR armv7hf) -set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/x86_64-musl.cmake b/scripts/cmake/x86_64-musl.cmake deleted file mode 100644 index 9eee6d80f..000000000 --- a/scripts/cmake/x86_64-musl.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR x86_64) -set(CMAKE_LINKER ld.ldd) \ No newline at end of file