Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftPM should support swift install #8140

Open
dduan opened this issue Nov 27, 2024 · 2 comments
Open

SwiftPM should support swift install #8140

dduan opened this issue Nov 27, 2024 · 2 comments

Comments

@dduan
Copy link
Contributor

dduan commented Nov 27, 2024

Description

tl;dr swift install is a command that builds the default execuatble target in release mode, and copy the result somewhere.

The somewhere should default to a fixed location that the user can access (for example, ~/swift/bin). The user can access it directly, or add it to their PATH. This location can be overriden by a envvar, for example, $SWIFTBIN.

Why is this a great idea? Sometimes you don't want to distribute your CLI applications via a public channel such as Homebrew. Maybe it's not meant for others to use, maybe you want to control what version to use by building from source.

Imagine a in-house tool whose source is part of a repository. The tool is meant to be version locked with whatever the repo's git revision is.

monorepo
├── ...
├── tools
│   └── great-swift-tool
│       └── Package.swift
└── tmp # git ignored
    └── bin

How does one build great-swift-tool and put it under ./tmp/bin today? Easy:

swift build --package-path tools/great-swift-tool -c release
cp tools/great-swift-tool/.build/release/great-swift-tool-executable tmp/bin

... put that in a shell script or make target and forget it, right?

IMO this is unnecessarily complicated in 2 ways:

  1. the user has to know that the build result is in .build/release
  2. the user has to write out the executable's name

With the proposed solution, this could be simplified as 1 command:

SWIFTBIN=tmp/bin swift install --package-path tools/great-swift-tool

I think that'd be pretty cool.

(In the future the command can take a git repository with for a SwiftPM project as input: swift install https://github.com/swiftlang/swift-format)

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

No response

@kkebo
Copy link
Contributor

kkebo commented Nov 27, 2024

There is already experimental--prefixed swift package install.

#6768

@unnamedd
Copy link
Contributor

A good inspiration can be Cargo (from Rust).
There, we have the same possibilities that were brought here.

Here is the help from cargo install:

➜ cargo install --help
Install a Rust binary

Usage: cargo install [OPTIONS] [CRATE[@<VER>]]...

Arguments:
  [CRATE[@<VER>]]...  Select the package from the given source

Options:
      --version <VERSION>     Specify a version to install
      --index <INDEX>         Registry index to install from
      --registry <REGISTRY>   Registry to use
      --git <URL>             Git URL to install the specified crate from
      --branch <BRANCH>       Branch to use when installing from git
      --tag <TAG>             Tag to use when installing from git
      --rev <SHA>             Specific commit to use when installing from git
      --path <PATH>           Filesystem path to local crate to install from
      --root <DIR>            Directory to install packages into
  -f, --force                 Force overwriting existing crates or binaries
      --no-track              Do not save tracking information
      --list                  List all installed packages and their versions
      --message-format <FMT>  Error format
      --debug                 Build in debug mode (with the 'dev' profile) instead of release mode
  -v, --verbose...            Use verbose output (-vv very verbose/build.rs output)
  -q, --quiet                 Do not print cargo log messages
      --color <WHEN>          Coloring: auto, always, never
      --config <KEY=VALUE>    Override a configuration value
  -Z <FLAG>                   Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
  -h, --help                  Print help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants