From ed20c5f2c716097b2c29986ab6287ed86d048b7e Mon Sep 17 00:00:00 2001 From: Iwan BK Date: Wed, 30 Oct 2024 11:35:40 +0700 Subject: [PATCH 1/2] feat(macos): add macos support for docker2fl --- docker2fl/src/docker2fl.rs | 10 +++++++++- rfs/src/fungi/meta.rs | 32 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/docker2fl/src/docker2fl.rs b/docker2fl/src/docker2fl.rs index 4340558..04d4f79 100644 --- a/docker2fl/src/docker2fl.rs +++ b/docker2fl/src/docker2fl.rs @@ -71,9 +71,17 @@ impl DockerImageToFlist { } pub async fn prepare(&mut self) -> Result<()> { - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "macos")))] let docker = Docker::connect_with_socket_defaults().context("failed to create docker")?; + #[cfg(target_os = "macos")] + let docker = Docker::connect_with_socket( + concat!(env!("HOME"), "/.docker/run/docker.sock"), + 120, + bollard::API_DEFAULT_VERSION, + ) + .context("failed to create docker")?; + let container_file = Path::file_stem(self.docker_tmp_dir.path()).expect("failed to get directory name"); let container_name = container_file diff --git a/rfs/src/fungi/meta.rs b/rfs/src/fungi/meta.rs index 211f947..0b6b62c 100644 --- a/rfs/src/fungi/meta.rs +++ b/rfs/src/fungi/meta.rs @@ -12,31 +12,33 @@ use crate::store; const ID_LEN: usize = 32; const KEY_LEN: usize = 32; -const TYPE_MASK: u32 = nix::libc::S_IFMT; +const TYPE_MASK: u32 = nix::libc::S_IFMT as u32; #[repr(u32)] #[derive(Debug, Clone, PartialEq, Eq)] pub enum FileType { - Regular = nix::libc::S_IFREG, - Dir = nix::libc::S_IFDIR, - Link = nix::libc::S_IFLNK, - Block = nix::libc::S_IFBLK, - Char = nix::libc::S_IFCHR, - Socket = nix::libc::S_IFSOCK, - FIFO = nix::libc::S_IFIFO, + // we can't simply write `Regular = nix::libc::S_IFREG` because it is u32 in Linux but u16 in MacOS + Regular = nix::libc::S_IFREG as u32, + Dir = nix::libc::S_IFDIR as u32, + Link = nix::libc::S_IFLNK as u32, + Block = nix::libc::S_IFBLK as u32, + Char = nix::libc::S_IFCHR as u32, + Socket = nix::libc::S_IFSOCK as u32, + FIFO = nix::libc::S_IFIFO as u32, Unknown = 0, } impl From for FileType { fn from(value: u32) -> Self { match value { - nix::libc::S_IFREG => Self::Regular, - nix::libc::S_IFDIR => Self::Dir, - nix::libc::S_IFLNK => Self::Link, - nix::libc::S_IFBLK => Self::Block, - nix::libc::S_IFCHR => Self::Char, - nix::libc::S_IFSOCK => Self::Socket, - nix::libc::S_IFIFO => Self::FIFO, + // we can't simply write `nix::libc::S_IFREG => Self::Regular` because it is u32 in Linux but u16 in MacOS + x if x == nix::libc::S_IFREG as u32 => Self::Regular, + x if x == nix::libc::S_IFDIR as u32 => Self::Dir, + x if x == nix::libc::S_IFLNK as u32 => Self::Link, + x if x == nix::libc::S_IFBLK as u32 => Self::Block, + x if x == nix::libc::S_IFCHR as u32 => Self::Char, + x if x == nix::libc::S_IFSOCK as u32 => Self::Socket, + x if x == nix::libc::S_IFIFO as u32 => Self::FIFO, _ => Self::Unknown, } } From 71c3dc166644a80c5f20e66cc27356a3eafe8638 Mon Sep 17 00:00:00 2001 From: Iwan BK Date: Wed, 30 Oct 2024 11:36:30 +0700 Subject: [PATCH 2/2] feat(ghactions): add macos github actions check --- .github/workflows/tests.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d4f25cd..3d09630 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -16,13 +16,12 @@ jobs: - uses: clechasseur/rs-fmt-check@v2 test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v4 - - name: Get Dependencies - run: | - sudo apt-get update - sudo apt-get install capnproto - uses: actions-rs/toolchain@v1 with: toolchain: stable