diff --git a/.github/actions/setup-build-env/action.yml b/.github/actions/setup-build-env/action.yml new file mode 100644 index 0000000..1077fce --- /dev/null +++ b/.github/actions/setup-build-env/action.yml @@ -0,0 +1,42 @@ +name: 'Setup Build Environment' +description: 'Common setup for Rust builds with all required packages (Linux & macOS)' +runs: + using: 'composite' + steps: + - name: Install Rust toolchain + shell: bash + run: | + rustup update stable + rustup default stable + rustup component add rustfmt clippy + + - name: Cache Cargo dependencies + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Set up Homebrew (macOS) + if: runner.os == 'macOS' + uses: Homebrew/actions/setup-homebrew@master + + - name: Install packages (macOS) + if: runner.os == 'macOS' + shell: bash + run: brew tap slp/krun && brew install asciidoctor libkrun clang-format llvm + + - name: Install packages (Linux) + if: runner.os == 'Linux' + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y \ + libvirglrenderer-dev \ + libepoxy-dev \ + libdrm-dev \ + libpipewire-0.3-dev \ + clang-format \ + libclang-dev diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 80f6ad1..3956dd0 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -1,42 +1,15 @@ -name: Code Quality (rustfmt and clippy) -on: [pull_request, create] +name: Code Quality +on: [pull_request] jobs: - build: - if: github.event_name == 'pull_request' - name: Code Quality (clippy, rustfmt) - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable - target: - - x86_64-unknown-linux-gnu + code-quality-macos: + name: krunvm (macOS aarch64) + runs-on: macos-latest steps: - - name: Code checkout - uses: actions/checkout@v2 - - name: Install Rust toolchain (${{ matrix.rust }}) - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - override: true - components: rustfmt, clippy - - - name: Install asciidoctor - run: sudo apt-get install -y asciidoctor - - - name: Install additional Rust rust targets - run: rustup target add aarch64-unknown-linux-gnu aarch64-apple-darwin - - - name: Formatting (rustfmt) - run: cargo fmt -- --check - - - name: Clippy x86_64-unknown-linux-gnu (all features) - run: cargo clippy --all-features --target x86_64-unknown-linux-gnu - - - name: Clippy aarch64-unknown-linux-gnu (all features) - run: cargo clippy --all-features --target aarch64-unknown-linux-gnu - - - name: Clippy aarch64-apple-darwin (all features) - run: cargo clippy --all-features --target aarch64-apple-darwin + - uses: actions/checkout@v4 + + - name: Setup build environment + uses: ./.github/actions/setup-build-env + + - name: Clippy + run: cargo clippy --locked -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index f66028d..aed7fb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -217,7 +217,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "krunvm" -version = "0.2.4" +version = "0.2.5" dependencies = [ "clap", "confy", diff --git a/Cargo.toml b/Cargo.toml index 80f19a2..c10a4ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krunvm" -version = "0.2.4" +version = "0.2.5" authors = ["Sergio Lopez "] description = "Create microVMs from OCI images" repository = "https://github.com/containers/krunvm" diff --git a/build.rs b/build.rs index d7a571a..e46457a 100644 --- a/build.rs +++ b/build.rs @@ -54,7 +54,7 @@ fn generate_man_page>(outdir: P, command: &str) -> io::Result<()> .wait()?; if !result.success() { let msg = format!("'asciidoctor' failed with exit code {:?}", result.code()); - return Err(io::Error::new(io::ErrorKind::Other, msg)); + return Err(io::Error::other(msg)); } Ok(()) } diff --git a/src/main.rs b/src/main.rs index d6f336d..d3e0237 100644 --- a/src/main.rs +++ b/src/main.rs @@ -191,6 +191,9 @@ fn get_brew_prefix() -> Option { #[cfg(target_os = "macos")] fn reexec() -> Result<(), Error> { + let exec_path = env::current_exe().map_err(|_| ErrorKind::NotFound)?; + let exec_cstr = CString::new(exec_path.to_str().ok_or(ErrorKind::InvalidFilename)?)?; + let args: Vec = env::args_os() .map(|arg| CString::new(arg.into_vec()).unwrap()) .collect(); @@ -212,7 +215,7 @@ fn reexec() -> Result<(), Error> { // Use execve to replace the current process. This function only returns // if an error occurs. - match execve(&args[0], &args, &envs) { + match execve(&exec_cstr, &args, &envs) { Ok(_) => Ok(()), Err(e) => { eprintln!("Error re-executing krunvm: {}", e);