# Using swift-corelibs-foundation on Mac OS?

**URL:** <https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651>\
**Category:** Development\
**Tags:** linux\
**Created:** [March 18, 2021, 4:09am UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651 "2021-03-18T04:09:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdcarter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cdcarter/32/15892_2.png) [@cdcarter](https://forums.swift.org/u/cdcarter)\
**Post date:** [March 18, 2021, 4:09am UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/1 "2021-03-18T04:09:30Z")

</div>

I'm writing a Swift service that I will be deploying to several Linux servers. I'm developing the service on my Macbook Pro, with VS Code/sourcekit-lsp. When I click through to definitions of things, I'm (obviously) taken to the Darwin Foundation definitions.

The helpful advice over on [GitHub - swift-server/guides: Guides for building, debugging and deploying Swift Server applications](https://github.com/swift-server/guides) is that it's...critical to test on Linux.

> Swift supports architecture-specific code. By default, Foundation imports architecture-specific libraries like Darwin or Glibc. While developing on macOS, you may end up using APIs that are not available on Linux. Since you are most likely to deploy a cloud service on Linux, it is critical to test on Linux.

Obviously, I can't account for every difference, but it'd go a long way to be able to compile against swift-corelibs-foundation (and have sourcekit go to those definitions, so I can see ahead of time what will give me an unimplemented exception).

I understand that the usual mode should certainly to be compiling/linking against the native Foundation, but when targeting Linux, it'd be great to use corelibs-foundation...

---

<div class="post-metadata">

**Author:** ![lukasa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lukasa/32/1232_2.png) [@lukasa](https://forums.swift.org/u/lukasa)\
**Post date:** [March 18, 2021, 7:10am UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/2 "2021-03-18T07:10:42Z")

</div>

This is definitely something I want to see better tools for. In the short term, though, have you considered using Docker for Mac? It will give you the ability to rapidly get a Linux userspace with Swift installed, which should at least let you get the compile done.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [March 18, 2021, 9:48am UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/3 "2021-03-18T09:48:08Z")

</div>

Docker is definitely the way to go and ensuring you run CI on Linux as well.

There's also a discussion to be had about standardising the behaviour of SwiftPM (and therefore `swift test`, `swift run`, `swift build` etc across all platforms. This would provide a much better experience for people working across platforms though I suspect there'll be significant push back and this is probably off topic for this thread

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [March 18, 2021, 12:30pm UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/4 "2021-03-18T12:30:51Z")

</div>

I decided to actually pitch it so I've written it here

> [@Pitch: Standardise Swift CLI across all platforms](https://forums.swift.org/t/pitch-standardise-swift-cli-across-all-platforms/46672):
>
> SwiftPM and it's associated command line tools (swift test, swift build, swift run etc) currently work across all the platforms that SwiftPM supports. However the behaviour of those tools is different across different platforms - it's the same on all platforms apart from macOS. For example on macOS, swift test uses the Objective-C runtime to discover tests. swift build builds against the Objective-C Foundation runtime instead of using corelibs-foundation. This makes writing cross platform code d…

---

<div class="post-metadata">

**Author:** ![cdcarter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cdcarter/32/15892_2.png) [@cdcarter](https://forums.swift.org/u/cdcarter)\
**Post date:** [March 18, 2021, 10:19pm UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/6 "2021-03-18T22:19:08Z")

</div>

I appreciate all the thoughts/advice so far! I've poked at using Docker to do the compiles (success!) but I haven't figured out how to get VS Code to rely on _that_ sourcekit-lsp. I'll continue poking. It's good to hear this isn't completely crazy.

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [March 19, 2021, 6:39am UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/8 "2021-03-19T06:39:43Z")

</div>

There is an old post from @IanPartridge that explains a VSCode setup:

> **[Swift development in Docker using Visual Studio Code Remote](https://medium.com/@ianpartridge/swift-development-in-docker-using-visual-studio-code-remote-b84d035e70db?source=linkShare-ba7acd5498d-1616135851&_branch_match_id=1101093503401227646&_branch_referrer=H4sIAAAAAAAAA8soKSkottLXz8nMy9bLTU3JLM3VS87P1S8LrwgsyovI9k5NAgBpEL%2BxIwAAAA%3D%3D)**
>
> Xcode provides a great experience when developing Swift applications on macOS, but as Swift matures and becomes more popular on Linux…

Not sure how uptodate this is though.

Official docs (without mentioning Swift):

> **[Developing inside a Container using Visual Studio Code Remote Development](https://code.visualstudio.com/docs/remote/containers)**
>
> Developing inside a Container using Visual Studio Code Remote Development

---

<div class="post-metadata">

**Author:** ![cdcarter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cdcarter/32/15892_2.png) [@cdcarter](https://forums.swift.org/u/cdcarter)\
**Post date:** [March 19, 2021, 7:57pm UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/9 "2021-03-19T19:57:23Z")

</div>

Using the "community provided" Docker container and a few configuration tweaks inside VS Code and I am able to easily compile and test the Linux platform builds. Success! I much appreciate all the hints.

I got sourcekit-lsp providing completions, etc... I've got one part of my dream unfulfilled: jump to definition/jump to implementation for swift-corelibs-foundation and the standard library just...don't jump anywhere. Hover-docs and completion for Foundation work fine, but unlike on Mac OS I cannot actually jump to the definition.

I suspect this is due to the Docker image needing the swift-corelibs-foundation etc... sources instead of just precompiled binaries. I can probably figure this out, but figured I'd continue to document what I'm running into.

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [March 19, 2021, 9:06pm UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/10 "2021-03-19T21:06:13Z")

</div>

Nice, can you share with what setup you ended up with? Would also like to give it a try 🙂

---

<div class="post-metadata">

**Author:** ![cdcarter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cdcarter/32/15892_2.png) [@cdcarter](https://forums.swift.org/u/cdcarter)\
**Post date:** [March 21, 2021, 6:00pm UTC](https://forums.swift.org/t/using-swift-corelibs-foundation-on-mac-os/46651/11 "2021-03-21T18:00:25Z")

</div>

Hey Tobias, short of actually getting a write up of what I'm doing, I threw things in a git repo to demonstrate.

```
git clone https://repo.or.cz/swcgi.git

```

Then, launch VS Code and install the "Remote Development" extension (which includes the Remote-Containers extension). Once its installed, Cmd-Shift-P (command pallet) and then type/select "Open Folder in Container". Select the cloned repository, and VS Code will start assembling the docker container and getting you connected.

In the repo, the .devcontainer director contains the configuration that's going to be used. There's the actual Dockerfile (which starts with the swift5.3 image), as well as a devcontainer.json file which tells the remote VS Code to install swift plugins and points them to the right sourcekit-lsp.

As I mentioned before, click-to-definition works for project files and dependencies, but not for Foundation or the Stdlib. Still working on that.

Hope this helps someone!
