Skip to content

Commit

Permalink
Allow building a server only binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Aug 7, 2024
1 parent 4b1710b commit 47ee225
Show file tree
Hide file tree
Showing 20 changed files with 651 additions and 569 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
override: true
components: rustfmt, clippy

- name: Build server-only binary
run: cargo build -p crusader --no-default-features
working-directory: src

- name: Build
run: cargo build
working-directory: src
Expand Down
4 changes: 2 additions & 2 deletions android/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
To build a statically linked server image:
```
docker build .. -t crusader -f server-static.Dockerfile --build-arg TARGET=x86_64-unknown-linux-musl --platform=linux/x86_64
docker build .. -t crusader -f server-static.Dockerfile
```

Some possible targets:
- `--build-arg TARGET=i686-unknown-linux-musl --platform=linux/i386`
- `--build-arg TARGET=x86_64-unknown-linux-musl --platform=linux/x86_64`
- `--build-arg TARGET=arm-unknown-linux-musleabihf --platform=linux/arm/v7`
- `--build-arg TARGET=aarch64-unknown-linux-musl --platform=linux/arm64`
Supported platforms:
- `linux/i386`
- `linux/x86_64`
- `linux/arm/v7`
- `linux/arm64`

Available profiles:
- `--build-arg PROFILE=release` (default)
Expand Down
29 changes: 18 additions & 11 deletions docker/server-static.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
ARG TARGET=x86_64-unknown-linux-musl
ARG PROFILE=release

FROM rust AS build
ARG PROFILE
ARG TARGET
ARG TARGETARCH
ARG PROFILE=release

COPY src /src
WORKDIR /src

RUN echo no-target-detected > /target

RUN if [ "$TARGETARCH" = "386" ]; then\
echo i686-unknown-linux-musl > /target; fi
RUN if [ "$TARGETARCH" = "amd64" ]; then\
echo x86_64-unknown-linux-musl > /target; fi
RUN if [ "$TARGETARCH" = "arm" ]; then\
echo arm-unknown-linux-musleabihf > /target; fi
RUN if [ "$TARGETARCH" = "arm64" ]; then\
echo aarch64-unknown-linux-musl > /target; fi

ENV RUSTFLAGS="-C target-feature=+crt-static"

RUN rustup target add $TARGET
RUN rustup target add $(cat /target)

RUN cargo build -p crusader --no-default-features --profile=$PROFILE --target $(cat /target)

RUN cargo fetch
RUN cargo build -p crusader --profile=$PROFILE --target $TARGET
RUN cp target/$(cat /target)/$PROFILE/crusader /

FROM scratch
ARG PROFILE
ARG TARGET
COPY --from=build /src/target/$TARGET/$PROFILE/crusader /crusader
COPY --from=build /crusader /

EXPOSE 35481/tcp 35481/udp
ENTRYPOINT [ "/crusader", "serve" ]
2 changes: 1 addition & 1 deletion src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ lto = "fat"

[profile.size]
inherits = "speed"
opt-level = "s"
opt-level = "z"
2 changes: 1 addition & 1 deletion src/crusader-gui-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
toml = "0.5.9"
serde = { version = "1.0.137", features = ["derive"] }
crusader-lib = { path = "../crusader-lib" }
crusader-lib = { path = "../crusader-lib", features = ["server", "client"] }
tokio = { version = "1.18.2", features = ["full"] }
eframe = "0.28.1"
egui_plot = "0.28.1"
Expand Down
4 changes: 2 additions & 2 deletions src/crusader-gui-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crusader_lib::{
latency,
plot::{self, float_max, to_rates},
protocol, serve,
test::{self, Config, PlotConfig},
with_time,
test::{self, PlotConfig},
with_time, Config,
};
use eframe::{
egui::{self, Grid, Id, ScrollArea, TextEdit, TextStyle, Ui, Vec2b},
Expand Down
12 changes: 8 additions & 4 deletions src/crusader-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
server = []
client = ["dep:plotters", "dep:axum", "dep:image", "dep:snap"]

[dependencies]
plotters = { version = "0.3.6", default-features = false, features = [
plotters = { version = "0.3.6", default-features = false, optional = true, features = [
"ab_glyph",
"bitmap_backend",
"line_series",
Expand All @@ -22,7 +26,7 @@ tokio = { version = "1.18.2", features = ["full"] }
tokio-util = { version = "0.7.2", features = ["codec"] }
futures = "0.3.21"
bytes = "1.1.0"
snap = "1.0.5"
snap = { version = "1.0.5", optional = true }
rmp-serde = "1.1.0"
socket2 = "0.4.6"
libc = "0.2"
Expand All @@ -31,5 +35,5 @@ axum = { version = "0.7.5", features = [
"ws",
"tokio",
"http1",
], default-features = false }
image = "0.24.9"
], default-features = false, optional = true }
image = { version = "0.24.9", optional = true }
Loading

0 comments on commit 47ee225

Please sign in to comment.