diff --git a/compiled_starters/swift/.codecrafters/compile.sh b/compiled_starters/swift/.codecrafters/compile.sh new file mode 100755 index 0000000..06109ef --- /dev/null +++ b/compiled_starters/swift/.codecrafters/compile.sh @@ -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 diff --git a/compiled_starters/swift/.codecrafters/run.sh b/compiled_starters/swift/.codecrafters/run.sh new file mode 100755 index 0000000..0b55717 --- /dev/null +++ b/compiled_starters/swift/.codecrafters/run.sh @@ -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 "$@" diff --git a/compiled_starters/swift/.gitattributes b/compiled_starters/swift/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/swift/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/swift/.gitignore b/compiled_starters/swift/.gitignore new file mode 100644 index 0000000..21d4f9d --- /dev/null +++ b/compiled_starters/swift/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.build +Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc \ No newline at end of file diff --git a/compiled_starters/swift/Package.swift b/compiled_starters/swift/Package.swift new file mode 100644 index 0000000..dd04570 --- /dev/null +++ b/compiled_starters/swift/Package.swift @@ -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"), + ] +) \ No newline at end of file diff --git a/compiled_starters/swift/README.md b/compiled_starters/swift/README.md new file mode 100644 index 0000000..5b3d893 --- /dev/null +++ b/compiled_starters/swift/README.md @@ -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. diff --git a/compiled_starters/swift/Sources/main.swift b/compiled_starters/swift/Sources/main.swift new file mode 100644 index 0000000..97d5929 --- /dev/null +++ b/compiled_starters/swift/Sources/main.swift @@ -0,0 +1,5 @@ +import Foundation + +// Uncomment this block to pass the first stage +// print("$ ", terminator: "") +// _ = readLine() diff --git a/compiled_starters/swift/codecrafters.yml b/compiled_starters/swift/codecrafters.yml new file mode 100644 index 0000000..640bdb5 --- /dev/null +++ b/compiled_starters/swift/codecrafters.yml @@ -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 diff --git a/compiled_starters/swift/your_program.sh b/compiled_starters/swift/your_program.sh new file mode 100755 index 0000000..27a033c --- /dev/null +++ b/compiled_starters/swift/your_program.sh @@ -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 "$@" diff --git a/course-definition.yml b/course-definition.yml index 85b355e..c98195d 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -31,6 +31,7 @@ languages: - slug: "rust" - slug: "typescript" - slug: "zig" + - slug: "swift" marketing: difficulty: medium diff --git a/dockerfiles/swift-6.0.Dockerfile b/dockerfiles/swift-6.0.Dockerfile new file mode 100644 index 0000000..96bf7f3 --- /dev/null +++ b/dockerfiles/swift-6.0.Dockerfile @@ -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 \ No newline at end of file diff --git a/solutions/swift/01-oo8/code/.codecrafters/compile.sh b/solutions/swift/01-oo8/code/.codecrafters/compile.sh new file mode 100755 index 0000000..06109ef --- /dev/null +++ b/solutions/swift/01-oo8/code/.codecrafters/compile.sh @@ -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 diff --git a/solutions/swift/01-oo8/code/.codecrafters/run.sh b/solutions/swift/01-oo8/code/.codecrafters/run.sh new file mode 100755 index 0000000..0b55717 --- /dev/null +++ b/solutions/swift/01-oo8/code/.codecrafters/run.sh @@ -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 "$@" diff --git a/solutions/swift/01-oo8/code/.gitattributes b/solutions/swift/01-oo8/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/swift/01-oo8/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/swift/01-oo8/code/.gitignore b/solutions/swift/01-oo8/code/.gitignore new file mode 100644 index 0000000..21d4f9d --- /dev/null +++ b/solutions/swift/01-oo8/code/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.build +Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc \ No newline at end of file diff --git a/solutions/swift/01-oo8/code/Package.swift b/solutions/swift/01-oo8/code/Package.swift new file mode 100644 index 0000000..dd04570 --- /dev/null +++ b/solutions/swift/01-oo8/code/Package.swift @@ -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"), + ] +) \ No newline at end of file diff --git a/solutions/swift/01-oo8/code/README.md b/solutions/swift/01-oo8/code/README.md new file mode 100644 index 0000000..5b3d893 --- /dev/null +++ b/solutions/swift/01-oo8/code/README.md @@ -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. diff --git a/solutions/swift/01-oo8/code/Sources/main.swift b/solutions/swift/01-oo8/code/Sources/main.swift new file mode 100644 index 0000000..8824382 --- /dev/null +++ b/solutions/swift/01-oo8/code/Sources/main.swift @@ -0,0 +1,4 @@ +import Foundation + +print("$ ", terminator: "") +_ = readLine() diff --git a/solutions/swift/01-oo8/code/codecrafters.yml b/solutions/swift/01-oo8/code/codecrafters.yml new file mode 100644 index 0000000..640bdb5 --- /dev/null +++ b/solutions/swift/01-oo8/code/codecrafters.yml @@ -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 diff --git a/solutions/swift/01-oo8/code/your_program.sh b/solutions/swift/01-oo8/code/your_program.sh new file mode 100755 index 0000000..27a033c --- /dev/null +++ b/solutions/swift/01-oo8/code/your_program.sh @@ -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 "$@" diff --git a/solutions/swift/01-oo8/diff/Sources/main.swift.diff b/solutions/swift/01-oo8/diff/Sources/main.swift.diff new file mode 100644 index 0000000..87ea586 --- /dev/null +++ b/solutions/swift/01-oo8/diff/Sources/main.swift.diff @@ -0,0 +1,8 @@ +@@ -1,5 +1,4 @@ + import Foundation + +-// Uncomment this block to pass the first stage +-// print("$ ", terminator: "") +-// _ = readLine() ++print("$ ", terminator: "") ++_ = readLine() diff --git a/solutions/swift/01-oo8/explanation.md b/solutions/swift/01-oo8/explanation.md new file mode 100644 index 0000000..3323c0a --- /dev/null +++ b/solutions/swift/01-oo8/explanation.md @@ -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 +``` diff --git a/starter_templates/swift/code/.codecrafters/compile.sh b/starter_templates/swift/code/.codecrafters/compile.sh new file mode 100755 index 0000000..06109ef --- /dev/null +++ b/starter_templates/swift/code/.codecrafters/compile.sh @@ -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 diff --git a/starter_templates/swift/code/.codecrafters/run.sh b/starter_templates/swift/code/.codecrafters/run.sh new file mode 100755 index 0000000..0b55717 --- /dev/null +++ b/starter_templates/swift/code/.codecrafters/run.sh @@ -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 "$@" diff --git a/starter_templates/swift/code/.gitignore b/starter_templates/swift/code/.gitignore new file mode 100644 index 0000000..21d4f9d --- /dev/null +++ b/starter_templates/swift/code/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.build +Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc \ No newline at end of file diff --git a/starter_templates/swift/code/Package.swift b/starter_templates/swift/code/Package.swift new file mode 100644 index 0000000..dd04570 --- /dev/null +++ b/starter_templates/swift/code/Package.swift @@ -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"), + ] +) \ No newline at end of file diff --git a/starter_templates/swift/code/Sources/main.swift b/starter_templates/swift/code/Sources/main.swift new file mode 100644 index 0000000..97d5929 --- /dev/null +++ b/starter_templates/swift/code/Sources/main.swift @@ -0,0 +1,5 @@ +import Foundation + +// Uncomment this block to pass the first stage +// print("$ ", terminator: "") +// _ = readLine() diff --git a/starter_templates/swift/config.yml b/starter_templates/swift/config.yml new file mode 100644 index 0000000..393914c --- /dev/null +++ b/starter_templates/swift/config.yml @@ -0,0 +1,3 @@ +attributes: + required_executable: "swift (>=6.0)" + user_editable_file: Sources/main.swift