Skip to content

use of hardlinks to a symlinked toolchain is not portable on macOS #3136

Closed
@brotskydotcom

Description

@brotskydotcom

Problem

rustup always uses hard links to the rustup executable on file systems that allow it, even if the rustup "executable" is itself a symlink. On macOS, which supports both filesystems that allow hard links to symlinks and filesystems that don't, this creates a portability problem; for example, you can't always copy (or backup) a rust install from one volume to another.

Steps

On a Mac with both an HFS+ volume and an AFS volume:

  1. install brew rustup-init.
  2. run rustup-init with a home directory on the AFS volume. This will result in hardlinks to rustup which is itself a symlink, as shown in this listing:
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 cargo@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 cargo-clippy@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 cargo-fmt@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 cargo-miri@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 clippy-driver@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rls@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rust-gdb@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rust-gdbgui@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rust-lldb@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rustc@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rustdoc@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rustfmt@ -> /opt/homebrew/bin/rustup-init
    lrwxr-xr-x  13 dbrotsky  staff  29 Jan  6 23:28 rustup@ -> /opt/homebrew/bin/rustup-init
    
  3. Try copying (or backing up) the .cargo directory to the HFS+ filesystem. This will fail.

Possible Solution(s)

While one option would be always to use symlinks on Mac, as is done on Android, that's a bigger change than needed, since arguably most rustup installs place an actual executable for rustup itself (and hard links to executables are supported on all macOS filesystems). The more cautious change is to detect whether rustup is a symlink and, if so, use a symlink to it rather than a hard link.

Notes

No response

Rustup version

rustup 1.25.1 (2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.66.0 (69f9c33d7 2022-12-12)`

Installed toolchains

Default host: aarch64-apple-darwin
rustup home:  /Users/dbrotsky/.rustup

stable-aarch64-apple-darwin (default)
rustc 1.66.0 (69f9c33d7 2022-12-12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions