Skip to content

Commit 7b7c02e

Browse files
authored
Merge pull request #305 from codecrafters-io/andy/upgrade
[Redis] CC-1745: Upgrade Bun to v1.2, Rust to v1.86, and Elixir to v1.18
2 parents 938a2b4 + d907048 commit 7b7c02e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+278
-51
lines changed

compiled_starters/elixir/.codecrafters/compile.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
set -e # Exit on failure
1010

11-
# (This file is empty since Elixir programs don't use a compile step)
11+
mix escript.build
12+
mv codecrafters_redis /tmp/codecrafters-build-redis-elixir

compiled_starters/elixir/.codecrafters/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
set -e # Exit on failure
1010

11-
exec mix run --no-halt -- "$@"
11+
exec /tmp/codecrafters-build-redis-elixir "$@"

compiled_starters/elixir/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Ignore the compiled binary
2+
/codecrafters_redis
3+
14
# The directory Mix will write compiled artifacts to.
25
/_build/
36

compiled_starters/elixir/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ event loops, the Redis protocol and more.
1212

1313
# Passing the first stage
1414

15-
The entry point for your Redis implementation is in `lib/server.ex`. Study and
15+
The entry point for your Redis implementation is in `lib/main.ex`. Study and
1616
uncomment the relevant code, and push your changes to pass the first stage:
1717

