Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiled_starters/swift/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to compile your program on CodeCrafters
#
# This runs before .codecrafters/run.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

swift build -c release --build-path /tmp/codecrafters-build-shell-swift
11 changes: 11 additions & 0 deletions compiled_starters/swift/.codecrafters/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

exec swift run -c release --skip-build --build-path /tmp/codecrafters-build-shell-swift build-your-own-shell "$@"
1 change: 1 addition & 0 deletions compiled_starters/swift/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
8 changes: 8 additions & 0 deletions compiled_starters/swift/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.build
Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
14 changes: 14 additions & 0 deletions compiled_starters/swift/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "build-your-own-shell",
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "build-your-own-shell"),
]
)
35 changes: 35 additions & 0 deletions compiled_starters/swift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)

This is a starting point for Swift solutions to the
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).

In this challenge, you'll build your own POSIX compliant shell that's capable of
interpreting shell commands, running external programs and builtin commands like
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
REPLs, builtin commands, and more.

**Note**: If you're viewing this repo on GitHub, head over to
[codecrafters.io](https://codecrafters.io) to try the challenge.

# Passing the first stage

The entry point for your `shell` implementation is in `Sources/main.swift`.
Study and uncomment the relevant code, and push your changes to pass the first
stage:

```sh
git commit -am "pass 1st stage" # any msg
git push origin master
```

Time to move on to the next stage!

# Stage 2 & beyond

Note: This section is for stages 2 and beyond.

1. Ensure you have `swift (>=6.0)` installed locally
1. Run `./your_program.sh` to run your program, which is implemented in
`Sources/main.swift`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
5 changes: 5 additions & 0 deletions compiled_starters/swift/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

// Uncomment this block to pass the first stage
// print("$ ", terminator: "")
// _ = readLine()
11 changes: 11 additions & 0 deletions compiled_starters/swift/codecrafters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set this to true if you want debug logs.
#
# These can be VERY verbose, so we suggest turning them off
# unless you really need them.
debug: false

# Use this to change the Swift version used to run your code
# on Codecrafters.
#
# Available versions: swift-6.0
buildpack: swift-6.0
24 changes: 24 additions & 0 deletions compiled_starters/swift/your_program.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
#
# Use this script to run your program LOCALLY.
#
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit early if any commands fail

# Copied from .codecrafters/compile.sh
#
# - Edit this to change how your program compiles locally
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
(
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
swift build -c release --build-path /tmp/codecrafters-build-shell-swift
)

# Copied from .codecrafters/run.sh
#
# - Edit this to change how your program runs locally
# - Edit .codecrafters/run.sh to change how your program runs remotely
exec swift run -c release --skip-build --build-path /tmp/codecrafters-build-shell-swift build-your-own-shell "$@"
1 change: 1 addition & 0 deletions course-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ languages:
- slug: "rust"
- slug: "typescript"
- slug: "zig"
- slug: "swift"

marketing:
difficulty: medium
Expand Down
15 changes: 15 additions & 0 deletions dockerfiles/swift-6.0.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# syntax=docker/dockerfile:1.7-labs
FROM swift:6.0-focal

# Ensures the container is re-built if Package.swift changes
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Package.swift"

WORKDIR /app

# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
COPY --exclude=.git --exclude=README.md . /app

RUN .codecrafters/compile.sh

# Cache dependencies (TODO: Check if this is required, or whether build implicitly caches dependencies)
RUN swift package --build-path /tmp/codecrafters-build-shell-swift resolve
11 changes: 11 additions & 0 deletions solutions/swift/01-oo8/code/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to compile your program on CodeCrafters
#
# This runs before .codecrafters/run.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

swift build -c release --build-path /tmp/codecrafters-build-shell-swift
11 changes: 11 additions & 0 deletions solutions/swift/01-oo8/code/.codecrafters/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

exec swift run -c release --skip-build --build-path /tmp/codecrafters-build-shell-swift build-your-own-shell "$@"
1 change: 1 addition & 0 deletions solutions/swift/01-oo8/code/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
8 changes: 8 additions & 0 deletions solutions/swift/01-oo8/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.build
Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
14 changes: 14 additions & 0 deletions solutions/swift/01-oo8/code/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "build-your-own-shell",
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "build-your-own-shell"),
]
)
35 changes: 35 additions & 0 deletions solutions/swift/01-oo8/code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)

