Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does Process with Launch Path /usr/bin/swift requires Command Line Tools to be installed on Mac?

I am working on an mac application where I needed to use different swift script to be executed on different actions.

            let outputPipe = Pipe()
            let errorPipe = Pipe()
             
            let task:Process = Process()
            task.launchPath = "/usr/bin/swift"
            task.arguments = [filePath, scriptInput.string]
            task.standardOutput = outputPipe
            task.standardError = errorPipe
            task.launch()

For executing swift script I am initializing the process with launch path /usr/bin/swift. On mac which don’t have xcode installed my application ask to download command line tools.

Does Command Line Tools needed to be installed in mac in order to run swift scripts?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, Swift "scripts" (Swift files run directly using swift — which are, behind the scenes, compiled into a temporary directory and then immediately executed) require either the Command Line Tools or a full Xcode installation on the target machine (depending on what the script needs to do).

macOS does not come with the Swift compiler (or other developer tools) preinstalled, so compiling Swift on a target machine requires installing it. The /usr/bin/swift which comes preinstalled on macOS prompts for this installation when run — and installing the tools will overwrite /usr/bin/swift to be able to compile Swift.

If you are trying to distribute and run "scripts" like this alongside your app, you’ll either need to ensure that the end user has the Command Line Tools installed (or prompt them to follow the instructions to install them themselves), or precompile those scripts into your app so you don’t need to rely on /usr/bin/swift. The latter is likely preferred: why do you need to run actions in external scripts, and why can’t your application perform these actions itself?

If your app intends to help users run their own scripts, they will need to install these tools as well.


Note that this isn’t unique to /usr/bin/swift. macOS also ships with a /usr/bin/git, for instance, that prompts for the same thing. The Command Line Tools are necessary for many basic developer-related command-line tools.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading