├── .gitignore
├── Sources
└── vscode-remote-try-swift
│ └── main.swift
├── Tests
├── LinuxMain.swift
└── vscode-remote-try-swiftTests
│ ├── XCTestManifests.swift
│ └── vscode_remote_try_swiftTests.swift
├── .devcontainer
├── devcontainer.json
└── Dockerfile
├── .vscode
├── launch.json
└── tasks.json
├── Package.swift
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /.build
3 | /Packages
4 | /*.xcodeproj
5 | xcuserdata/
6 |
--------------------------------------------------------------------------------
/Sources/vscode-remote-try-swift/main.swift:
--------------------------------------------------------------------------------
1 | let name = "VS Code Remote - Containers"
2 |
3 | print("Hello, \(name)!")
--------------------------------------------------------------------------------
/Tests/LinuxMain.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 |
3 | import vscode_remote_try_swiftTests
4 |
5 | var tests = [XCTestCaseEntry]()
6 | tests += vscode_remote_try_swiftTests.allTests()
7 | XCTMain(tests)
8 |
--------------------------------------------------------------------------------
/Tests/vscode-remote-try-swiftTests/XCTestManifests.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 |
3 | #if !canImport(ObjectiveC)
4 | public func allTests() -> [XCTestCaseEntry] {
5 | return [
6 | testCase(vscode_remote_try_swiftTests.allTests),
7 | ]
8 | }
9 | #endif
10 |
--------------------------------------------------------------------------------
/.devcontainer/devcontainer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Swift",
3 | "dockerFile": "Dockerfile",
4 |
5 | "runArgs": [
6 | "-u", "vscode",
7 | "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
8 | ],
9 |
10 | "settings": {
11 | "lldb.adapterType": "bundled",
12 | "lldb.executable": "/usr/bin/lldb",
13 | "terminal.integrated.shell.linux": "/bin/bash"
14 | },
15 |
16 | // Uncomment the next line if you want to publish any ports.
17 | // "appPort": [],
18 |
19 | "extensions": [
20 | "pvasek.sourcekit-lsp--dev-unofficial",
21 | "vadimcn.vscode-lldb"
22 | ]
23 | }
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 |
8 | {
9 | "type": "lldb",
10 | "request": "launch",
11 | "name": "Debug",
12 | "program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/vscode-remote-try-swift",
13 | "args": [],
14 | "cwd": "${workspaceFolder}",
15 | "preLaunchTask": "build"
16 | }
17 | ]
18 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "label": "build",
8 | "type": "shell",
9 | "command": "swift build",
10 | "group": {
11 | "kind": "build",
12 | "isDefault": true
13 | }
14 | },
15 | {
16 | "label": "test",
17 | "type": "shell",
18 | "command": "swift test"
19 | },
20 | {
21 | "label": "run",
22 | "type": "shell",
23 | "command": "swift run"
24 | }
25 | ]
26 | }
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.1
2 | // The swift-tools-version declares the minimum version of Swift required to build this package.
3 |
4 | import PackageDescription
5 |
6 | let package = Package(
7 | name: "vscode-remote-try-swift",
8 | dependencies: [
9 | // Dependencies declare other packages that this package depends on.
10 | // .package(url: /* package url */, from: "1.0.0"),
11 | ],
12 | targets: [
13 | // Targets are the basic building blocks of a package. A target can define a module or a test suite.
14 | // Targets can depend on other targets in this package, and on products in packages which this package depends on.
15 | .target(
16 | name: "vscode-remote-try-swift",
17 | dependencies: []),
18 | .testTarget(
19 | name: "vscode-remote-try-swiftTests",
20 | dependencies: ["vscode-remote-try-swift"]),
21 | ]
22 | )
23 |
--------------------------------------------------------------------------------
/.devcontainer/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM swift:5.1
2 |
3 | # Or your actual UID, GID on Linux if not the default 1000
4 | ARG USERNAME=vscode
5 | ARG USER_UID=1000
6 | ARG USER_GID=$USER_UID
7 |
8 | # Avoid warnings by switching to noninteractive
9 | ENV DEBIAN_FRONTEND=noninteractive
10 |
11 | # Configure apt and install packages
12 | RUN apt-get update \
13 | # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
14 | && groupadd --gid $USER_GID $USERNAME \
15 | && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
16 | # [Optional] Add sudo support for non-root user
17 | && apt-get install -y sudo \
18 | && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
19 | && chmod 0440 /etc/sudoers.d/$USERNAME \
20 | #
21 | # Clean up
22 | && apt-get autoremove -y \
23 | && apt-get clean -y \
24 | && rm -rf /var/lib/apt/lists/*
25 |
26 | # Switch back to dialog for any ad-hoc use of apt-get
27 | ENV DEBIAN_FRONTEND=
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Ian Partridge. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/Tests/vscode-remote-try-swiftTests/vscode_remote_try_swiftTests.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 | import class Foundation.Bundle
3 |
4 | final class vscode_remote_try_swiftTests: XCTestCase {
5 | func testExample() throws {
6 | // This is an example of a functional test case.
7 | // Use XCTAssert and related functions to verify your tests produce the correct
8 | // results.
9 |
10 | // Some of the APIs that we use below are available in macOS 10.13 and above.
11 | guard #available(macOS 10.13, *) else {
12 | return
13 | }
14 |
15 | let fooBinary = productsDirectory.appendingPathComponent("vscode-remote-try-swift")
16 |
17 | let process = Process()
18 | process.executableURL = fooBinary
19 |
20 | let pipe = Pipe()
21 | process.standardOutput = pipe
22 |
23 | try process.run()
24 | process.waitUntilExit()
25 |
26 | let data = pipe.fileHandleForReading.readDataToEndOfFile()
27 | let output = String(data: data, encoding: .utf8)
28 |
29 | XCTAssertEqual(output, "Hello, world!\n")
30 | }
31 |
32 | /// Returns path to the built products directory.
33 | var productsDirectory: URL {
34 | #if os(macOS)
35 | for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
36 | return bundle.bundleURL.deletingLastPathComponent()
37 | }
38 | fatalError("couldn't find the products directory")
39 | #else
40 | return Bundle.main.bundleURL
41 | #endif
42 | }
43 |
44 | static var allTests = [
45 | ("testExample", testExample),
46 | ]
47 | }
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Try Out Development Containers: Swift
2 |
3 | This is a sample project that lets you try out the **[VS Code Remote - Containers](https://aka.ms/vscode-remote/containers)** extension in a few easy steps.
4 |
5 | > **Note:** If you're following the quick start, you can jump to the [Things to try](#things-to-try) section.
6 |
7 | ## Setting up the development container
8 |
9 | Follow these steps to open this sample in a container:
10 |
11 | 1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
12 |
13 | 2. **Linux users:** Update `USER_UID` and `USER_GID` in `.devcontainer/Dockerfile` with your user UID/GID if not 1000 to avoid creating files as root.
14 |
15 | 3. If you're not yet in a development container:
16 | - Clone this repository.
17 | - Press F1 and select the **Remote-Containers: Open Folder in Container...** command.
18 | - Select the cloned copy of this folder, wait for the container to start, and try things out!
19 |
20 | ## Things to try
21 |
22 | Once you have this sample opened in a container, you'll be able to work with it like you would locally.
23 |
24 | > **Note:** This container runs as a non-root user with sudo access by default. Comment out `"-u", "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root.
25 |
26 | Some things to try:
27 |
28 | 1. **Edit:**
29 | - Open `Sources/main.swift`
30 | - Try adding some code and check out the language features.
31 | 1. **Terminal:** Press ctrl+shift+\` and type `uname` and other Linux commands from the terminal window.
32 | 1. **Build, Run, and Debug:**
33 | - Open `Sources/main.swift`
34 | - Add a breakpoint (e.g. on line 8).
35 | - Press F5 to launch the app in the container.
36 | - Once the breakpoint is hit, try hovering over variables, examining locals, and more.
37 |
38 | ## License
39 |
40 | Copyright © Ian Partridge All rights reserved.
41 | Licensed under the MIT License. See LICENSE in the project root for license information.
42 |
--------------------------------------------------------------------------------