A few features for VSCode devContainers now available

There's nothing super-heavy about these features, but they made my life easier, so I added them to the general catalog of containers available to support using .devContainer setups with Swift:5.7 and later. There's three separate features:

  • jemalloc - installs the jemalloc libraries (helpful if you're exploring using package-benchmark)
  • swiftpm - installs the sqlite & libsqlite libraries needed to build SwiftPM
  • foundationnetworking - installs the libcurl-openssl to support foundation networking

An example devContainer stanza including all three:

{
    "image": "swift:5.7",
    "features": {
        "ghcr.io/heckj/devcontainer-swift-additions/jemalloc:1": { },
        "ghcr.io/heckj/devcontainer-swift-additions/swiftpm:1": { },
        "ghcr.io/heckj/devcontainer-swift-additions/foundationnetworking:1": { }
    }
}

Source repository is GitHub - heckj/devcontainer-swift-additions: VSCode devContainer features to support additions on a base Swift devContainer - and I'd be happy to migrate or move these around if they're useful to more folks or you'd like to expand on them.

4 Likes

These look great. Have you thought of getting them to work for amazonlinux2 as well?

Any reason you've not called the swiftpm feature sqlite, since an sqlite install is used for many other things than swiftpm

When I was stubbing them together, I was doing it based on notes from Swift Package Index's setup, and they referenced it for use in building SwiftPM, so I ran from there - but there's no reason I couldn't rename it to sqlite.

I haven't used amazonlinux myself, or needed to, so I didn't look at anything related to how to set that up (I'm not even sure what packaging system it uses internally), or how devContainer features handle different patterns for different base OS images. (As an aside, I know there's some quirks with jemalloc on amazonlinux thanks to @taylorswift, who provided a snippet for getting the relevant jemalloc installed for package-benchmark.)

It's all pretty ugly. Your install script needs to recognise the Linux version and proceed as required. I was going to say look at the GitHub - devcontainers/features: A collection of Dev Container Features managed by Dev Container spec maintainers. See https://github.com/devcontainers/feature-starter to publish your own to see how they do it, but pretty much all of them assume apt-get is available.

But the common-utils feature does some platform recognition here. Basically it runs . /etc/os-release and then reads the ID environment variable setup.

amazonlinux2 uses yum instead of apt-get

1 Like

Yeah, I wasn't sure about the internals, or even how devcontainers were dealing with this situation, so after your prompt I started a Q&A discussion within their devcontainers repo asking about what conventions were used, features, and what capabilities might exist to help with underlying distribution identification.

Thanks for the link to common-utils, I'll do a bit more looking and see if I can swing something as an update.

1 Like

I thought Joseph's devcontainer features repo was such a great idea and that it would be a good to centralise something like this to make it easier to find. After discussion with Joseph this repo has been moved to swift-server-community/swift-devcontainer-features.

This means paths to the features has changed slightly and you now add them to your devcontainer as follows.

{
    "image": "swift:5.7",
    "features": {
        "ghcr.io/swift-server-community/swift-devcontainer-features/jemalloc:1": { },
        "ghcr.io/swift-server-community/swift-devcontainer-features/sqlite:1": { },
        "ghcr.io/swift-server-community/swift-devcontainer-features/foundationnetworking:1": { }
    }
}

Also we have added two new features.

  • swiftformat: Installs Nick Lockwood's swiftformat to your devcontainer
  • swift-format: Installs Apple's swift-format to your devcontainer
    Note the subtle name difference :slight_smile:

Again these are installed as above but there is a "version" option you can use to control which version is installed.

{
    "image": "swift:5.7",
    "features": {
        "ghcr.io/swift-server-community/swift-devcontainer-features/swiftformat:0": {
            "version": "0.51.0"
        }
    }
}

If you have any great ideas for devcontainer features that would be useful to the community please add an issue or even better add a PR with an implementation.

4 Likes