Skip to content

Commit 3534455

Browse files
committed
feat: add cargo-make script(s) & formatting tools
1 parent 3e7a70f commit 3534455

File tree

11 files changed

+544
-0
lines changed

11 files changed

+544
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/target
22
bob.iml
33
report.json
4+
.idea/
5+
_*/
6+
_*

.rustfmt.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
edition = "2024"
2+
newline_style = "Unix"
3+
4+
max_width = 110
5+
6+
fn_params_layout = "Tall"
7+
fn_call_width = 100
8+
9+
force_multiline_blocks = true
10+
group_imports = "StdExternalCrate"
11+
12+
imports_granularity = "Module"
13+
imports_layout = "HorizontalVertical"
14+
normalize_doc_attributes = true
15+
reorder_impl_items = true
16+
reorder_modules = true
17+
18+
struct_field_align_threshold = 100
19+
20+
#tab_spaces = 2
21+
#reorder_imports = true
22+
#line_width = 120

.taplo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include = ["**/*.toml"]
2+
#exclude = []
3+
4+
#[formatting]
5+
6+
[[rule]]
7+
include = ["**/Cargo.toml", ".taplo.toml", "Cargo.toml"]
8+
9+
[rule.formatting]
10+
align_entries = true
11+
align_comments = true
12+
array_trailing_comma = true
13+
column_width = 100 # Try and keep this in sync with rustfmt's max_width, or roughly so
14+
inline_table_expand = false

Makefile.toml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
extend = [
2+
{ path = "./build/common-tasks.toml" },
3+
{ path = "./build/dist-tasks.toml" },
4+
{ path = "./build/docker-tasks.toml", optional = true },
5+
{ path = "./build/watch-tasks.toml", optional = true },
6+
]
7+
8+
# Name of output if/when calling dist tasks, should match the cargo bin output
9+
env.PROJECT_NAME = "bob" # "cargo_output_binary_name_for_PROJECT_NAME"
10+
# Default profile to use for builds during dist related tasks
11+
env.SLEEP_TIME = "15"
12+
13+
# Identifies the first argument passed after `cargo` as, or inplace of `build`.
14+
# ie: `cargo build <...zyx...>` vs. `cargo zigbuild <...xyz...>`
15+
env.BUILD_ARG = "build"
16+
# env.BUILD_ARG = "zigbuild"
17+
18+
## START Full sweeps/aliases
19+
[tasks.b]
20+
run_task = { name = ["build"], parallel = false }
21+
22+
[tasks.br]
23+
run_task = { name = ["build_release"], parallel = false }
24+
25+
[tasks.a]
26+
run_task = { name = [
27+
"build_workspace",
28+
"build",
29+
"test",
30+
"build_release_workspace",
31+
"build_release",
32+
"test_all",
33+
], parallel = false }
34+
35+
[tasks.r]
36+
run_task = { name = ["run"], parallel = false }
37+
38+
[tasks.rr]
39+
run_task = { name = ["run_release"], parallel = false }
40+
41+
[tasks.bw]
42+
run_task = { name = ["build_workspace"], parallel = false }
43+
44+
[tasks.brw]
45+
run_task = { name = ["build_release_workspace"], parallel = false }
46+
47+
[tasks.t]
48+
run_task = { name = ["test"], parallel = false }
49+
50+
[tasks.ta]
51+
run_task = { name = ["test_all"], parallel = false }
52+
53+
[tasks.tnc]
54+
run_task = { name = ["test_no_capture"], parallel = false }
55+
56+
[tasks.tanc]
57+
run_task = { name = ["test_all_no_capture"], parallel = false }
58+
59+
[tasks.f]
60+
run_task = { name = ["format"], parallel = false }
61+
62+
[tasks.c]
63+
run_task = { name = ["check"], parallel = false }
64+
65+
[tasks.cp]
66+
run_task = { name = ["clippy"], parallel = false }
67+
68+
[tasks.cl]
69+
run_task = { name = ["clean"], parallel = false }
70+
71+
[tasks.reset]
72+
run_task = { name = ["clean", "a"], parallel = false }
73+
74+
[tasks.envs]
75+
run_task = { name = "print_all", parallel = false }
76+
77+
[tasks.up]
78+
run_task = { name = [
79+
"a",
80+
"docker_start",
81+
"sleep",
82+
"run_as_project",
83+
], parallel = false }
84+
85+
[tasks.down]
86+
run_task = { name = ["docker_stop"], parallel = false }
87+
88+
[tasks.dist]
89+
env.PROFILE = "release"
90+
run_task = { name = ["build_release_dist"], parallel = false }
91+
92+
# END Full sweeps/aliases

build/.build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# This is/can be used in the .github/workflows/draft.yml workflow
5+
# Though it's often easier to just do it directly in the yml unless
6+
# what you're needing is a fair bit more complicated
7+
8+
export ARTIFACT_NAME="REPLACE_NAME_HERE-$1"
9+
10+
# Build for the target
11+
cargo build --release --locked --target "$1"
12+
13+
mkdir -p "$ARTIFACT_NAME"
14+
# Create the artifact
15+
cp "target/$1/release/REPLACE_NAME_HERE" "$ARTIFACT_NAME"
16+
cp "README.md" "LICENSE-APACHE" "LICENSE-MIT" "$ARTIFACT_NAME"
17+
18+
# Zip the artifact
19+
if ! command -v zip &>/dev/null; then
20+
sudo apt-get update && sudo apt-get install -yq zip
21+
fi
22+
# Zips the items without including the folder itself in the resulting archive
23+
cd $ARTIFACT_NAME
24+
zip -r "../$ARTIFACT_NAME.zip" *
25+
cd ..

build/common-tasks.toml

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
[env]
2+
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
3+
CARGO_MAKE_TIME_SUMMARY = true
4+
BREAKER = "----------------------------------------"
5+
6+
# ROOT = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}"
7+
ROOT = "."
8+
9+
# Platform specific file extensions, can use specifics for
10+
# build/dist taks that call linux.(args|command) vs windows.(args|command)
11+
# WINDOWS_EXTENSION = ".exe"
12+
# LINUX_EXTENSION = ""
13+
# MACOS_EXTENSION = ""
14+
15+
# BIN_EXTENSION = "${LINUX_EXTENSION}"
16+
17+
# Using a 'decode-mapping' to set the correct extension
18+
BIN_EXTENSION = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "", mapping = { "linux" = "", "macos" = "", "windows" = ".exe", "openbsd" = "" } }
19+
20+
## This isn't needed anyway
21+
# PROFILE = "${CARGO_MAKE_CARGO_PROFILE}"
22+
PROFILE = "release"
23+
VERSION = "${CARGO_MAKE_PROJECT_VERSION}"
24+
# Name of the output binary
25+
BIN_NAME = "${PROJECT_NAME}"
26+
# The formatted name of the output binary we want
27+
OUTPUT_BIN_NAME = "${BIN_NAME}_${VERSION}"
28+
# The folder where the binary will be copied to -- /_output_bin_name_dist
29+
DIST_FOLDER = "${ROOT}/_${OUTPUT_BIN_NAME}_dist"
30+
# the FULL path from root WITH EXE - root / target /current_profile / the_bin_name.EXE
31+
FOLDER_BIN_EXE = "${ROOT}/target/${PROFILE}/${BIN_NAME}${BIN_EXTENSION}"
32+
33+
# If you're running on an older Windows, or a builder (workflows etc.)
34+
# You may want to change this to "powershell.exe" or "powershell"
35+
# I have not tested with the older versions personally- all commands are
36+
# powershell/pwsh compatible afik
37+
#
38+
# NOTE: cmd.exe is NOT supported as the commands use CMDlets for zipping, moving, etc.
39+
#
40+
WINDOWS_SHELL = "pwsh.exe"
41+
42+
VARS = { script = ['''
43+
echo ""ROOT: ${ROOT}
44+
echo "PROFILE: ${PROFILE}"
45+
echo "VERSION: ${VERSION}"
46+
echo "BIN_NAME: ${BIN_NAME}"
47+
echo "OUTPUT_BIN_NAME: ${OUTPUT_BIN_NAME}"
48+
echo "DIST_FOLDER: ${DIST_FOLDER}"
49+
echo "FOLDER_BIN_EXE: ${FOLDER_BIN_EXE}"
50+
echo "BREAKER: ${BREAKER}"
51+
'''], multi_line = true }
52+
53+
# Sanity command to dump out all the variables
54+
# Also serves as a way to see variable interp in multiline scripts (it's odd)
55+
[tasks.print_all]
56+
script_runner = "@duckscript"
57+
script = '''
58+
echo "BREAKER: ${BREAKER}"
59+
echo ""ROOT: ${ROOT}
60+
echo "PROFILE: ${PROFILE}"
61+
echo "VERSION: ${VERSION}"
62+
echo "BIN_NAME: ${BIN_NAME}"
63+
echo "OUTPUT_BIN_NAME: ${OUTPUT_BIN_NAME}"
64+
echo "DIST_FOLDER: ${DIST_FOLDER}"
65+
echo "FOLDER_BIN_EXE: ${FOLDER_BIN_EXE}"
66+
echo "BREAKER: ${BREAKER}"
67+
'''
68+
69+
# START Core bare. min
70+
[tasks.format]
71+
command = "cargo"
72+
args = ["fmt", "--", "--emit=files"]
73+
dependencies = ["_taplo_format"]
74+
75+
[tasks.clean]
76+
command = "cargo"
77+
args = ["clean"]
78+
79+
[tasks.build]
80+
command = "cargo"
81+
args = ["${BUILD_ARG}", "${@}"]
82+
dependencies = ["format"]
83+
84+
[tasks.build_release]
85+
command = "cargo"
86+
args = ["${BUILD_ARG}", "--release", "${@}"]
87+
dependencies = ["format"]
88+
89+
[tasks.docs]
90+
command = "cargo"
91+
args = ["doc", "--no-deps", "${@}"]
92+
93+
[tasks.check]
94+
command = "cargo"
95+
args = ["check", "--all-targets", "--color", "always", "${@}"]
96+
97+
[tasks.clippy]
98+
command = "cargo"
99+
args = [
100+
"clippy",
101+
"--all-targets",
102+
"--color",
103+
"always",
104+
"--",
105+
"-W",
106+
"clippy::pedantic",
107+
]
108+
# END Core bare. min
109+
110+
# START Tests
111+
[tasks.test]
112+
command = "cargo"
113+
args = ["test", "${@}"]
114+
115+
[tasks.test_all]
116+
command = "cargo"
117+
args = ["test", "--all", "${@}"]
118+
119+
[tasks.test_no_capture]
120+
command = "cargo"
121+
args = ["test", "${@}", "--", "--nocapture"]
122+
123+
[tasks.test_all_no_capture]
124+
command = "cargo"
125+
args = ["test", "--all", "${@}", "--", "--nocapture"]
126+
# END Tests
127+
128+
# START Function outputs
129+
[tasks.run]
130+
command = "cargo"
131+
# We also capture anything after the main command
132+
args = ["run", "${@}"]
133+
134+
[tasks.run_release]
135+
command = "cargo"
136+
args = ["run", "--release", "${@}"]
137+
138+
[tasks.run_as_project]
139+
command = "cargo"
140+
args = ["run", " --bin", "${PROJECT_NAME}", "${@}"]
141+
142+
# END Function outputs
143+
144+
# START Workspaces
145+
[tasks.build_workspace]
146+
command = "cargo"
147+
args = ["${BUILD_ARG}", "--workspace", "${@}"]
148+
dependencies = ["format"]
149+
150+
[tasks.build_release_workspace]
151+
command = "cargo"
152+
args = ["${BUILD_ARG}", "--release", "--workspace", "${@}"]
153+
dependencies = ["format"]
154+
155+
[tasks.test_workspace]
156+
command = "cargo"
157+
args = ["test", "--workspace", "${@}"]
158+
# END Workspaces
159+
160+
[tasks.sleep]
161+
linux.command = "sleep"
162+
linux.args = ["${SLEEP_TIME}"]
163+
windows.command = "${WINDOWS_SHELL}"
164+
windows.args = ["-Command", "Start-Sleep", "-Seconds", "${SLEEP_TIME}"]
165+
166+
## START Misc tasks
167+
168+
# START Taplo (TOML Formmater) tasks
169+
[tasks.taplo_lint]
170+
command = "taplo"
171+
args = ["lint"]
172+
173+
[tasks._taplo_format]
174+
command = "taplo"
175+
args = ["format"]
176+
177+
[tasks._taplo_format_force]
178+
command = "taplo"
179+
args = ["format", "--force"]
180+
# END Taplo (TOML Formmater) tasks
181+
182+
## END Misc tasks

0 commit comments

Comments
 (0)