Skip to content

Commit

Permalink
Fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesdejager committed May 19, 2024
1 parent 3159845 commit a0e2f29
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 19 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,111 @@ jobs:
run: cargo build --workspace
- name: Build Docs
run: cargo doc --workspace --no-deps

build-linux-gnu:
runs-on: ubuntu-latest
name: Build for Linux (GNU)
env:
target: x86_64-unknown-linux-gnu
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install -y libpam-dev
- name: Build for Linux (GNU)
run: cargo build --target=${{ env.target }}

build-linux-musl:
runs-on: ubuntu-latest
name: Build for Linux (MUSL)
env:
target: x86_64-unknown-linux-musl
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build for Linux (MUSL)
run: RUSTFLAGS="-C target-feature=+crt-static" cargo build --target=${{ env.target }}

build-windows:
runs-on: windows-latest
name: Build for Windows
env:
trget: x86_64-pc-windows-msvc
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.trget }}
- name: Build for Windows
run: cargo build --target=${{ env.trget }}

build-macos-intel:
runs-on: macos-latest
name: Build for macOS (Intel)
env:
target: x86_64-apple-darwin
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Build for macOS (Intel)
run: cargo build --target=${{ env.target }}

build-macos-arm:
runs-on: macos-latest
name: Build for macOS (ARM)
env:
target: aarch64-apple-darwin
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Otherwise the code that retrieves the git version doesn't work
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
default: true
target: ${{ env.target }}
- name: Install Rosetta
if: runner.os == 'macOS' && runner.arch == 'arm64'
run: softwareupdate --install-rosetta --agree-to-license
- name: Build
run: cargo build --target=${{ env.target }}

1 change: 1 addition & 0 deletions src/server/ftpserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ where
///
/// - `path` - Path to the helper executable
/// - `args` - Optional arguments to pass to the helper executable.
#[cfg(unix)]
pub fn connection_helper(mut self, path: OsString, args: Vec<OsString>) -> Self {
self.connection_helper = Some(path);
self.connection_helper_args = args;
Expand Down
53 changes: 34 additions & 19 deletions src/server/ftpserver/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::server::shutdown;
use crate::{auth::UserDetail, server::controlchan, storage::StorageBackend};
use std::ffi::OsString;
use std::net::SocketAddr;
#[cfg(unix)]
use std::os::fd::AsRawFd;
use std::sync::Arc;
use tokio::net::TcpListener;
Expand Down Expand Up @@ -49,25 +50,11 @@ where
Ok((tcp_stream, socket_addr)) => {
slog::info!(logger, "Incoming control connection from {:?}", socket_addr);
if let Some(helper) = connection_helper.as_ref() {
slog::info!(logger, "Spawning {:?}", helper);
let fd = tcp_stream.as_raw_fd();
nix::fcntl::fcntl(fd, nix::fcntl::FcntlArg::F_SETFD(nix::fcntl::FdFlag::empty())).unwrap();
let result = tokio::process::Command::new(helper)
.args(connection_helper_args.iter())
.arg(fd.to_string())
.spawn();
let logger2 = logger.clone();
match result {
Ok(mut child) => {
tokio::spawn(async move {
let child_status = child.wait().await;
slog::debug!(logger2, "helper process exited {:?}", child_status);
});
}
Err(err) => {
slog::error!(logger, "Could not spawn helper process for connection from {:?}: {:?}", socket_addr, err);
}
}
slog::info!(logger, "Spawning connection helper: {:?} {:?}", helper, connection_helper_args);
#[cfg(unix)]
Self::spawn_helper(&logger, helper, &connection_helper_args, &tcp_stream, socket_addr);
#[cfg(not(unix))]
unimplemented!()
} else {
let result =
controlchan::spawn_loop::<Storage, User>((&options).into(), tcp_stream, None, None, shutdown_listener, failed_logins.clone()).await;
Expand All @@ -82,4 +69,32 @@ where
}
}
}

#[cfg(unix)]
fn spawn_helper(
logger: &slog::Logger,
helper: &OsString,
connection_helper_args: &[OsString],
tcp_stream: &tokio::net::TcpStream,
socket_addr: SocketAddr,
) {
let fd = tcp_stream.as_raw_fd();
nix::fcntl::fcntl(fd, nix::fcntl::FcntlArg::F_SETFD(nix::fcntl::FdFlag::empty())).unwrap();
let result = tokio::process::Command::new(helper)
.args(connection_helper_args.iter())
.arg(fd.to_string())
.spawn();
let logger2 = logger.clone();
match result {
Ok(mut child) => {
tokio::spawn(async move {
let child_status = child.wait().await;
slog::debug!(logger2, "helper process exited {:?}", child_status);
});
}
Err(err) => {
slog::error!(logger, "Could not spawn helper process for connection from {:?}: {:?}", socket_addr, err);
}
}
}
}

0 comments on commit a0e2f29

Please sign in to comment.