Skip to content

Linux support #262

@bguidolim

Description

@bguidolim

Summary

Make mcs build and run on Linux. The codebase is already well-structured with Environment and ShellRunner as natural abstraction points, so most changes are conditional compilation guards and constant swaps.

Effort Estimate

Moderate — ~15-20 focused changes, no architectural rewrite needed.

Required Changes

Build Configuration

  • Remove or conditionalize .macOS(.v13) in Package.swift (line 7-8) — currently blocks compilation entirely

Conditional Compilation Guards

  • Darwin.read()Glibc.read() in CLIOutput.swift:523 — use #if canImport(Darwin) / #if canImport(Glibc)
  • termios VMIN/VTIME indices in CLIOutput.swift:236-237 — macOS uses tuple indices 16/17, Linux uses 6/5. Replace magic numbers with platform-conditional named constants
  • CryptoKit → add #if canImport(CryptoKit) with import Crypto fallback (from apple/swift-crypto) in:
    • FileHasher.swift:1
    • SettingsHasher.swift:1
    • SectionValidator.swift:1
    • PackTrustManager.swift:1
  • OSAllocatedUnfairLock in ScriptRunner.swift:174 — Apple-only (os framework). Replace with Swift 6 Mutex (Synchronization module) or NSLock wrapper

Homebrew on Linux

  • Add Linuxbrew prefix /home/linuxbrew/.linuxbrew to Homebrew.allPrefixes (Homebrew.swift:6)
  • Update Environment.swift:59-63 brew prefix fallback to include Linux default path

Verification

  • Foundation Process, FileManager, NSString, ObjCBool — these work on Linux via swift-corelibs-foundation (verified in audit)
  • Hardcoded POSIX paths (/usr/bin/env, /usr/bin/which, /bin/bash in Constants.swift:36-42) — exist on all standard Linux distros, no change needed
  • POSIX APIs (flock, ioctl+TIOCGWINSZ, isatty, open/close, .posixPermissions) — all available on Linux, no change needed

Files Affected

File Change
Package.swift Remove/conditionalize macOS platform restriction
Sources/mcs/Core/CLIOutput.swift #if canImport(Darwin/Glibc) for read(), fix termios indices
Sources/mcs/Core/FileHasher.swift CryptoKit conditional import
Sources/mcs/Core/SettingsHasher.swift CryptoKit conditional import
Sources/mcs/Doctor/SectionValidator.swift CryptoKit conditional import
Sources/mcs/ExternalPack/PackTrustManager.swift CryptoKit conditional import
Sources/mcs/ExternalPack/ScriptRunner.swift Replace OSAllocatedUnfairLock
Sources/mcs/Core/Homebrew.swift Add Linuxbrew prefix
Sources/mcs/Core/Environment.swift Add Linux brew prefix fallback

Notes

  • Distribution remains Homebrew-only (Linuxbrew is officially supported)
  • All Foundation bridging types (NSString, ObjCBool, NSNumber, NSHomeDirectory) work via swift-corelibs-foundation
  • POSIX APIs (flock, ioctl, termios, isatty) are all available on Linux
  • No architectural changes required — just conditional compilation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions