Skip to content

Commit

Permalink
Merge pull request #97 from wcampbell0x2a/add-msrv-improve-ci
Browse files Browse the repository at this point in the history
Update CI, add MSRV, add static musl build
  • Loading branch information
genonullfree committed Feb 4, 2023
2 parents 68483b1 + cb5ef35 commit a3b9dd4
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .cargo/config
@@ -0,0 +1,2 @@
[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "target-feature=+crt-static"]
140 changes: 54 additions & 86 deletions .github/workflows/rust.yml
Expand Up @@ -10,105 +10,73 @@ env:
CARGO_TERM_COLOR: always

jobs:
linux-fmt:
name: Rustfmt
# fmt and clippy
fmt-clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

linux-check:
name: Build
needs: linux-fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: build
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2

linux-test:
name: Linux Test Suite
needs: linux-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
# fmt
- run: cargo fmt --all -- --check

linux-release:
name: Release Linux x86_64
needs: linux-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-unknown-linux-gnu
override: true
- uses: actions-rs/cargo@v1
with:
command: build
args: --release
- uses: actions/upload-artifact@v2.2.4
with:
name: teleporter-linux-x86_64
path: target/release/teleporter
# clippy
- run: cargo clippy -- -D warnings

macos-test:
name: MacOS Test Suite
needs: linux-check
runs-on: macos-latest
# build, test all supported targets
build-test-stable:
runs-on: ubuntu-latest
strategy:
matrix:
targets:
- x86_64-unknown-linux-musl
- x86_64-unknown-linux-gnu
toolchain:
# msrv
- 1.64.0
- stable
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.targets }}
- uses: Swatinem/rust-cache@v2
- run: cargo install cross --git https://github.com/cross-rs/cross
- run: cross build --locked --workspace --target ${{ matrix.targets }}
- run: cross build --locked --workspace --target ${{ matrix.targets }} --release
- run: cross test --locked --workspace --target ${{ matrix.targets }}
- uses: actions/upload-artifact@v3
with:
command: test
name: teleporter-${{ matrix.targets }}
path: target/${{ matrix.targets }}/release/teleporter