1818
```sh
@@ -28,6 +28,6 @@ Note: This section is for stages 2 and beyond.
2828

2929
1. Ensure you have `mix` installed locally
3030
1. Run `./your_program.sh` to run your Redis server, which is implemented in
31-
`lib/server.ex`.
31+
`lib/main.ex`.
3232
1. Commit your changes and run `git push origin master` to submit your solution
3333
to CodeCrafters. Test output will be streamed to your terminal.

compiled_starters/elixir/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Elixir version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: elixir-1.16
11-
language_pack: elixir-1.16
10+
# Available versions: elixir-1.18
11+
language_pack: elixir-1.18

compiled_starters/elixir/lib/server.ex renamed to compiled_starters/elixir/lib/main.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Server do
22
@moduledoc """
33
Your implementation of a Redis server
44
"""
5-
5+
66
use Application
77

88
def start(_type, _args) do
@@ -24,3 +24,13 @@ defmodule Server do
2424
# {:ok, _client} = :gen_tcp.accept(socket)
2525
end
2626
end
27+
28+
defmodule CLI do
29+
def main(_args) do
30+
# Start the Server application
31+
{:ok, _pid} = Application.ensure_all_started(:codecrafters_redis)
32+
33+
# Run forever
34+
Process.sleep(:infinity)
35+
end
36+
end

compiled_starters/elixir/mix.exs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ defmodule App.MixProject do
44

55
def project do
66
[
7-
app: :redis,
7+
app: :codecrafters_redis,
88
version: "1.0.0",
9-
elixir: "~> 1.10",
10-
start_permanent: Mix.env() == :prod
9+
elixir: "~> 1.18",
10+
start_permanent: Mix.env() == :prod,
11+
deps: deps(),
12+
escript: [main_module: CLI]
1113
]
1214
end
1315

16+
# Run "mix help compile.app" to learn about applications.
1417
def application do
1518
[
1619
extra_applications: [:logger],
1720
mod: {Server, []}
1821
]
1922
end
23+
24+
# Run "mix help deps" to learn about dependencies.
25+
defp deps do
26+
[
27+
# {:dep_from_hexpm, "~> 0.3.0"},
28+
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
29+
]
30+
end
2031
end

compiled_starters/elixir/your_program.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@
88

99
set -e # Exit early if any commands fail
1010

11+
# Copied from .codecrafters/compile.sh
12+
#
13+
# - Edit this to change how your program compiles locally
14+
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
15+
(
16+
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17+
mix escript.build
18+
mv codecrafters_redis /tmp/codecrafters-build-redis-elixir
19+
)
20+
1121
# Copied from .codecrafters/run.sh
1222
#
1323
# - Edit this to change how your program runs locally
1424
# - Edit .codecrafters/run.sh to change how your program runs remotely
15-
exec mix run --no-halt -- "$@"
25+
exec /tmp/codecrafters-build-redis-elixir "$@"

compiled_starters/rust/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ That's all!
2626

2727
Note: This section is for stages 2 and beyond.
2828

29-
1. Ensure you have `cargo (1.82)` installed locally
29+
1. Ensure you have `cargo (1.86)` installed locally
3030
1. Run `./your_program.sh` to run your Redis server, which is implemented in
3131
`src/main.rs`. This command compiles your Rust project, so it might be slow
3232
the first time you run it. Subsequent runs will be fast.

compiled_starters/rust/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Rust version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: rust-1.85
11-
language_pack: rust-1.85
10+
# Available versions: rust-1.86
11+
language_pack: rust-1.86

compiled_starters/typescript/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ That's all!
2626

2727
Note: This section is for stages 2 and beyond.
2828

29-
1. Ensure you have `bun (1.1)` installed locally
29+
1. Ensure you have `bun (1.2)` installed locally
3030
1. Run `./your_program.sh` to run your Redis server, which is implemented in
3131
`app/main.ts`.
3232
1. Commit your changes and run `git push origin master` to submit your solution

compiled_starters/typescript/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the TypeScript version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: bun-1.1
11-
language_pack: bun-1.1
10+
# Available versions: bun-1.2
11+
language_pack: bun-1.2

dockerfiles/bun-1.2.Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM oven/bun:1.2-alpine
3+
4+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb"
5+
6+
WORKDIR /app
7+
8+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
9+
COPY --exclude=.git --exclude=README.md . /app
10+
11+
# For reproducible builds.
12+
# This will install the exact versions of each package specified in the lockfile.
13+
# If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated.
14+
RUN bun install --frozen-lockfile
15+
16+
# If the node_modules directory exists, move it to /app-cached
17+
RUN mkdir -p /app-cached
18+
RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi

dockerfiles/elixir-1.18.Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM elixir:1.18.3-alpine
3+
4+
# Ensures the container is re-built if dependency files change
5+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="mix.exs"
6+
7+
WORKDIR /app
8+
9+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10+
COPY --exclude=.git --exclude=README.md . /app
11+
12+
# install hex + rebar
13+
RUN mix local.hex --force && \
14+
mix local.rebar --force
15+
16+
# install and compile mix dependencies
17+
RUN mix deps.get && \
18+
mix deps.compile
19+
20+
# Install & cache deps
21+
RUN .codecrafters/compile.sh
22+
23+
RUN mkdir -p /app-cached
24+
RUN if [ -d "/app/_build" ]; then mv /app/_build /app-cached; fi
25+
RUN if [ -d "/app/deps" ]; then mv /app/deps /app-cached; fi

dockerfiles/rust-1.86.Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM rust:1.86-bookworm
3+
4+
# Rebuild the container if these files change
5+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
6+
7+
WORKDIR /app
8+
9+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10+
COPY --exclude=.git --exclude=README.md . /app
11+
12+
# This runs cargo build
13+
RUN .codecrafters/compile.sh

solutions/elixir/01-jm1/code/.codecrafters/compile.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
set -e # Exit on failure
1010

11-
# (This file is empty since Elixir programs don't use a compile step)
11+
mix escript.build
12+
mv codecrafters_redis /tmp/codecrafters-build-redis-elixir

solutions/elixir/01-jm1/code/.codecrafters/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
set -e # Exit on failure
1010

11-
exec mix run --no-halt -- "$@"
11+
exec /tmp/codecrafters-build-redis-elixir "$@"

solutions/elixir/01-jm1/code/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Ignore the compiled binary
2+
/codecrafters_redis
3+
14
# The directory Mix will write compiled artifacts to.
25
/_build/
36

solutions/elixir/01-jm1/code/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ event loops, the Redis protocol and more.
1212

1313
# Passing the first stage
1414

15-
The entry point for your Redis implementation is in `lib/server.ex`. Study and
15+
The entry point for your Redis implementation is in `lib/main.ex`. Study and
1616
uncomment the relevant code, and push your changes to pass the first stage:
1717

1818
```sh
@@ -28,6 +28,6 @@ Note: This section is for stages 2 and beyond.
2828

2929
1. Ensure you have `mix` installed locally
3030
1. Run `./your_program.sh` to run your Redis server, which is implemented in
31-
`lib/server.ex`.
31+
`lib/main.ex`.
3232
1. Commit your changes and run `git push origin master` to submit your solution
3333
to CodeCrafters. Test output will be streamed to your terminal.

solutions/elixir/01-jm1/code/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Elixir version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: elixir-1.16
11-
language_pack: elixir-1.16
10+
# Available versions: elixir-1.18
11+
language_pack: elixir-1.18

