-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
130 lines (111 loc) · 3.75 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
PKG_TARGET=x86_64-unknown-linux-musl
PKG_TARGET_DARWIN=x86_64-apple-darwin
RUST_VERSION ?= $(shell rustc --version | cut -d ' ' -f2)
PKG_BIN_PATH=./bin
PKG_NAME=$(shell cat Cargo.toml | sed -n 's/name = "\([^}]*\)"/\1/p' | head -n1)
PKG_TAG=$(shell cat Cargo.toml | sed -n 's/version = "\([^}]*\)"/\1/p' | head -n1)
run:
@echo "Running application..."
@rustc -vV
@cargo run -- --help
.PHONY: run
build:
@echo "Building application..."
@rustc -vV
@cargo build --release --target x86_64-unknown-linux-musl
.PHONY: build
test:
@echo "Testing library..."
@rustc -vV
@cargo test --lib
.PHONY: test
fmt:
@echo "Fixing and formatting source files..."
@cargo fix --allow-dirty
@cargo fmt --all
.PHONY: fmt
docker.build:
@docker build -t joseluisq/paket:latest -f docker/alpine/Dockerfile .
.PHONY: docker.build
docker.run:
@docker run -it --rm joseluisq/paket:latest -h
.PHONY: docker.run
pipeline-prod:
@drone exec \
--trusted \
--privileged \
--event=tag \
--exclude=test \
--exclude=publish-linux-local \
--exclude=publish-linux-dockerhub \
--exclude=github-release \
--pipeline=production
.PHONY: pipeline-prod
#######################################
########## Production tasks ###########
#######################################
linux:
@docker run --rm -it \
-v $(PWD):/root/src/paket \
-v cargo-git:/root/.cargo/git \
-v cargo-registry:/root/.cargo/registry \
-v cargo-paket-target:/root/src/paket/target \
\
--workdir /root/src/paket \
joseluisq/rust-linux-darwin-builder:$(RUST_VERSION) \
\
bash -c "\
echo Building Linux release binary... && \
rustc -vV && \
cargo build --release --target $(PKG_TARGET) && \
du -sh ./target/$(PKG_TARGET)/release/$(PKG_NAME) && \
mkdir -p release && \
cp -rf ./target/$(PKG_TARGET)/release/$(PKG_NAME) release/$(PKG_NAME)-linux && \
echo \"Shrinking Linux binary file...\" && \
strip release/$(PKG_NAME)-linux && \
du -sh ./release/$(PKG_NAME)-linux"
.PHONY: linux
darwin:
@docker run --rm -it \
-v $(PWD):/root/src/paket \
-v cargo-git:/root/.cargo/git \
-v cargo-registry:/root/.cargo/registry \
-v cargo-paket-target:/root/src/paket/target \
\
--workdir /root/src/paket \
joseluisq/rust-linux-darwin-builder:$(RUST_VERSION) \
\
bash -c "\
echo Building Darwin release binary... && \
rustc -vV && \
cargo build --release --target $(PKG_TARGET_DARWIN) && \
du -sh ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) && \
mkdir -p release && \
cp -rf ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) release/$(PKG_NAME)-darwin && \
echo \"Shrinking Darwin binary file...\" && \
x86_64-apple-darwin20.2-strip release/$(PKG_NAME)-darwin && \
du -sh ./release/$(PKG_NAME)-darwin"
.PHONY: darwin
# Create a release build
prod.release.linux:
@rustc -vV
@echo "Compiling Linux release binary for $(PKG_TARGET)..."
@cargo build --release --target $(PKG_TARGET)
@du -sh ./target/$(PKG_TARGET)/release/$(PKG_NAME)
@echo "Shrinking Linux release binary..."
@strip ./target/$(PKG_TARGET)/release/$(PKG_NAME)
@du -sh ./target/$(PKG_TARGET)/release/$(PKG_NAME)
@mkdir -p $(PKG_BIN_PATH)/$(PKG_TARGET)/
@cp ./target/$(PKG_TARGET)/release/$(PKG_NAME) $(PKG_BIN_PATH)/$(PKG_TARGET)/
.PHONY: prod.release.linux
prod.release.darwin:
@rustc -vV
@echo "Compiling Darwin release binary for $(PKG_TARGET_DARWIN)..."
@cargo build --release --target $(PKG_TARGET_DARWIN)
@du -sh ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME)
@echo "Shrinking Darwin release binary..."
@x86_64-apple-darwin20.2-strip ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME)
@du -sh ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME)
@mkdir -p $(PKG_BIN_PATH)/$(PKG_TARGET_DARWIN)/
@cp ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) $(PKG_BIN_PATH)/$(PKG_TARGET_DARWIN)/
.PHONY: prod.release.darwin