Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows build #513

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,115 @@ jobs:
run: cargo build --workspace
- name: Build Docs
run: cargo doc --workspace --no-deps

build-linux-gnu:
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/master' }}
name: Build on 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
if: ${{ github.ref != 'refs/heads/master' }}
name: Build on 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
if: ${{ github.ref != 'refs/heads/master' }}
name: Build on 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
if: ${{ github.ref != 'refs/heads/master' }}
name: Build on 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
if: ${{ github.ref != 'refs/heads/master' }}
name: Build on 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);
}
}
}
}
Loading