Skip to content

Commit

Permalink
add swift
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Jan 19, 2024
1 parent fae1f8d commit fae1bd7
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 44 deletions.
72 changes: 37 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,43 @@ jobs:
matrix:
# do the slow ones first, to make the overall build quicker
build:
# - 00_tcl
- 01_prolog
- 02_smalltalk
- 03_python3
- 04_julia
- 05_perl
- 06_cobol
- 07_haskell
- 08_ruby
- 09_forth
- 10_lua
- 11_ocaml
- 12_php
- 13_erlang
- 14_crystal
- 15_scala
- 16_csharp
- 17_coffeescript
- 18_kotlin
- 19_java
- 20_deno
- 21_node
- 22_go
- 23_bun
- 24_fortran
- 25_rust
- 26_vala
- 27_cpp-clang
- 28_cpp-gcc
- 29_c-clang
- 30_c-gcc
- 31_nim
- 32_pascal
- 33_zig
- 34_assembly
# - tcl
- prolog
- smalltalk
- python3
- julia
- perl
- swift
- cobol
- ruby
- haskell
- forth
- lua
- ocaml
- php
- erlang
- crystal
- scala
- csharp
- coffeescript
- kotlin
- java
- deno
- node
- go
- bun
- fortran
- rust
- swiftc
- vala
- cpp-clang
- cpp-gcc
- c-clang
- c-gcc
- nim
- pascal
- zig
- assembly
runs-on: ubuntu-latest
container:
image: acheronfail/count
Expand Down
7 changes: 7 additions & 0 deletions count.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var i = 0
let target = Int(CommandLine.arguments[1])!
while i < target {
i = (i + 1) | 1;
}

print("\(i)")
13 changes: 6 additions & 7 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN curl -fSL \
https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh \
| bash
RUN cargo install ripgrep --features pcre2
RUN cargo binstall --no-confirm hyperfine just timers juliaup
RUN cargo binstall --no-confirm hyperfine just max_rss juliaup

RUN juliaup add release && juliaup config versionsdbupdateinterval 0

Expand All @@ -53,13 +53,12 @@ RUN curl -fSL https://crystal-lang.org/install.sh | bash -s -- --version=1.11
RUN curl -fSL https://nim-lang.org/choosenim/init.sh | sh -s -- -y
ENV PATH="/root/.nimble/bin:$PATH"

RUN cd && curl -fSL "$(curl -fSL https://ziglang.org/download/index.json | jq -r '.[keys_unsorted[1]]["x86_64-linux"].tarball')" \
> zig.tar.xz \
&& mkdir -p "/root/.zig" \
&& tar -xvf zig.tar.xz --strip-components=1 -C "/root/.zig" \
&& rm zig.tar.xz
COPY ./zig.sh ./zig.sh
RUN ./zig.sh
ENV PATH="/root/.zig:$PATH"

RUN cargo install max_rss --version 0.4.1
COPY ./swift.sh ./swift.sh
RUN ./swift.sh
ENV PATH="/root/.swift/usr/bin:$PATH"

WORKDIR /var/count
24 changes: 24 additions & 0 deletions docker/swift.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# https://www.swift.org/install/linux/#installation-via-tarball

set -euxo pipefail
cd "$HOME"

install_dir="$HOME/.swift"

tarball_url="https://download.swift.org/swift-5.9.2-release/ubuntu2204/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-ubuntu22.04.tar.gz"
tarball_sig_url="${tarball_url}.sig"

tarball="swift.tar.gz"
tarball_sig="swift.tar.gz.sig"

wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -

curl -fSL "$tarball_url" > "$tarball"
curl -fSL "$tarball_sig_url" > "$tarball_sig"
gpg --verify "$tarball_sig"

mkdir -p "$install_dir"
tar -xvf "$tarball" --strip-components=1 -C "$install_dir"
rm "$tarball"
15 changes: 15 additions & 0 deletions docker/zig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euxo pipefail
cd "$HOME"

install_dir="$HOME/.zig"
jq_path='.[keys_unsorted[1]]["x86_64-linux"].tarball'
tarball_url=$(curl -fSL https://ziglang.org/download/index.json | jq -r "$jq_path")
tarball="zig.tar.xz"

curl -fSL "$tarball_url" > $tarball
mkdir -p "$install_dir"

tar -xvf $tarball --strip-components=1 -C "$install_dir"
rm $tarball
14 changes: 12 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ docker-sh:
# - mono fails to install (https://github.com/mono/mono/issues/21423)
# - running anything with erlang segfaults
docker-build:
docker build --progress=plain --platform 'linux/amd64' -t {{tag}} .
docker build --progress=plain --platform 'linux/amd64' -t {{tag}} ./docker

docker-pull:
docker pull {{tag}}
Expand Down Expand Up @@ -73,12 +73,13 @@ measure what:
python
ruby
smalltalk
swift
tcl
)
args="--warmup 3"
for language in "${slow_langs[@]}"; do
if [[ "{{what}}" == *"$language"* ]]; then
if [[ "{{what}}" == "$language" ]]; then
args="--runs 1"
break
fi
Expand Down Expand Up @@ -329,3 +330,12 @@ build-vala: (_check "valac") && (_size "count")
valac --version > VERSION
valac ./count.vala -o count --Xcc=-O3
echo './count {{i}}' > CMD

build-swift: (_check "swift")
swift --version > VERSION
echo 'swift ./count.swift {{i}}' > CMD

build-swiftc: (_check "swiftc") && (_size "count")
swiftc --version > VERSION
swiftc ./count.swift -o count -O
echo './count {{i}}' > CMD

0 comments on commit fae1bd7

Please sign in to comment.