This is a starting point for Swift solutions to the
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).

In this challenge, you'll build your own POSIX compliant shell that's capable of
interpreting shell commands, running external programs and builtin commands like
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
REPLs, builtin commands, and more.

**Note**: If you're viewing this repo on GitHub, head over to
[codecrafters.io](https://codecrafters.io) to try the challenge.

# Passing the first stage

The entry point for your `shell` implementation is in `Sources/main.swift`.
Study and uncomment the relevant code, and push your changes to pass the first
stage:

```sh
git commit -am "pass 1st stage" # any msg
git push origin master
```

Time to move on to the next stage!

# Stage 2 & beyond

Note: This section is for stages 2 and beyond.

1. Ensure you have `swift (>=6.0)` installed locally
1. Run `./your_program.sh` to run your program, which is implemented in
`Sources/main.swift`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
4 changes: 4 additions & 0 deletions solutions/swift/01-oo8/code/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Foundation

print("$ ", terminator: "")
_ = readLine()
11 changes: 11 additions & 0 deletions solutions/swift/01-oo8/code/codecrafters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set this to true if you want debug logs.
#
# These can be VERY verbose, so we suggest turning them off
# unless you really need them.
debug: false

# Use this to change the Swift version used to run your code
# on Codecrafters.
#
# Available versions: swift-6.0
buildpack: swift-6.0
24 changes: 24 additions & 0 deletions solutions/swift/01-oo8/code/your_program.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
#
# Use this script to run your program LOCALLY.
#
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit early if any commands fail

# Copied from .codecrafters/compile.sh
#
# - Edit this to change how your program compiles locally
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
(
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
swift build -c release --build-path /tmp/codecrafters-build-shell-swift
)

# Copied from .codecrafters/run.sh
#
# - Edit this to change how your program runs locally
# - Edit .codecrafters/run.sh to change how your program runs remotely
exec swift run -c release --skip-build --build-path /tmp/codecrafters-build-shell-swift build-your-own-shell "$@"
8 changes: 8 additions & 0 deletions solutions/swift/01-oo8/diff/Sources/main.swift.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@@ -1,5 +1,4 @@
import Foundation

-// Uncomment this block to pass the first stage
-// print("$ ", terminator: "")
-// _ = readLine()
+print("$ ", terminator: "")
+_ = readLine()
17 changes: 17 additions & 0 deletions solutions/swift/01-oo8/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The entry point for your Shell implementation is in `Sources/main.swift`.

Study and uncomment the relevant code:

```swift
// Uncomment this block to pass the first stage
print("$ ", terminator: "")
_ = readLine()
```

Push your changes to pass the first stage:

```
git add .
git commit -m "pass 1st stage" # any msg
git push origin master
```
11 changes: 11 additions & 0 deletions starter_templates/swift/code/.codecrafters/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to compile your program on CodeCrafters
#
# This runs before .codecrafters/run.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

swift build -c release --build-path /tmp/codecrafters-build-shell-swift
11 changes: 11 additions & 0 deletions starter_templates/swift/code/.codecrafters/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure

exec swift run -c release --skip-build --build-path /tmp/codecrafters-build-shell-swift build-your-own-shell "$@"
8 changes: 8 additions & 0 deletions starter_templates/swift/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.build
Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
14 changes: 14 additions & 0 deletions starter_templates/swift/code/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "build-your-own-shell",
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "build-your-own-shell"),
]
)
5 changes: 5 additions & 0 deletions starter_templates/swift/code/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

// Uncomment this block to pass the first stage
// print("$ ", terminator: "")
// _ = readLine()
3 changes: 3 additions & 0 deletions starter_templates/swift/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
attributes:
required_executable: "swift (>=6.0)"
user_editable_file: Sources/main.swift