Skip to content

Commit

Permalink
Add armv7hf and win32 build
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Mar 8, 2024
1 parent 5117167 commit 4326894
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
48 changes: 25 additions & 23 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
build-linux:
runs-on: ubuntu-20.04
strategy:
matrix:
target: ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "armv7-unknown-linux-gnueabihf"]
env:
CC: clang-18
CXX: clang-18
Expand All @@ -24,7 +27,7 @@ jobs:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt-get install -y crossbuild-essential-arm64
sudo apt-get install -y crossbuild-essential-arm64 crossbuild-essential-armhf
- uses: actions/cache@v4
with:
path: |
Expand All @@ -33,34 +36,29 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
run: |
rustup update
rustup toolchain install nightly
rustup target add --toolchain nightly x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
- name: Build x86_64
rustup target add --toolchain nightly ${{ matrix.target }}
- name: Build
env:
CARGO_HOST_LINKER: "clang-18"
CARGO_HOST_RUSTFLAGS: "-Clink-arg=-fuse-ld=lld-18"
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: "-Clinker-plugin-lto -Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18 -Clink-arg=--target=x86_64-unknown-linux-gnu"
run: cargo +nightly -Ztarget-applies-to-host -Zhost-config build --verbose --release --target=x86_64-unknown-linux-gnu
- uses: actions/upload-artifact@v4
with:
name: hath-rust-x86_64
path: target/x86_64-unknown-linux-gnu/release/hath-rust
- name: Build aarch64
env:
CARGO_HOST_LINKER: "clang-18"
CARGO_HOST_RUSTFLAGS: "-Clink-arg=-fuse-ld=lld-18"
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS: "-Clinker-plugin-lto -Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18 -Clink-arg=--target=aarch64-unknown-linux-gnu"
run: cargo +nightly -Ztarget-applies-to-host -Zhost-config build --verbose --release --target=aarch64-unknown-linux-gnu
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUSTFLAGS: "-Clinker-plugin-lto -Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18 -Clink-arg=--target=armv7-unknown-linux-gnueabihf"
run: cargo +nightly -Ztarget-applies-to-host -Zhost-config build --verbose --release --target=${{ matrix.target }}
- uses: actions/upload-artifact@v4
with:
name: hath-rust-aarch64
path: target/aarch64-unknown-linux-gnu/release/hath-rust
name: hath-rust-${{ matrix.target }}
path: target/${{ matrix.target }}/release/hath-rust
build-windows:
runs-on: windows-latest
strategy:
matrix:
target: ["x86_64-pc-windows-msvc", "i686-pc-windows-msvc"]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand All @@ -71,13 +69,17 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
run: |
rustup update
rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --verbose --release
run: cargo build --verbose --release --target ${{ matrix.target }}
- uses: actions/upload-artifact@v4
with:
name: hath-rust-windows
path: target/release/hath-rust.exe
name: hath-rust-${{ matrix.target }}
path: target/${{ matrix.target }}/release/hath-rust.exe
build-macos:
runs-on: macos-14
steps:
Expand All @@ -90,7 +92,7 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
run: |
rustup update
Expand All @@ -103,5 +105,5 @@ jobs:
run: lipo -create target/x86_64-apple-darwin/release/hath-rust target/aarch64-apple-darwin/release/hath-rust -output target/release/hath-rust
- uses: actions/upload-artifact@v4
with:
name: hath-rust-macos
name: hath-rust-universal-apple-darwin
path: target/release/hath-rust
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ axum = { version = "0.7", default-features = false, features = ["http1", "matche
bytes = "1.5"
chrono = "0.4"
clap = { version = "4.5", features = ["derive", "wrap_help"] }
cpufeatures = "0.2"
filesize = "0.2"
filetime = "0.2"
futures = "0.3"
Expand Down Expand Up @@ -39,6 +38,10 @@ tokio-stream = { version = "0.1", default-features = false, features = ["fs"] }
tower = { version = "0.4", features = ["util", "timeout"] }
tower-http = { version = "0.5", features = ["fs"] }

# cpufeatures not support all platforms
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))'.dependencies]
cpufeatures = "0.2"

[target.'cfg(not(any(target_env = "msvc", target_os = "macos")))'.dependencies]
tikv-jemallocator = { version = "0.5", features = ["background_threads", "unprefixed_malloc_on_supported_platforms"] }

Expand Down
5 changes: 4 additions & 1 deletion src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ impl RPCClient {
.and_then(|cert| cert.parse2(self.key.as_str()).ok());

if let Some(cert) = &cert {
let tomorrow = Asn1Time::from_unix(self.get_timestemp() + 86400).unwrap_or_else(|_| Asn1Time::days_from_now(1).unwrap());
let timestamp = (self.get_timestemp() as isize) // Maybe is 32 bit system
.checked_add(86400)
.map(|t| Asn1Time::from_unix(t.try_into().unwrap()).unwrap());
let tomorrow = timestamp.unwrap_or_else(|| Asn1Time::days_from_now(1).unwrap());
if cert.cert.is_some() && cert.pkey.is_some() && cert.cert.as_ref().unwrap().not_after() < tomorrow {
error!("The retrieved certificate is expired, or the system time is off by more than a day. Correct the system time and try again.");
return None;
Expand Down
14 changes: 12 additions & 2 deletions src/server/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub fn create_ssl_acceptor(cert: &ParsedPkcs12_2) -> SslAcceptor {
let _ = builder.set_num_tickets(1);

// From https://wiki.mozilla.org/Security/Server_Side_TLS#Old_backward_compatibility
cpufeatures::new!(cpuid_aes, "aes");
if !cpuid_aes::get() {
if !aes_support() {
// Not have AES hardware acceleration, prefer ChaCha20.
builder
.set_cipher_list(
Expand Down Expand Up @@ -64,3 +63,14 @@ pub fn create_ssl_acceptor(cert: &ParsedPkcs12_2) -> SslAcceptor {
}
builder.build()
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
fn aes_support() -> bool {
cpufeatures::new!(cpuid_aes, "aes");
cpuid_aes::get()
}

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
fn aes_support() -> bool {
false // Unable to check AES acceleration support, assumed negative.
}

0 comments on commit 4326894

Please sign in to comment.