Skip to content

Commit 3a95df4

Browse files
authored
Add CLI build workflow (etro-js#274)
1 parent b03068d commit 3a95df4

File tree

9 files changed

+245
-1
lines changed

9 files changed

+245
-1
lines changed

.github/workflows/build-cli.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build CLI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build_aarch64_apple_darwin:
11+
runs-on: macos-latest
12+
name: Build aarch64-apple-darwin target
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Install Rust
16+
run: rustup toolchain install stable
17+
- name: Run Build Script
18+
run: |
19+
cd crates/web5_cli/build/aarch64_apple_darwin
20+
./build
21+
- name: Upload executable
22+
uses: actions/upload-artifact@v3
23+
with:
24+
name: web5-aarch64-apple-darwin
25+
path: target/aarch64-apple-darwin/release/web5_cli
26+
27+
build_x86_64_apple_darwin:
28+
runs-on: macos-12
29+
name: Build x86_64-apple-darwin target
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Install Rust
33+
run: rustup toolchain install stable
34+
- name: Run Build Script
35+
run: |
36+
cd crates/web5_cli/build/x86_64_apple_darwin
37+
./build
38+
- name: Upload executable
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: web5-x86_64-apple-darwin
42+
path: target/x86_64-apple-darwin/release/web5_cli
43+
44+
build_x86_64_unknown_linux_gnu:
45+
runs-on: ubuntu-latest
46+
name: Build x86_64-unknown-linux-gnu target
47+
steps:
48+
- uses: actions/checkout@v2
49+
- name: Run Build Script
50+
run: |
51+
cd crates/web5_cli/build/x86_64_unknown_linux_gnu
52+
./build
53+
- name: Upload executable
54+
uses: actions/upload-artifact@v3
55+
with:
56+
name: web5-x86_64-linux-gnu
57+
path: target/x86_64-unknown-linux-gnu/release/web5_cli
58+
59+
build_x86_64_unknown_linux_musl:
60+
runs-on: ubuntu-latest
61+
name: Build x86_64-unknown-linux-musl target
62+
steps:
63+
- uses: actions/checkout@v2
64+
- name: Run Build Script
65+
run: |
66+
cd crates/web5_cli/build/x86_64_unknown_linux_musl
67+
./build
68+
- name: Upload executable
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: web5-x86_64-linux-musl
72+
path: target/x86_64-unknown-linux-musl/release/web5_cli

crates/web5_cli/Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ clap = { version = "4.5.7", features = ["derive"] }
1212
serde_json = { workspace = true }
1313
web5 = { path = "../web5" }
1414
url = "2.5.2"
15-
uuid = { workspace = true }
15+
uuid = { workspace = true }
16+
17+
[dependencies.openssl]
18+
version = "0.10"
19+
optional = true
20+
features = ["vendored"]
21+
22+
[features]
23+
default = []
24+
x86_64_apple_darwin = ["openssl"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
REPO_DIR=../../../../
6+
7+
rustup target add aarch64-apple-darwin
8+
9+
(
10+
cd $REPO_DIR;
11+
cargo build --target aarch64-apple-darwin --release --package web5_cli;
12+
# located at: target/aarch64-apple-darwin/release/web5_cli
13+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
REPO_DIR=../../../../
6+
7+
rustup target add x86_64-apple-darwin
8+
9+
(
10+
cd $REPO_DIR;
11+
cargo build --target x86_64-apple-darwin --release \
12+
--package web5_cli \
13+
--features x86_64_apple_darwin;
14+
# located at target/x86_64-apple-darwin/release/web5_cli
15+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM --platform=linux/amd64 ubuntu:22.04
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
curl \
7+
build-essential \
8+
libssl-dev \
9+
pkg-config
10+
11+
# Install rust
12+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
13+
ENV PATH="/root/.cargo/bin:${PATH}"
14+
15+
# Copy the source code to the container
16+
WORKDIR /usr/src/myapp
17+
COPY Cargo.toml ./
18+
COPY bindings/web5_uniffi_wrapper ./bindings/web5_uniffi_wrapper
19+
COPY bindings/web5_uniffi ./bindings/web5_uniffi
20+
COPY crates/web5 ./crates/web5
21+
COPY crates/web5_cli ./crates/web5_cli
22+
23+
# Execute the build
24+
RUN cargo build --release --package web5_cli
25+
26+
# Set the entrypoint, so that we can `docker cp` the build output
27+
CMD tail -f /dev/null
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
REPO_DIR=../../../../
6+
IMAGE_NAME=web5_cli_x86_64-unknown-linux-gnu_image
7+
CONTAINER_NAME=web5_cli_x86_64-unknown-linux-gnu_container
8+
9+
docker build -f $(pwd)/Dockerfile -t $IMAGE_NAME $REPO_DIR
10+
11+
docker run -d --name $CONTAINER_NAME $IMAGE_NAME
12+
13+
TARGET_DIR=$REPO_DIR/target/x86_64-unknown-linux-gnu/release
14+
mkdir -p $TARGET_DIR
15+
16+
docker cp $CONTAINER_NAME:/usr/src/myapp/target/release/web5_cli $TARGET_DIR/web5_cli
17+
18+
docker stop $CONTAINER_NAME
19+
docker rm $CONTAINER_NAME
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM --platform=linux/amd64 alpine:latest
2+
3+
# Install system dependencies
4+
RUN apk add --no-cache \
5+
build-base \
6+
musl-dev \
7+
openssl-dev \
8+
linux-headers \
9+
rustup \
10+
libgcc \
11+
libstdc++ \
12+
curl \
13+
git \
14+
openssl-libs-static
15+
16+
# Install rust
17+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
18+
ENV PATH="/root/.cargo/bin:${PATH}"
19+
20+
# Copy the source code to the container
21+
WORKDIR /usr/src/myapp
22+
COPY Cargo.toml ./
23+
COPY bindings/web5_uniffi_wrapper ./bindings/web5_uniffi_wrapper
24+
COPY bindings/web5_uniffi ./bindings/web5_uniffi
25+
COPY crates/web5 ./crates/web5
26+
COPY crates/web5_cli ./crates/web5_cli
27+
28+
RUN cargo build --release --package web5_cli
29+
30+
# Set the entrypoint, so that we can `docker cp` the build output
31+
CMD tail -f /dev/null
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
REPO_DIR=../../../../
6+
IMAGE_NAME=web5_cli_x86_64-unknown-linux-musl_image
7+
CONTAINER_NAME=web5_cli_x86_64-unknown-linux-musl_container
8+
9+
docker build -f $(pwd)/Dockerfile -t $IMAGE_NAME $REPO_DIR
10+
11+
docker run -d --name $CONTAINER_NAME $IMAGE_NAME
12+
13+
TARGET_DIR=$REPO_DIR/target/x86_64-unknown-linux-musl/release
14+
mkdir -p $TARGET_DIR
15+
16+
docker cp $CONTAINER_NAME:/usr/src/myapp/target/release/web5_cli $TARGET_DIR/web5_cli
17+
18+
docker stop $CONTAINER_NAME
19+
docker rm $CONTAINER_NAME

crates/web5_cli/install.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
if [ -z "$1" ]; then
4+
echo "Usage: $0 <version>"
5+
exit 1
6+
fi
7+
8+
VERSION=$1
9+
OS=$(uname | tr '[:upper:]' '[:lower:]')
10+
ARCH=$(uname -m)
11+
12+
case $OS in
13+
"linux")
14+
case $ARCH in
15+
"x86_64") FILENAME="web5-x86_64-linux-gnu.zip" ;;
16+
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
17+
esac
18+
;;
19+
"darwin")
20+
case $ARCH in
21+
"x86_64") FILENAME="web5-x86_64-apple-darwin.zip" ;;
22+
"arm64") FILENAME="web5-aarch64-apple-darwin.zip" ;;
23+
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
24+
esac
25+
;;
26+
*)
27+
echo "Unsupported OS: $OS"; exit 1 ;;
28+
esac
29+
30+
# Download and unzip
31+
curl -L -o /tmp/$FILENAME https://github.com/TBD54566975/web5-rs/releases/download/$VERSION/$FILENAME
32+
unzip -o /tmp/$FILENAME -d /tmp
33+
34+
# Move the executable to /usr/local/bin and make it executable
35+
sudo mv /tmp/web5_cli /usr/local/bin/web5
36+
sudo chmod +x /usr/local/bin/web5
37+
38+
# Cleanup
39+
rm /tmp/$FILENAME

0 commit comments

Comments
 (0)