From d7c20559fc58a17a2137ebeb7bdcb6ba4839fbb5 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 17 Sep 2024 17:53:20 +0100 Subject: [PATCH 1/5] Add initial Gleam project structure and scripts for CodeCrafters challenge. --- .../gleam/.codecrafters/compile.sh | 11 ++++++ compiled_starters/gleam/.codecrafters/run.sh | 11 ++++++ compiled_starters/gleam/.gitattributes | 1 + compiled_starters/gleam/.gitignore | 4 ++ compiled_starters/gleam/README.md | 34 +++++++++++++++++ compiled_starters/gleam/codecrafters.yml | 11 ++++++ compiled_starters/gleam/gleam.toml | 11 ++++++ compiled_starters/gleam/manifest.toml | 11 ++++++ compiled_starters/gleam/src/main.gleam | 29 ++++++++++++++ compiled_starters/gleam/your_program.sh | 24 ++++++++++++ dockerfiles/gleam-1.4.Dockerfile | 17 +++++++++ .../01-vi6/code/.codecrafters/compile.sh | 11 ++++++ .../gleam/01-vi6/code/.codecrafters/run.sh | 11 ++++++ solutions/gleam/01-vi6/code/.gitattributes | 1 + solutions/gleam/01-vi6/code/.gitignore | 4 ++ solutions/gleam/01-vi6/code/README.md | 34 +++++++++++++++++ solutions/gleam/01-vi6/code/codecrafters.yml | 11 ++++++ solutions/gleam/01-vi6/code/gleam.toml | 11 ++++++ solutions/gleam/01-vi6/code/manifest.toml | 11 ++++++ solutions/gleam/01-vi6/code/src/main.gleam | 24 ++++++++++++ solutions/gleam/01-vi6/code/your_program.sh | 24 ++++++++++++ .../gleam/01-vi6/diff/src/main.gleam.diff | 38 +++++++++++++++++++ solutions/gleam/01-vi6/explanation.md | 24 ++++++++++++ .../gleam/code/.codecrafters/compile.sh | 11 ++++++ .../gleam/code/.codecrafters/run.sh | 11 ++++++ starter_templates/gleam/code/.gitignore | 4 ++ starter_templates/gleam/code/gleam.toml | 11 ++++++ starter_templates/gleam/code/manifest.toml | 11 ++++++ starter_templates/gleam/code/src/main.gleam | 29 ++++++++++++++ starter_templates/gleam/config.yml | 3 ++ 30 files changed, 448 insertions(+) create mode 100755 compiled_starters/gleam/.codecrafters/compile.sh create mode 100755 compiled_starters/gleam/.codecrafters/run.sh create mode 100644 compiled_starters/gleam/.gitattributes create mode 100644 compiled_starters/gleam/.gitignore create mode 100644 compiled_starters/gleam/README.md create mode 100644 compiled_starters/gleam/codecrafters.yml create mode 100644 compiled_starters/gleam/gleam.toml create mode 100644 compiled_starters/gleam/manifest.toml create mode 100644 compiled_starters/gleam/src/main.gleam create mode 100755 compiled_starters/gleam/your_program.sh create mode 100644 dockerfiles/gleam-1.4.Dockerfile create mode 100755 solutions/gleam/01-vi6/code/.codecrafters/compile.sh create mode 100755 solutions/gleam/01-vi6/code/.codecrafters/run.sh create mode 100644 solutions/gleam/01-vi6/code/.gitattributes create mode 100644 solutions/gleam/01-vi6/code/.gitignore create mode 100644 solutions/gleam/01-vi6/code/README.md create mode 100644 solutions/gleam/01-vi6/code/codecrafters.yml create mode 100644 solutions/gleam/01-vi6/code/gleam.toml create mode 100644 solutions/gleam/01-vi6/code/manifest.toml create mode 100644 solutions/gleam/01-vi6/code/src/main.gleam create mode 100755 solutions/gleam/01-vi6/code/your_program.sh create mode 100644 solutions/gleam/01-vi6/diff/src/main.gleam.diff create mode 100644 solutions/gleam/01-vi6/explanation.md create mode 100755 starter_templates/gleam/code/.codecrafters/compile.sh create mode 100755 starter_templates/gleam/code/.codecrafters/run.sh create mode 100644 starter_templates/gleam/code/.gitignore create mode 100644 starter_templates/gleam/code/gleam.toml create mode 100644 starter_templates/gleam/code/manifest.toml create mode 100644 starter_templates/gleam/code/src/main.gleam create mode 100644 starter_templates/gleam/config.yml diff --git a/compiled_starters/gleam/.codecrafters/compile.sh b/compiled_starters/gleam/.codecrafters/compile.sh new file mode 100755 index 0000000..0f4122e --- /dev/null +++ b/compiled_starters/gleam/.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 + +gleam build diff --git a/compiled_starters/gleam/.codecrafters/run.sh b/compiled_starters/gleam/.codecrafters/run.sh new file mode 100755 index 0000000..8d39ab0 --- /dev/null +++ b/compiled_starters/gleam/.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 gleam run --module main -- "$@" diff --git a/compiled_starters/gleam/.gitattributes b/compiled_starters/gleam/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/gleam/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/gleam/.gitignore b/compiled_starters/gleam/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/compiled_starters/gleam/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/compiled_starters/gleam/README.md b/compiled_starters/gleam/README.md new file mode 100644 index 0000000..6db1fb4 --- /dev/null +++ b/compiled_starters/gleam/README.md @@ -0,0 +1,34 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/kafka.png) + +This is a starting point for Gleam solutions to the +["Build Your Own Kafka" Challenge](https://codecrafters.io/challenges/kafka). + +In this challenge, you'll build a toy Kafka clone that's capable of accepting +and responding to APIVersions & Fetch API requests. You'll also learn about +encoding and decoding messages using the Kafka wire protocol. You'll also learn +about handling the network protocol, event loops, TCP sockets 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 Kafka implementation is in `src/main.gleam`. 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 +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `gleam (1.0+)` installed locally +1. Run `./your_program.sh` to run your Kafka broker, which is implemented in + `src/main.gleam`. +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/gleam/codecrafters.yml b/compiled_starters/gleam/codecrafters.yml new file mode 100644 index 0000000..6589fc2 --- /dev/null +++ b/compiled_starters/gleam/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 Gleam version used to run your code +# on Codecrafters. +# +# Available versions: gleam-1.4 +language_pack: gleam-1.4 diff --git a/compiled_starters/gleam/gleam.toml b/compiled_starters/gleam/gleam.toml new file mode 100644 index 0000000..7915c96 --- /dev/null +++ b/compiled_starters/gleam/gleam.toml @@ -0,0 +1,11 @@ +name = "codecrafters_kafka" +version = "1.0.0" + +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_stdlib = "~> 0.34 or ~> 1.0" + +[dev-dependencies] +gleeunit = "~> 1.0" diff --git a/compiled_starters/gleam/manifest.toml b/compiled_starters/gleam/manifest.toml new file mode 100644 index 0000000..37eae7c --- /dev/null +++ b/compiled_starters/gleam/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/compiled_starters/gleam/src/main.gleam b/compiled_starters/gleam/src/main.gleam new file mode 100644 index 0000000..bcba553 --- /dev/null +++ b/compiled_starters/gleam/src/main.gleam @@ -0,0 +1,29 @@ +import gleam/io + +import gleam/erlang/process +import gleam/option.{None} +import gleam/otp/actor +import glisten + +pub fn main() { + // Ensures gleam doesn't complain about unused imports in stage 1 (feel free to remove this!) + let _ = glisten.handler + let _ = glisten.serve + let _ = process.sleep_forever + let _ = actor.continue + let _ = None + + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + // Uncomment this block to pass the first stage + // + // let assert Ok(_) = + // glisten.handler(fn(_conn) { #(Nil, None) }, fn(_msg, state, _conn) { + // io.println("Received message!") + // actor.continue(state) + // }) + // |> glisten.serve(9092) + // + // process.sleep_forever() +} \ No newline at end of file diff --git a/compiled_starters/gleam/your_program.sh b/compiled_starters/gleam/your_program.sh new file mode 100755 index 0000000..3dea0f5 --- /dev/null +++ b/compiled_starters/gleam/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 + gleam build +) + +# 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 gleam run --module main -- "$@" diff --git a/dockerfiles/gleam-1.4.Dockerfile b/dockerfiles/gleam-1.4.Dockerfile new file mode 100644 index 0000000..82b3e8b --- /dev/null +++ b/dockerfiles/gleam-1.4.Dockerfile @@ -0,0 +1,17 @@ +# syntax=docker/dockerfile:1.7-labs +FROM ghcr.io/gleam-lang/gleam:v1.4.1-erlang-alpine + +# Rebuild if gleam.toml or manifest.toml change +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="gleam.toml,manifest.toml" + +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 + +# Force deps to be downloaded +RUN gleam build + +# Cache build directory +RUN mkdir -p /app-cached +RUN mv build /app-cached/build diff --git a/solutions/gleam/01-vi6/code/.codecrafters/compile.sh b/solutions/gleam/01-vi6/code/.codecrafters/compile.sh new file mode 100755 index 0000000..0f4122e --- /dev/null +++ b/solutions/gleam/01-vi6/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 + +gleam build diff --git a/solutions/gleam/01-vi6/code/.codecrafters/run.sh b/solutions/gleam/01-vi6/code/.codecrafters/run.sh new file mode 100755 index 0000000..8d39ab0 --- /dev/null +++ b/solutions/gleam/01-vi6/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 gleam run --module main -- "$@" diff --git a/solutions/gleam/01-vi6/code/.gitattributes b/solutions/gleam/01-vi6/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/gleam/01-vi6/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/gleam/01-vi6/code/.gitignore b/solutions/gleam/01-vi6/code/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/solutions/gleam/01-vi6/code/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/solutions/gleam/01-vi6/code/README.md b/solutions/gleam/01-vi6/code/README.md new file mode 100644 index 0000000..6db1fb4 --- /dev/null +++ b/solutions/gleam/01-vi6/code/README.md @@ -0,0 +1,34 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/kafka.png) + +This is a starting point for Gleam solutions to the +["Build Your Own Kafka" Challenge](https://codecrafters.io/challenges/kafka). + +In this challenge, you'll build a toy Kafka clone that's capable of accepting +and responding to APIVersions & Fetch API requests. You'll also learn about +encoding and decoding messages using the Kafka wire protocol. You'll also learn +about handling the network protocol, event loops, TCP sockets 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 Kafka implementation is in `src/main.gleam`. 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 +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `gleam (1.0+)` installed locally +1. Run `./your_program.sh` to run your Kafka broker, which is implemented in + `src/main.gleam`. +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/gleam/01-vi6/code/codecrafters.yml b/solutions/gleam/01-vi6/code/codecrafters.yml new file mode 100644 index 0000000..6589fc2 --- /dev/null +++ b/solutions/gleam/01-vi6/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 Gleam version used to run your code +# on Codecrafters. +# +# Available versions: gleam-1.4 +language_pack: gleam-1.4 diff --git a/solutions/gleam/01-vi6/code/gleam.toml b/solutions/gleam/01-vi6/code/gleam.toml new file mode 100644 index 0000000..7915c96 --- /dev/null +++ b/solutions/gleam/01-vi6/code/gleam.toml @@ -0,0 +1,11 @@ +name = "codecrafters_kafka" +version = "1.0.0" + +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_stdlib = "~> 0.34 or ~> 1.0" + +[dev-dependencies] +gleeunit = "~> 1.0" diff --git a/solutions/gleam/01-vi6/code/manifest.toml b/solutions/gleam/01-vi6/code/manifest.toml new file mode 100644 index 0000000..37eae7c --- /dev/null +++ b/solutions/gleam/01-vi6/code/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/solutions/gleam/01-vi6/code/src/main.gleam b/solutions/gleam/01-vi6/code/src/main.gleam new file mode 100644 index 0000000..a1cd3d0 --- /dev/null +++ b/solutions/gleam/01-vi6/code/src/main.gleam @@ -0,0 +1,24 @@ +import gleam/io + +import gleam/erlang/process +import gleam/option.{None} +import gleam/otp/actor +import glisten + +pub fn main() { + // Ensures gleam doesn't complain about unused imports in stage 1 (feel free to remove this!) + let _ = glisten.handler + let _ = glisten.serve + let _ = process.sleep_forever + let _ = actor.continue + let _ = None + + let assert Ok(_) = + glisten.handler(fn(_conn) { #(Nil, None) }, fn(_msg, state, _conn) { + io.println("Received message!") + actor.continue(state) + }) + |> glisten.serve(9092) + + process.sleep_forever() +} \ No newline at end of file diff --git a/solutions/gleam/01-vi6/code/your_program.sh b/solutions/gleam/01-vi6/code/your_program.sh new file mode 100755 index 0000000..3dea0f5 --- /dev/null +++ b/solutions/gleam/01-vi6/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 + gleam build +) + +# 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 gleam run --module main -- "$@" diff --git a/solutions/gleam/01-vi6/diff/src/main.gleam.diff b/solutions/gleam/01-vi6/diff/src/main.gleam.diff new file mode 100644 index 0000000..ec2ac09 --- /dev/null +++ b/solutions/gleam/01-vi6/diff/src/main.gleam.diff @@ -0,0 +1,38 @@ +@@ -1,29 +1,24 @@ + import gleam/io + + import gleam/erlang/process + import gleam/option.{None} + import gleam/otp/actor + import glisten + + pub fn main() { + // Ensures gleam doesn't complain about unused imports in stage 1 (feel free to remove this!) + let _ = glisten.handler + let _ = glisten.serve + let _ = process.sleep_forever + let _ = actor.continue + let _ = None + +- // You can use print statements as follows for debugging, they'll be visible when running tests. +- io.println("Logs from your program will appear here!") ++ let assert Ok(_) = ++ glisten.handler(fn(_conn) { #(Nil, None) }, fn(_msg, state, _conn) { ++ io.println("Received message!") ++ actor.continue(state) ++ }) ++ |> glisten.serve(9092) + +- // Uncomment this block to pass the first stage +- // +- // let assert Ok(_) = +- // glisten.handler(fn(_conn) { #(Nil, None) }, fn(_msg, state, _conn) { +- // io.println("Received message!") +- // actor.continue(state) +- // }) +- // |> glisten.serve(9092) +- // +- // process.sleep_forever() ++ process.sleep_forever() + } +\ No newline at end of file diff --git a/solutions/gleam/01-vi6/explanation.md b/solutions/gleam/01-vi6/explanation.md new file mode 100644 index 0000000..b30711d --- /dev/null +++ b/solutions/gleam/01-vi6/explanation.md @@ -0,0 +1,24 @@ +The entry point for your Kafka implementation is in `src/main.gleam`. + +Study and uncomment the relevant code: + +```gleam +// Uncomment this block to pass the first stage + +let assert Ok(_) = + glisten.handler(fn(_conn) { #(Nil, None) }, fn(_msg, state, _conn) { + io.println("Received message!") + actor.continue(state) + }) + |> glisten.serve(9092) + +process.sleep_forever() +``` + +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/gleam/code/.codecrafters/compile.sh b/starter_templates/gleam/code/.codecrafters/compile.sh new file mode 100755 index 0000000..0f4122e --- /dev/null +++ b/starter_templates/gleam/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 + +gleam build diff --git a/starter_templates/gleam/code/.codecrafters/run.sh b/starter_templates/gleam/code/.codecrafters/run.sh new file mode 100755 index 0000000..8d39ab0 --- /dev/null +++ b/starter_templates/gleam/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 gleam run --module main -- "$@" diff --git a/starter_templates/gleam/code/.gitignore b/starter_templates/gleam/code/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/starter_templates/gleam/code/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/starter_templates/gleam/code/gleam.toml b/starter_templates/gleam/code/gleam.toml new file mode 100644 index 0000000..7915c96 --- /dev/null +++ b/starter_templates/gleam/code/gleam.toml @@ -0,0 +1,11 @@ +name = "codecrafters_kafka" +version = "1.0.0" + +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_stdlib = "~> 0.34 or ~> 1.0" + +[dev-dependencies] +gleeunit = "~> 1.0" diff --git a/starter_templates/gleam/code/manifest.toml b/starter_templates/gleam/code/manifest.toml new file mode 100644 index 0000000..37eae7c --- /dev/null +++ b/starter_templates/gleam/code/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/starter_templates/gleam/code/src/main.gleam b/starter_templates/gleam/code/src/main.gleam new file mode 100644 index 0000000..bcba553 --- /dev/null +++ b/starter_templates/gleam/code/src/main.gleam @@ -0,0 +1,29 @@ +import gleam/io + +import gleam/erlang/process +import gleam/option.{None} +import gleam/otp/actor +import glisten + +pub fn main() { + // Ensures gleam doesn't complain about unused imports in stage 1 (feel free to remove this!) + let _ = glisten.handler + let _ = glisten.serve + let _ = process.sleep_forever + let _ = actor.continue + let _ = None + + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + // Uncomment this block to pass the first stage + // + // let assert Ok(_) = + // glisten.handler(fn(_conn) { #(Nil, None) }, fn(_msg, state, _conn) { + // io.println("Received message!") + // actor.continue(state) + // }) + // |> glisten.serve(9092) + // + // process.sleep_forever() +} \ No newline at end of file diff --git a/starter_templates/gleam/config.yml b/starter_templates/gleam/config.yml new file mode 100644 index 0000000..329d8d6 --- /dev/null +++ b/starter_templates/gleam/config.yml @@ -0,0 +1,3 @@ +attributes: + required_executable: gleam (1.0+) + user_editable_file: src/main.gleam From ae953718307a97b189e1c3fdc3a4c4fea5286aed Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 17 Sep 2024 17:59:14 +0100 Subject: [PATCH 2/5] Add gleam_erlang, gleam_otp, and glisten dependencies to gleam.toml files --- compiled_starters/gleam/gleam.toml | 3 +++ solutions/gleam/01-vi6/code/gleam.toml | 3 +++ starter_templates/gleam/code/gleam.toml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/compiled_starters/gleam/gleam.toml b/compiled_starters/gleam/gleam.toml index 7915c96..bb4b799 100644 --- a/compiled_starters/gleam/gleam.toml +++ b/compiled_starters/gleam/gleam.toml @@ -6,6 +6,9 @@ version = "1.0.0" [dependencies] gleam_stdlib = "~> 0.34 or ~> 1.0" +gleam_erlang = "~> 0.25" +gleam_otp = "~> 0.10" +glisten = "~> 2.0" [dev-dependencies] gleeunit = "~> 1.0" diff --git a/solutions/gleam/01-vi6/code/gleam.toml b/solutions/gleam/01-vi6/code/gleam.toml index 7915c96..bb4b799 100644 --- a/solutions/gleam/01-vi6/code/gleam.toml +++ b/solutions/gleam/01-vi6/code/gleam.toml @@ -6,6 +6,9 @@ version = "1.0.0" [dependencies] gleam_stdlib = "~> 0.34 or ~> 1.0" +gleam_erlang = "~> 0.25" +gleam_otp = "~> 0.10" +glisten = "~> 2.0" [dev-dependencies] gleeunit = "~> 1.0" diff --git a/starter_templates/gleam/code/gleam.toml b/starter_templates/gleam/code/gleam.toml index 7915c96..bb4b799 100644 --- a/starter_templates/gleam/code/gleam.toml +++ b/starter_templates/gleam/code/gleam.toml @@ -6,6 +6,9 @@ version = "1.0.0" [dependencies] gleam_stdlib = "~> 0.34 or ~> 1.0" +gleam_erlang = "~> 0.25" +gleam_otp = "~> 0.10" +glisten = "~> 2.0" [dev-dependencies] gleeunit = "~> 1.0" From cafdd235f7466177f4ca5654fd8e45ad351e1620 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 17 Sep 2024 17:59:51 +0100 Subject: [PATCH 3/5] Update gleam dependencies in manifest.toml for gleam_erlang, gleam_otp, and glisten. --- compiled_starters/gleam/manifest.toml | 6 ++++++ starter_templates/gleam/code/manifest.toml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/compiled_starters/gleam/manifest.toml b/compiled_starters/gleam/manifest.toml index 37eae7c..0604deb 100644 --- a/compiled_starters/gleam/manifest.toml +++ b/compiled_starters/gleam/manifest.toml @@ -2,10 +2,16 @@ # You typically do not need to edit this file packages = [ + { name = "gleam_erlang", version = "0.26.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "3DF72F95F4716883FA51396FB0C550ED3D55195B541568CAF09745984FD37AD1" }, + { name = "gleam_otp", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "CD5FC777E99673BDB390092DF85E34EAA6B8EE1882147496290AB3F45A4960B1" }, { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, + { name = "glisten", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "CF3A9383E9BA4A8CBAF2F7B799716290D02F2AC34E7A77556B49376B662B9314" }, ] [requirements] +gleam_erlang = { version = "~> 0.25" } +gleam_otp = { version = "~> 0.10" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } +glisten = { version = "~> 2.0" } diff --git a/starter_templates/gleam/code/manifest.toml b/starter_templates/gleam/code/manifest.toml index 37eae7c..0604deb 100644 --- a/starter_templates/gleam/code/manifest.toml +++ b/starter_templates/gleam/code/manifest.toml @@ -2,10 +2,16 @@ # You typically do not need to edit this file packages = [ + { name = "gleam_erlang", version = "0.26.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "3DF72F95F4716883FA51396FB0C550ED3D55195B541568CAF09745984FD37AD1" }, + { name = "gleam_otp", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "CD5FC777E99673BDB390092DF85E34EAA6B8EE1882147496290AB3F45A4960B1" }, { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, + { name = "glisten", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "CF3A9383E9BA4A8CBAF2F7B799716290D02F2AC34E7A77556B49376B662B9314" }, ] [requirements] +gleam_erlang = { version = "~> 0.25" } +gleam_otp = { version = "~> 0.10" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } +glisten = { version = "~> 2.0" } From 66feb1c5e5bedfe04de0c715355a6d26250c4456 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 17 Sep 2024 18:03:59 +0100 Subject: [PATCH 4/5] Add gleam_erlang, gleam_otp, and glisten dependencies to manifest.toml --- solutions/gleam/01-vi6/code/manifest.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/solutions/gleam/01-vi6/code/manifest.toml b/solutions/gleam/01-vi6/code/manifest.toml index 37eae7c..0604deb 100644 --- a/solutions/gleam/01-vi6/code/manifest.toml +++ b/solutions/gleam/01-vi6/code/manifest.toml @@ -2,10 +2,16 @@ # You typically do not need to edit this file packages = [ + { name = "gleam_erlang", version = "0.26.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "3DF72F95F4716883FA51396FB0C550ED3D55195B541568CAF09745984FD37AD1" }, + { name = "gleam_otp", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "CD5FC777E99673BDB390092DF85E34EAA6B8EE1882147496290AB3F45A4960B1" }, { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, + { name = "glisten", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "CF3A9383E9BA4A8CBAF2F7B799716290D02F2AC34E7A77556B49376B662B9314" }, ] [requirements] +gleam_erlang = { version = "~> 0.25" } +gleam_otp = { version = "~> 0.10" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } +glisten = { version = "~> 2.0" } From 68832f0cd57e73b0758d0af0c02725972374569d Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 17 Sep 2024 18:04:11 +0100 Subject: [PATCH 5/5] Add Gleam and JavaScript to the list of supported languages in course definition. --- course-definition.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/course-definition.yml b/course-definition.yml index 028ed8c..152e5f0 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -15,10 +15,11 @@ short_description_md: |- completion_percentage: 15 languages: + - slug: "gleam" - slug: "go" + - slug: "javascript" - slug: "python" - slug: "rust" - - slug: "javascript" marketing: difficulty: medium