solutions/elixir/01-jm1/code/lib/server.ex renamed to solutions/elixir/01-jm1/code/lib/main.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Server do
22
@moduledoc """
33
Your implementation of a Redis server
44
"""
5-
5+
66
use Application
77

88
def start(_type, _args) do
@@ -19,3 +19,13 @@ defmodule Server do
1919
{:ok, _client} = :gen_tcp.accept(socket)
2020
end
2121
end
22+
23+
defmodule CLI do
24+
def main(_args) do
25+
# Start the Server application
26+
{:ok, _pid} = Application.ensure_all_started(:codecrafters_redis)
27+
28+
# Run forever
29+
Process.sleep(:infinity)
30+
end
31+
end

solutions/elixir/01-jm1/code/mix.exs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ defmodule App.MixProject do
44

55
def project do
66
[
7-
app: :redis,
7+
app: :codecrafters_redis,
88
version: "1.0.0",
9-
elixir: "~> 1.10",
10-
start_permanent: Mix.env() == :prod
9+
elixir: "~> 1.18",
10+
start_permanent: Mix.env() == :prod,
11+
deps: deps(),
12+
escript: [main_module: CLI]
1113
]
1214
end
1315

16+
# Run "mix help compile.app" to learn about applications.
1417
def application do
1518
[
1619
extra_applications: [:logger],
1720
mod: {Server, []}
1821
]
1922
end
23+
24+
# Run "mix help deps" to learn about dependencies.
25+
defp deps do
26+
[
27+
# {:dep_from_hexpm, "~> 0.3.0"},
28+
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
29+
]
30+
end
2031
end

solutions/elixir/01-jm1/code/your_program.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@
88

99
set -e # Exit early if any commands fail
1010

11+
# Copied from .codecrafters/compile.sh
12+
#
13+
# - Edit this to change how your program compiles locally
14+
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
15+
(
16+
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17+
mix escript.build
18+
mv codecrafters_redis /tmp/codecrafters-build-redis-elixir
19+
)
20+
1121
# Copied from .codecrafters/run.sh
1222
#
1323
# - Edit this to change how your program runs locally
1424
# - Edit .codecrafters/run.sh to change how your program runs remotely
15-
exec mix run --no-halt -- "$@"
25+
exec /tmp/codecrafters-build-redis-elixir "$@"

solutions/elixir/01-jm1/diff/lib/server.ex.diff renamed to solutions/elixir/01-jm1/diff/lib/main.ex.diff

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
@@ -1,26 +1,21 @@
1+
@@ -1,36 +1,31 @@
22
defmodule Server do
33
@moduledoc """
44
Your implementation of a Redis server
55
"""
6-
6+
77
use Application
88

99
def start(_type, _args) do
@@ -29,3 +29,14 @@
2929
+ {:ok, _client} = :gen_tcp.accept(socket)
3030
end
3131
end
32+
33+
defmodule CLI do
34+
def main(_args) do
35+
# Start the Server application
36+
{:ok, _pid} = Application.ensure_all_started(:codecrafters_redis)
37+
38+
# Run forever
39+
Process.sleep(:infinity)
40+
end
41+
end
42+
\ No newline at end of file

solutions/elixir/01-jm1/explanation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The entry point for your Redis implementation is in `lib/server.ex`.
1+
The entry point for your Redis implementation is in `lib/main.ex`.
22

33
Study and uncomment the relevant code:
44

solutions/rust/01-jm1/code/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ That's all!
2626

2727
Note: This section is for stages 2 and beyond.
2828

29-
1. Ensure you have `cargo (1.82)` installed locally
29+
1. Ensure you have `cargo (1.86)` installed locally
3030
1. Run `./your_program.sh` to run your Redis server, which is implemented in
3131
`src/main.rs`. This command compiles your Rust project, so it might be slow
3232
the first time you run it. Subsequent runs will be fast.

solutions/rust/01-jm1/code/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Rust version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: rust-1.85
11-
language_pack: rust-1.85
10+
# Available versions: rust-1.86
11+
language_pack: rust-1.86

solutions/rust/02-rg2/code/codecrafters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ debug: false
77
# Use this to change the Rust version used to run your code
88
# on Codecrafters.
99
#
10-
# Available versions: rust-1.85
11-
language_pack: rust-1.85
10+
# Available versions: rust-1.86
11+
language_pack: rust-1.86

0 commit comments

Comments
 (0)