Skip to content

Commit 621bf01

Browse files
authored
Merge pull request #35 from zzjin/dev_server_rust
feat: enhance server-rust release workflow and build process for mult…
2 parents 99b14cd + 5a6f909 commit 621bf01

File tree

3 files changed

+80
-12
lines changed

3 files changed

+80
-12
lines changed

.github/workflows/server-rust-release.yml

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ jobs:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: write
14+
env:
15+
SERVER_RUST_TARGETS: x86_64-unknown-linux-musl aarch64-unknown-linux-musl
1416
steps:
1517
- name: Checkout
1618
uses: actions/checkout@v4
1719
with:
1820
fetch-depth: 0
1921

22+
- name: Cache cargo artifacts
23+
uses: actions/cache@v4
24+
with:
25+
path: |
26+
~/.cargo/registry
27+
~/.cargo/git
28+
packages/server-rust/target
29+
key: ${{ runner.os }}-server-rust-${{ hashFiles('packages/server-rust/Cargo.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-server-rust-
32+
2033
- name: Install nightly toolchain
2134
uses: dtolnay/rust-toolchain@master
2235
with:
@@ -36,9 +49,37 @@ jobs:
3649
fi
3750
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
3851
39-
- name: Build release binary
52+
- name: Build release binaries
4053
working-directory: packages/server-rust
41-
run: make build
54+
run: |
55+
for TARGET in $SERVER_RUST_TARGETS; do
56+
make build TARGET=$TARGET
57+
done
58+
59+
- name: Prepare release artifacts
60+
run: |
61+
mkdir -p packages/server-rust/dist
62+
for TARGET in $SERVER_RUST_TARGETS; do
63+
SRC="packages/server-rust/target/$TARGET/release/devbox-sdk-server"
64+
case "$TARGET" in
65+
x86_64-unknown-linux-musl)
66+
DEST_NAME=devbox-sdk-server-linux-amd64
67+
;;
68+
aarch64-unknown-linux-musl)
69+
DEST_NAME=devbox-sdk-server-linux-arm64
70+
;;
71+
*)
72+
DEST_NAME=devbox-sdk-server-$TARGET
73+
;;
74+
esac
75+
DEST="packages/server-rust/dist/$DEST_NAME"
76+
if [ ! -f "$SRC" ]; then
77+
echo "Expected binary not found at $SRC" >&2
78+
exit 1
79+
fi
80+
cp "$SRC" "$DEST"
81+
chmod +x "$DEST"
82+
done
4283
4384
- name: Generate release notes
4485
id: notes
@@ -49,7 +90,11 @@ jobs:
4990
echo "## devbox-sdk-server v$VERSION"
5091
echo ""
5192
echo "- Commit: $SHA"
52-
echo "- Target: x86_64-unknown-linux-musl"
93+
echo ""
94+
echo "### Targets"
95+
for TARGET in $SERVER_RUST_TARGETS; do
96+
echo "- $TARGET"
97+
done
5398
echo ""
5499
echo "### Changes"
55100
git log -20 --pretty=format:'- %h %s'
@@ -65,5 +110,7 @@ jobs:
65110
tag_name: devbox-sdk-server-v${{ steps.crate.outputs.version }}
66111
name: devbox-sdk-server v${{ steps.crate.outputs.version }}
67112
body_path: release-notes.md
68-
files: packages/server-rust/target/x86_64-unknown-linux-musl/release/devbox-sdk-server
113+
files: |
114+
packages/server-rust/dist/devbox-sdk-server-linux-amd64
115+
packages/server-rust/dist/devbox-sdk-server-linux-arm64
69116
fail_on_unmatched_files: true

packages/server-rust/Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
# DevBox Server Rust Makefile
22

3-
BINARY_NAME=server-rust
4-
BUILD_DIR=./target/x86_64-unknown-linux-musl/release
3+
BINARY_NAME=devbox-sdk-server
4+
TARGET ?= x86_64-unknown-linux-musl
5+
SUPPORTED_TARGETS = x86_64-unknown-linux-musl aarch64-unknown-linux-musl
6+
BUILD_DIR=./target/$(TARGET)/release
57
MAIN_PATH=./src/main.rs
68

79
# Default to release build
810
BUILD_FLAGS=--release
911

10-
.PHONY: help build run test fmt check clean clippy
12+
.PHONY: help build build-all run test fmt check clean clippy
1113

1214
all: build
1315

1416
help: ## Show available commands
1517
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-14s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
1618

17-
build: ## Build release binary
18-
@cargo cross build --toolchain nightly --build-std -Z build-std-features="optimize_for_size" --release --target x86_64-unknown-linux-musl
19+
build: ## Build release binary (override TARGET=<triple> for other arches)
20+
@echo "Building target $(TARGET)"
21+
@cargo cross build --toolchain nightly --build-std -Z build-std-features="optimize_for_size" --release --target $(TARGET)
1922
@echo "Binary: $(BUILD_DIR)/$(BINARY_NAME)"
2023

24+
build-all: ## Build release binaries for all supported targets
25+
@for target in $(SUPPORTED_TARGETS); do \
26+
$(MAKE) build TARGET=$$target; \
27+
done
28+
2129
build-release-upx: build ## Build release binary and compress with UPX
2230
@upx --best --lzma $(BUILD_DIR)/$(BINARY_NAME)
2331
@echo "Compressed Binary: $(BUILD_DIR)/$(BINARY_NAME)"

packages/server-rust/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ packages/server-rust/
8383

8484
2. **Build an optimized release binary**:
8585
```bash
86-
make build
87-
# Binary will be created at: ./target/x86_64-unknown-linux-musl/release/server-rust
86+
make build # defaults to TARGET=x86_64-unknown-linux-musl
87+
make build TARGET=aarch64-unknown-linux-musl
88+
# Binary will be created at: ./target/<target>/release/devbox-sdk-server
89+
# Build both release binaries at once: make build-all
8890
```
8991

9092
3. **Build with UPX compression** (optional, requires UPX):
@@ -97,9 +99,20 @@ packages/server-rust/
9799
```bash
98100
make run
99101
# Or using the built binary:
100-
./target/release/server-rust
102+
./target/<target>/release/devbox-sdk-server
101103
```
102104

105+
### Multi-architecture builds
106+
107+
Cross-compilation is handled through `cargo cross`. Use the `TARGET` variable (defaults to `x86_64-unknown-linux-musl`) to select an architecture:
108+
109+
| TARGET | Platform | Output binary |
110+
|--------|----------|----------------|
111+
| `x86_64-unknown-linux-musl` | Linux x86_64 (glibc-compatible, fully static) | `./target/x86_64-unknown-linux-musl/release/devbox-sdk-server` |
112+
| `aarch64-unknown-linux-musl` | Linux ARM64 (fully static) | `./target/aarch64-unknown-linux-musl/release/devbox-sdk-server` |
113+
114+
Run `make build TARGET=<triple>` to produce a single binary or `make build-all` to generate both release artifacts in one pass.
115+
103116
### Binary Size Optimizations
104117
The release build is heavily optimized for size:
105118
- **LTO**: Fat link-time optimization (`lto = "fat"`)

0 commit comments

Comments
 (0)