From 49b60504cd724e6010885d418fcb00626430eda8 Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Thu, 9 Jun 2022 16:36:34 +0300 Subject: [PATCH] Fix random crash on macOS on launch (#132) Extract the dylib to `/tmp` instead of `$TMPDIR` seems to solve it? (change only on macOS) Change CI to compile m1 binary Fix compilation error on m1 --- .github/workflows/ci.yaml | 32 +++++++++++++++++++++++++++----- CHANGELOG.md | 1 + mirrord-cli/src/main.rs | 23 ++++++++++++++++++++--- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ce722abdec6..c717e81f013 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,7 +26,7 @@ jobs: test_mirrord_protocol: strategy: matrix: - os: [ubuntu-latest, ubuntu-18.04, macos-12, macos-11, macos-10.15] + os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -34,6 +34,7 @@ jobs: with: profile: minimal toolchain: nightly + target: ${{matrix.target}} - uses: Swatinem/rust-cache@v1 with: key: ${{matrix.os}} @@ -74,10 +75,30 @@ jobs: name: test path: /tmp/test.tar - test_mirrord_layer: + test_mirrord_layer_cli: strategy: matrix: os: [ubuntu-latest, ubuntu-18.04, macos-12, macos-11, macos-10.15] + target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin] + exclude: + - os: ubuntu-latest + target: x86_64-apple-darwin + - os: ubuntu-latest + target: aarch64-apple-darwin + - os: ubuntu-18.04 + target: x86_64-apple-darwin + - os: ubuntu-18.04 + target: aarch64-apple-darwin + - os: macos-12 + target: x86_64-unknown-linux-gnu + - os: macos-11 + target: aarch64-apple-darwin + - os: macos-11 + target: x86_64-unknown-linux-gnu + - os: macos-10.15 + target: aarch64-apple-darwin + - os: macos-10.15 + target: x86_64-unknown-linux-gnu runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -85,11 +106,12 @@ jobs: with: profile: minimal toolchain: nightly + target: ${{matrix.target}} - uses: Swatinem/rust-cache@v1 with: - key: ${{matrix.os}} - # For now, just evrify it compiles. - - run: cargo +nightly build --manifest-path=mirrord-layer/Cargo.toml + key: ${{matrix.os}}-${{matrix.target}} + # For now, just verify it compiles. + - run: cargo +nightly build -p mirrord-layer -p mirrord --target=${{matrix.target}} build_mirrord: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a15bf46ddb..db35fa8eda9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how - Update bug report template to apply to the latest version of mirrord. - Chang release profile to strip debuginfo and enable LTO. - VS Code extension - update dependencies. +- CLI & macOS: Extract to `/tmp/` instead of `$TMPDIR` as the executed process is getting killed for some reason. ### Fixed diff --git a/mirrord-cli/src/main.rs b/mirrord-cli/src/main.rs index aa95e56e7e2..ad71c9e1eb1 100644 --- a/mirrord-cli/src/main.rs +++ b/mirrord-cli/src/main.rs @@ -1,4 +1,4 @@ -use std::{env::temp_dir, fs::File, io::Write, path::PathBuf, time::Duration}; +use std::{fs::File, io::Write, path::PathBuf, time::Duration}; use anyhow::{anyhow, Context, Result}; use clap::{Args, Parser, Subcommand}; @@ -73,14 +73,13 @@ mod mac_aarch { }; use mach_object::{OFile, CPU_TYPE_X86_64}; - use reqwest; use search_path::SearchPath; use tracing::warn; use super::*; pub fn is_binary_different_arch(binary_name: &String) -> bool { let search_path = SearchPath::new("PATH").unwrap(); - let binary_name = match search_path.find(&Path::new(binary_name)) { + let binary_path = match search_path.find(Path::new(binary_name)) { Some(path) => path, None => { warn!("Could not find binary in PATH"); @@ -142,6 +141,24 @@ mod mac_aarch { #[cfg(all(target_os = "macos", target_arch = "aarch64"))] use mac_aarch::*; +/// For some reason loading dylib from $TMPDIR can get the process killed somehow..? +#[cfg(target_os = "macos")] +mod mac { + use std::str::FromStr; + + use super::*; + + pub fn temp_dir() -> PathBuf { + PathBuf::from_str("/tmp/").unwrap() + } +} + +#[cfg(not(target_os = "macos"))] +use std::env::temp_dir; + +#[cfg(target_os = "macos")] +use mac::temp_dir; + fn extract_library(dest_dir: Option) -> Result { let library_file = env!("CARGO_CDYLIB_FILE_MIRRORD_LAYER"); let library_path = std::path::Path::new(library_file);