macos-release:
name: Release Darwin x86_64
needs: macos-test
build-test-macos:
runs-on: macos-latest
strategy:
matrix:
targets:
- x86_64-apple-darwin
toolchain:
# msrv
- 1.64.0
- stable
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-apple-darwin
override: true
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
command: build
args: --release
- uses: actions/upload-artifact@v2.2.4
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.targets }}
- uses: Swatinem/rust-cache@v2
- run: cargo build --locked --workspace --target ${{ matrix.targets }}
- run: cargo build --locked --workspace --target ${{ matrix.targets }} --release
- run: cargo test --locked --workspace --target ${{ matrix.targets }}
- uses: actions/upload-artifact@v3
with:
name: teleporter-darwin-x86_64
path: target/release/teleporter
name: teleporter-${{ matrix.targets }}
path: target/${{ matrix.targets }}/release/teleporter
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/genonullfree/teleporter.git"
keywords = ["netcat", "teleport", "teleporter", "transfer", "send"]
categories = ["command-line-utilities", "network-programming"]
edition = "2021"
rust-version = "1.64.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
4 changes: 2 additions & 2 deletions src/listen.rs
Expand Up @@ -45,7 +45,7 @@ pub fn run(opt: ListenOpt) -> Result<(), TeleportError> {
let recv_list_clone = Arc::clone(&recv_list);
thread::spawn(move || {
if let Err(e) = handle_connection(s, &recv_list_clone, args) {
println!("Error: {:?}", e);
println!("Error: {e:?}");
}
let recv_list = recv_list_clone.lock().unwrap();
print_list(&recv_list);
Expand All @@ -68,7 +68,7 @@ fn print_list(list: &MutexGuard<Vec<String>>) {
if list.len() == 0 {
print!("\rListening...");
} else {
print!("\rReceiving: {:?}", list);
print!("\rReceiving: {list:?}");
}
io::stdout().flush().unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Expand Up @@ -113,6 +113,6 @@ fn main() {
// Display any errors
match out {
Ok(()) => {}
Err(s) => println!("Error: {}", s),
Err(s) => println!("Error: {s}"),
};
}
18 changes: 9 additions & 9 deletions src/send.rs
Expand Up @@ -21,7 +21,7 @@ fn get_file_list(opt: &SendOpt) -> Vec<String> {
let mut tmp = match scope_dir(item) {
Ok(t) => t,
Err(_) => {
println!("Error: Cannot read item: {:?}", item);
println!("Error: Cannot read item: {item:?}");
continue;
}
};
Expand Down Expand Up @@ -52,7 +52,7 @@ fn scope_dir(dir: &Path) -> Result<Vec<String>, Error> {
let mut tmp = match scope_dir(&entry.as_ref().unwrap().path()) {
Ok(t) => t,
Err(_) => {
println!("Error: Cannot read dir: {:?}", entry);
println!("Error: Cannot read dir: {entry:?}");
continue;
}
};
Expand Down Expand Up @@ -80,14 +80,14 @@ fn find_replacements(opt: &mut SendOpt) -> Replace {
// Iterate over the input list
for (idx, item) in opt.input.iter().enumerate() {
// If it is a filename, no rename is happening
if File::open(&item).is_ok() {
if File::open(item).is_ok() {
continue;
}

let path = item.to_str().unwrap();

// If the path name contains ':'
if path.contains(&":") {
if path.contains(':') {
// Split on ':' and use the first as original name
// and the second as the new name
let mut split = path.split(':');
Expand Down Expand Up @@ -120,7 +120,7 @@ fn find_replacements(opt: &mut SendOpt) -> Replace {

/// Client function sends filename and file data for each filepath
pub fn run(mut opt: SendOpt) -> Result<(), TeleportError> {
print!("Teleporter Client {} => ", VERSION);
print!("Teleporter Client {VERSION} => ");
let start_time = Instant::now();
let mut sent = 0;
let mut skip = 0;
Expand Down Expand Up @@ -154,15 +154,15 @@ pub fn run(mut opt: SendOpt) -> Result<(), TeleportError> {
}

// Validate file
let file = match File::open(&filepath) {
let file = match File::open(filepath) {
Ok(f) => f,
Err(s) => {
println!("Error opening file: {}", filepath);
println!("Error opening file: {filepath}");
return Err(TeleportError::Io(s));
}
};

let thread_file = File::open(&filepath)?;
let thread_file = File::open(filepath)?;
// Skip if opt.no_delta present, otherwise calculate the delta hash of the file
let handle = match opt.overwrite && !opt.no_delta {
true => Some(thread::spawn(move || {
Expand Down Expand Up @@ -319,7 +319,7 @@ pub fn run(mut opt: SendOpt) -> Result<(), TeleportError> {
// Print file transfer statistics
let duration = file_time.elapsed();
let speed = (header.filesize as f64 * 8.0) / duration.as_secs() as f64 / 1024.0 / 1024.0;
println!(" done! Time: {:.2?} Speed: {:.3} Mbps", duration, speed);
println!(" done! Time: {duration:.2?} Speed: {speed:.3} Mbps");
}
let total_time = start_time.elapsed();
println!(
Expand Down
10 changes: 5 additions & 5 deletions src/teleport.rs
Expand Up @@ -43,7 +43,7 @@ impl TeleportHeader {
out.append(&mut self.data_len.to_le_bytes().to_vec());

// Add action code
let mut action = self.action as u8;
let mut action = self.action;
if self.iv.is_some() {
action |= TeleportAction::Encrypted as u8;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ impl TeleportInit {
}

// Add features
out.append(&mut (self.features as u32).to_le_bytes().to_vec());
out.append(&mut self.features.to_le_bytes().to_vec());

// Add chmod
out.append(&mut self.chmod.to_le_bytes().to_vec());
Expand All @@ -206,7 +206,7 @@ impl TeleportInit {
out.append(&mut flen.to_le_bytes().to_vec());

// Add filename
out.append(&mut self.filename.iter().map(|x| *x as u8).collect());
out.append(&mut self.filename.to_vec());

Ok(out)
}
Expand Down Expand Up @@ -306,7 +306,7 @@ impl TeleportInitAck {
let mut out = Vec::<u8>::new();

// Add status
let status = self.status as u8;
let status = self.status;
out.append(&mut vec![status]);

// Add version
Expand All @@ -320,7 +320,7 @@ impl TeleportInitAck {
}

// Add optional features
let feat = self.features.unwrap() as u32;
let feat = self.features.unwrap();
out.append(&mut feat.to_le_bytes().to_vec());

// If no delta, return early
Expand Down
10 changes: 5 additions & 5 deletions src/utils.rs
Expand Up @@ -18,7 +18,7 @@ struct UpdateUnit {
}

pub fn print_updates(received: f64, header: &TeleportInit) {
let units = update_units(received as f64, header.filesize as f64);
let units = update_units(received, header.filesize as f64);
print!(
"\r => {:>8.03}{} of {:>8.03}{} ({:02.02}%)",
units.partial.value, units.partial.unit, units.total.value, units.total.unit, units.percent
Expand All @@ -27,7 +27,7 @@ pub fn print_updates(received: f64, header: &TeleportInit) {
}

fn update_units(partial: f64, total: f64) -> UpdateUnit {
let percent: f64 = (partial as f64 / total as f64) * 100f64;
let percent: f64 = (partial / total) * 100f64;
let p = identify_unit(partial);
let t = identify_unit(total);

Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn calc_delta_hash(mut file: &File) -> Result<teleport::TeleportDelta, Error
let meta = file.metadata()?;
let file_size = meta.len();

file.seek(SeekFrom::Start(0))?;
file.rewind()?;
let mut buf = Vec::<u8>::new();
buf.resize(gen_chunk_size(meta.len()), 0);
let mut whole_hasher = xxh3::Xxh3::new();
Expand All @@ -209,12 +209,12 @@ pub fn calc_delta_hash(mut file: &File) -> Result<teleport::TeleportDelta, Error
}

let mut out = teleport::TeleportDelta::new();
out.filesize = file_size as u64;
out.filesize = file_size;
out.chunk_size = buf.len().try_into().unwrap();
out.hash = whole_hasher.finish();
out.chunk_hash = chunk_hash;

file.seek(SeekFrom::Start(0))?;
file.rewind()?;

Ok(out)
}

0 comments on commit a3b9dd4

Please sign in to comment.