add makefile for static compilation
This commit is contained in:
parent
368e3b2b30
commit
602ff3595d
2
.cargo/config
Normal file
2
.cargo/config
Normal file
@ -0,0 +1,2 @@
|
||||
[target.aarch64-unknown-linux-musl]
|
||||
linker = "aarch64-linux-musl-gcc"
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
dist
|
||||
release
|
||||
|
@ -2,6 +2,7 @@ image: rust:1.59-alpine3.15
|
||||
|
||||
stages:
|
||||
- test
|
||||
- build
|
||||
|
||||
test:
|
||||
stage: test
|
||||
@ -15,4 +16,20 @@ audit:
|
||||
before_script:
|
||||
- apk --no-cache add musl-dev cargo-audit
|
||||
script:
|
||||
- cargo audit
|
||||
- cargo audit
|
||||
|
||||
build-statically:
|
||||
stage: build
|
||||
before_script:
|
||||
- apk --no-cache add musl-dev make
|
||||
- wget https://musl.cc/aarch64-linux-musl-cross.tgz
|
||||
- echo "c909817856d6ceda86aa510894fa3527eac7989f0ef6e87b5721c58737a06c38 aarch64-linux-musl-cross.tgz" | sha256sum -c - || exit 1
|
||||
- tar -zxvf aarch64-linux-musl-cross.tgz -C / --exclude='aarch64-linux-musl-cross/usr' --strip 1
|
||||
- wget https://musl.cc/x86_64-w64-mingw32-cross.tgz
|
||||
- echo "3a5c90309209a8b2e7ea1715a34b1029692e34189c5e7ecd77e1f102f82f6a02 x86_64-w64-mingw32-cross.tgz" | sha256sum -c - || exit 1
|
||||
- tar -zxvf x86_64-w64-mingw32-cross.tgz -C / --exclude='./x86_64-w64-mingw32-cross/usr' --strip 2
|
||||
- wget https://musl.cc/x86_64-linux-musl-cross.tgz
|
||||
- echo "c5d410d9f82a4f24c549fe5d24f988f85b2679b452413a9f7e5f7b956f2fe7ea x86_64-linux-musl-cross.tgz" | sha256sum -c - || exit 1
|
||||
- tar -zxvf x86_64-linux-musl-cross.tgz -C / --exclude='x86_64-linux-musl-cross/usr' --strip 1
|
||||
script:
|
||||
- make all
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -710,7 +710,6 @@ name = "http-client"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bank",
|
||||
"gloo-console",
|
||||
"http-lib",
|
||||
"js-sys",
|
||||
"serde",
|
||||
|
55
Makefile
Normal file
55
Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
LINUX_X86_64_MUSL_TARGET = x86_64-unknown-linux-musl
|
||||
LINUX_AARCH64_MUSL_TARGET = aarch64-unknown-linux-musl
|
||||
WINDOWS_GNU_TARGET = x86_64-pc-windows-gnu
|
||||
|
||||
x86_64-unknown-linux-musl_strip = strip
|
||||
aarch64-unknown-linux-musl_strip = aarch64-linux-musl-strip
|
||||
x86_64-pc-windows-gnu_strip = strip
|
||||
|
||||
BINARIES = socket-server http-server
|
||||
|
||||
RELEASE_DIR = release
|
||||
|
||||
.PHONY: audit clean test linux-x86_64-musl linux-aarch64-musl windows-gnu http-client $(RELEASE_DIR) all default
|
||||
|
||||
TARGETS = $(LINUX_X86_64_MUSL_TARGET) $(LINUX_AARCH64_MUSL_TARGET) $(WINDOWS_GNU_TARGET)
|
||||
|
||||
default: all
|
||||
all: linux-x86_64-musl linux-aarch64-musl windows-gnu http-client
|
||||
|
||||
define BUILDER
|
||||
target/$(TARGET)/release/%:
|
||||
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target $(TARGET) --package $$(basename $$(@F))
|
||||
$($(TARGET)_strip) $$@
|
||||
|
||||
$(RELEASE_DIR)/$(TARGET)/%: target/$(TARGET)/release/% $(RELEASE_DIR)
|
||||
mkdir -p $$(dir $$@)
|
||||
cp $$< $$@
|
||||
endef
|
||||
$(foreach TARGET,$(TARGETS),$(eval $(BUILDER)))
|
||||
|
||||
define BINARY_TARGETS
|
||||
linux-x86_64-musl: $(RELEASE_DIR)/$(LINUX_X86_64_MUSL_TARGET)/$(BINARY)
|
||||
linux-aarch64-musl: $(RELEASE_DIR)/$(LINUX_AARCH64_MUSL_TARGET)/$(BINARY)
|
||||
windows-gnu: $(RELEASE_DIR)/$(WINDOWS_GNU_TARGET)/$(BINARY).exe
|
||||
endef
|
||||
$(foreach BINARY,$(BINARIES),$(eval $(BINARY_TARGETS)))
|
||||
|
||||
http-client:
|
||||
cd http-client && trunk build --release
|
||||
rm -rf $(RELEASE_DIR)/$@
|
||||
mkdir -p $(RELEASE_DIR)/$@
|
||||
cp -r http-client/dist/* $(RELEASE_DIR)/$@
|
||||
|
||||
$(RELEASE_DIR):
|
||||
mkdir -p $(RELEASE_DIR)
|
||||
|
||||
test:
|
||||
cargo test
|
||||
|
||||
audit:
|
||||
cargo audit
|
||||
|
||||
clean:
|
||||
-rm -rf target $(RELEASE_DIR)
|
||||
|
21
README.md
21
README.md
@ -36,4 +36,23 @@ trunk serve
|
||||
Build for release (the built artifacts can be found in `dist`):
|
||||
```
|
||||
trunk build --release
|
||||
```
|
||||
```
|
||||
|
||||
# Releases
|
||||
Release binaries are built for multiple architectures (always statically compiled):
|
||||
|
||||
- x86_64-unknown-linux-musl (needs ``)
|
||||
- aarch64-unknown-linux-musl (needs `aarch64-linux-musl-gcc` and `aarch64-linux-musl-gcc`)
|
||||
- x86_64-pc-windows-gnu (needs `x86_64-w64-mingw32-gcc`)
|
||||
|
||||
These are the target triplet names as they are used by rustup (add them with `rustup target add $TARGET`).
|
||||
|
||||
To make it more convenient to build, a makefile is provided. Use the following targets for it:
|
||||
|
||||
- linux-x86_64-musl
|
||||
- linux-aarch64-musl
|
||||
- windows-gnu
|
||||
- http-client
|
||||
|
||||
The `default` and `all` targets build all of them. After a successful build, everything is copied into
|
||||
the `release` folder.
|
||||
|
@ -5,4 +5,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0.30"
|
||||
uuid = { version = "0.8.2", features = ["v4", "wasm-bindgen"] }
|
||||
uuid = { version = "0.8.2", features = ["v4", "wasm-bindgen"] }
|
||||
|
@ -6,7 +6,6 @@ edition = "2021"
|
||||
[dependencies]
|
||||
bank = { path = "../bank" }
|
||||
http-lib = { path = "../http-lib" }
|
||||
gloo-console = "0.2.1"
|
||||
js-sys = "0.3.56"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
serde_json = "1.0.79"
|
||||
|
@ -85,7 +85,7 @@ impl Component for Main {
|
||||
});
|
||||
false
|
||||
}
|
||||
Event::Transfer(amount, from, to) => false,
|
||||
Event::Transfer(_amount, _from, _to) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,4 +5,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bank = { path = "../bank" }
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
|
@ -14,4 +14,4 @@ pretty_env_logger = "0.4.0"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0.79"
|
||||
serde_json = "1.0.79"
|
||||
|
@ -68,7 +68,6 @@ async fn main() -> std::io::Result<()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::body::to_bytes;
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::http::{Method as HttpMethod, StatusCode};
|
||||
use actix_web::{test, App};
|
||||
use serde_json::Value;
|
||||
|
Loading…
Reference in New Issue
Block a user