From 81dff65713ef63cfab918decb9edacb2f32759ef Mon Sep 17 00:00:00 2001 From: MatthieuCoder Date: Fri, 20 Jan 2023 19:32:03 +0400 Subject: [PATCH] new build infrastructure --- .cargo/config.toml | 2 +- .ci/build.sh | 32 +++++++++++++++ .github/workflows/build.yml | 78 +++---------------------------------- Cargo.lock | 58 ++++++--------------------- Cargo.toml | 2 +- Cross.toml | 6 +++ Dockerfile.cross | 13 +++++++ exes/gateway/Cargo.toml | 2 +- libs/leash/src/lib.rs | 2 +- libs/proto/Cargo.toml | 2 +- 10 files changed, 73 insertions(+), 124 deletions(-) create mode 100755 .ci/build.sh create mode 100644 Cross.toml create mode 100644 Dockerfile.cross diff --git a/.cargo/config.toml b/.cargo/config.toml index 656e08b..c91c3f3 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [net] -git-fetch-with-cli = true \ No newline at end of file +git-fetch-with-cli = true diff --git a/.ci/build.sh b/.ci/build.sh new file mode 100755 index 0000000..0ff94c4 --- /dev/null +++ b/.ci/build.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +N=4 +i=0 +TARGETS=( + # Linux builds + "linux-arm64-gnuc:aarch64-unknown-linux-gnu" + "linux-arm64-musl:aarch64-unknown-linux-musl" + "linux-armv7-gnuc:armv7-unknown-linux-gnueabi" + "linux-armv7-musl:armv7-unknown-linux-musleabi" + "linux-86_64-gnuc:x86_64-unknown-linux-gnu" + "linux-86_64-musl:x86_64-unknown-linux-musl" + + # windows builds + "windows-86_64-gnu:x86_64-pc-windows-gnu" +) + +for thing in "${TARGETS[@]}"; do + KEY=${thing%%:*} + VALUE=${thing#*:} + + echo "* BUILDING FOR $VALUE" + cross build --release --target $VALUE + + # Copy intol folders + mkdir -p ./build/$KEY/ + cp target/$VALUE/release/* ./build/$KEY/ + + rm ./build/$KEY/*.{d,rlib} +done + +wait < <(jobs -p) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dfb9c89..d42eb8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,45 +66,13 @@ jobs: name: macos path: build/* - build_windows: - name: 'Build for Windows' - runs-on: windows-latest - - defaults: - run: - shell: msys2 {0} - - steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - uses: msys2/setup-msys2@v2 - with: - install: git mingw-w64-x86_64-go mingw-w64-x86_64-make mingw-w64-x86_64-protobuf mingw-w64-x86_64-rust mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn - - - name: Build all - run: | - export CGO_LDFLAGS='-lntdll -lWs2_32 -lcrypt32 -lSecur32 -luserenv -lNcrypt -lbcrypt' - mingw32-make.exe all - - uses: actions/upload-artifact@v3 - with: - name: windows - path: build/* - build_linux: name: 'Build for Linux' runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 + - uses: docker-practice/actions-setup-docker@master + timeout-minutes: 12 - uses: actions/cache@v3 with: path: | @@ -113,47 +81,11 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - uses: arduino/setup-protoc@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - uses: ATiltedTree/setup-rust@v1 - with: - rust-version: stable - - uses: actions/setup-go@v3 - with: - go-version: '1.18.4' - + key: ${{ runner.os }}-cargo - name: Build all run: | - make all + ./.ci/build.sh - uses: actions/upload-artifact@v3 with: - name: linux + name: release path: build/* - - release: - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/download-artifact@v3 - with: - name: windows - path: windows - - uses: actions/download-artifact@v3 - with: - name: linux_glibc - path: linux_glibc - - uses: actions/download-artifact@v3 - with: - name: macos - path: macos - - uses: ncipollo/release-action@v1 - with: - artifacts: "windows/*,macos/*,linux_glibc/*" - draft: true - generateReleaseNotes: true - skipIfReleaseExists: true diff --git a/Cargo.lock b/Cargo.lock index da521bd..0b7dcca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,15 +471,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "338089f42c427b86394a5ee60ff321da23a5c89c9d89514c829687b26359fcff" -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - [[package]] name = "criterion" version = "0.4.0" @@ -750,17 +741,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" -[[package]] -name = "flate2" -version = "1.0.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" -dependencies = [ - "crc32fast", - "libz-sys", - "miniz_oxide", -] - [[package]] name = "fnv" version = "1.0.7" @@ -1097,6 +1077,7 @@ dependencies = [ "rustls-native-certs", "tokio", "tokio-rustls", + "webpki-roots", ] [[package]] @@ -1234,17 +1215,6 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" -[[package]] -name = "libz-sys" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - [[package]] name = "linked-hash-map" version = "0.5.6" @@ -1719,12 +1689,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "pkg-config" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" - [[package]] name = "plotters" version = "0.3.4" @@ -2708,11 +2672,11 @@ dependencies = [ "futures-util", "log", "rustls", - "rustls-native-certs", "tokio", "tokio-rustls", "tungstenite", "webpki", + "webpki-roots", ] [[package]] @@ -2979,11 +2943,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba43f8e8dc9f92f61c9ac4d339f7a8483c3ebef2b4f56fe62fb19e151dc79dae" dependencies = [ "bitflags", - "flate2", "futures-util", "leaky-bucket-lite", "rustls", - "rustls-native-certs", "serde", "serde_json", "tokio", @@ -2993,6 +2955,7 @@ dependencies = [ "twilight-http", "twilight-model", "url", + "webpki-roots", ] [[package]] @@ -3138,12 +3101,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -3276,6 +3233,15 @@ dependencies = [ "untrusted", ] +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + [[package]] name = "which" version = "4.3.0" diff --git a/Cargo.toml b/Cargo.toml index 2c746fa..c26fa4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,4 +36,4 @@ tokio-test = "0.4.2" tracing-test = "0.2.3" tracing-subscriber = "0.3.16" test-log = { version = "*", features = ["trace"] } -env_logger = "0.10.0" \ No newline at end of file +env_logger = "0.10.0" diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..9fb3099 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,6 @@ +[build] +pre-build = [ + "dpkg --add-architecture $CROSS_DEB_ARCH", + "apt-get update && apt-get --assume-yes install libc6-dev", +] +dockerfile = "Dockerfile.cross" \ No newline at end of file diff --git a/Dockerfile.cross b/Dockerfile.cross new file mode 100644 index 0000000..7b37a9d --- /dev/null +++ b/Dockerfile.cross @@ -0,0 +1,13 @@ +ARG CROSS_BASE_IMAGE + +FROM debian as db +WORKDIR /dl +RUN apt-get update && apt-get install -y curl zip +RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip && \ + unzip protoc-21.12-linux-x86_64.zip -d protoc3 + +FROM $CROSS_BASE_IMAGE + +COPY --from=db /dl/protoc3 /dl/ +RUN mv /dl/bin/* /usr/local/bin/ && \ + mv /dl/include/* /usr/local/include/ diff --git a/exes/gateway/Cargo.toml b/exes/gateway/Cargo.toml index 3916138..3e6b8a5 100644 --- a/exes/gateway/Cargo.toml +++ b/exes/gateway/Cargo.toml @@ -18,7 +18,7 @@ serde = { workspace = true } serde_json = { workspace = true } tokio-stream = "0.1.11" -twilight-gateway = { version = "0.14" } +twilight-gateway = { default-features = false, features = ["rustls-webpki-roots"], version = "0.14" } twilight-model = "0.14" bytes = "1.3.0" async-nats = "0.26.0" diff --git a/libs/leash/src/lib.rs b/libs/leash/src/lib.rs index f3c9472..d45d6c8 100644 --- a/libs/leash/src/lib.rs +++ b/libs/leash/src/lib.rs @@ -133,7 +133,7 @@ where .recv() .await; #[cfg(not(unix))] - return tokio::signal::ctrl_c().await.unwrap(); + tokio::signal::ctrl_c().await.unwrap(); stop.send(()).unwrap(); shutdown_tracer_provider(); diff --git a/libs/proto/Cargo.toml b/libs/proto/Cargo.toml index 2556dfe..901249d 100644 --- a/libs/proto/Cargo.toml +++ b/libs/proto/Cargo.toml @@ -9,4 +9,4 @@ prost = "0.11.5" [build-dependencies] tonic-build = "0.8.4" -glob = "0.3.0" \ No newline at end of file +glob = "0.3.0" -- 2.39.5