1
+ set windows-shell := [" pwsh" , " -NoLogo" , " -NoProfileLoadTime" , " -Command" ]
2
+
3
+ MACH_VERSION := env_var_or_default (" MACH_VERSION" , " " )
4
+ profile := env_var_or_default (" profile" , " debug" )
5
+
6
+ os := \
7
+ if \
8
+ env_var_or_default (" os" , " " ) == " Windows_NT" { " windows" } \
9
+ else if \
10
+ env_var_or_default (" os" , " " ) != " " { env_var (" os" ) } \
11
+ else \
12
+ { os () }
13
+
14
+ arch := \
15
+ if \
16
+ env_var_or_default (" arch" , " " ) != " " { env_var (" arch" ) } \
17
+ else if \
18
+ arch () == " x86_64" { " amd64" } \
19
+ else if \
20
+ arch () == " aarch64" { " arm64" } \
21
+ else \
22
+ { arch () }
23
+
24
+ dylib := \
25
+ if \
26
+ os == " windows" { " dll" } \
27
+ else if \
28
+ os == " macos" { " dylib" } \
29
+ else if \
30
+ os == " linux" { " so" } \
31
+ else \
32
+ { os () }
33
+
34
+ target := \
35
+ if \
36
+ os + arch == " linuxamd64" { " x86_64-unknown-linux-gnu" } \
37
+ else if \
38
+ os + arch == " linuxarm64" { " aarch64-unknown-linux-gnu" } \
39
+ else if \
40
+ os + arch == " macosamd64" { " x86_64-apple-darwin" } \
41
+ else if \
42
+ os + arch == " macosarm64" { " aarch64-apple-darwin" } \
43
+ else if \
44
+ os + arch == " windowsamd64" { " x86_64-pc-windows-msvc" } \
45
+ else if \
46
+ os + arch == " windowsarm64" { " aarch64-pc-windows-msvc" } \
47
+ else \
48
+ { env_var_or_default (" target" , " debug" ) }
49
+
50
+ profile_cargo := \
51
+ if \
52
+ profile != " debug" { " --profile " + profile } \
53
+ else \
54
+ { " " }
55
+
56
+ target_cargo := \
57
+ if \
58
+ target == " debug" { " " } \
59
+ else if \
60
+ target == " " { " " } \
61
+ else \
62
+ { " --target " + target }
63
+
64
+ out_dir := join (justfile_directory (), " target" , os + " -" + arch , profile)
65
+ out_dir_link := join (justfile_directory (), " target" , profile)
66
+
67
+ _ default :
68
+ @ echo " Available Env:"
69
+ @ echo " profile"
70
+ @ echo " debug [default]"
71
+ @ echo " release"
72
+ @ echo " os"
73
+ @ echo " auto [default]"
74
+ @ echo " linux"
75
+ @ echo " macos"
76
+ @ echo " windows"
77
+ @ echo " arch"
78
+ @ echo " auto [default]"
79
+ @ echo " arm64"
80
+ @ echo " amd64"
81
+ @ just --list --unsorted
82
+
83
+ [unix ]
1
84
build :
2
- cargo build
85
+ # Install npm
86
+ test -d node_modules || npm install
87
+
88
+ # Build crates
89
+ cargo build {{ profile_cargo}} {{ target_cargo}}
90
+ @ cp " ./target/.cargo/{{ target}} /{{ profile}} /libmach_bundler_npm_os_arch.{{ dylib}} " " ./packages/mach_nodejs/index.node"
91
+
92
+ # Clean dir
93
+ @ rm -rf " {{ out_dir}} "
94
+ @ rm -rf " {{ out_dir_link}} "
95
+ @ mkdir -p " {{ out_dir}} "
96
+
97
+ # Copy binary
98
+ @ mkdir -p " {{ out_dir}} /bin"
99
+ @ cp " ./target/.cargo/{{ target}} /{{ profile}} /mach" " {{ out_dir}} /bin"
100
+
101
+ [windows ]
102
+ build :
103
+ # Install npm
104
+ if (!(Test-Path ' node_modules' )) { pnpm install }
105
+
106
+ # Build mach and napi
107
+ cargo build {{ profile_cargo}} {{ target_cargo}}
108
+ @ Copy-Item " .\t arget\. cargo\{ {target}}\{ {profile}}\m ach_bundler_npm_os_arch.{{ dylib}} " -Destination " .\n pm\m ach-os-arch\p latform\n ative\i ndex.node" | Out-Null
109
+
110
+ # Clean dir
111
+ @ if (Test-Path {{out_dir}}) { Remove-Item -Recurse -Force {{ out_dir}} | Out-Null }
112
+ @ if (Test-Path {{out_dir_link}}) { Remove-Item -Recurse -Force {{ out_dir_link}} | Out-Null }
113
+ @ New-Item -ItemType " directory" -Force -Path " {{ out_dir}} " | Out-Null
114
+
115
+ # Copy binary
116
+ @ New-Item -ItemType " directory" -Force -Path " {{ out_dir}} \b in" | Out-Null
117
+ @ Copy-Item " .\t arget\. cargo\{ {target}}\{ {profile}}\m ach.exe" -Destination " {{ out_dir}} \b in" | Out-Null
118
+
119
+ # Copy Nodejs adapter
120
+ @ New-Item -ItemType " directory" -Force -Path " {{ out_dir}} \n odejs" | Out-Null
121
+ @ Copy-Item " .\n pm\m ach-os-arch\c md" -Destination " {{ out_dir}} \n odejs" -Recurse | Out-Null
122
+ @ Copy-Item " .\n pm\m ach-os-arch\p latform" -Destination " {{ out_dir}} \n odejs" -Recurse | Out-Null
123
+ @ Copy-Item " .\n pm\m ach-os-arch\p ackage.json" -Destination " {{ out_dir}} \n odejs" -Recurse | Out-Null
124
+ @ New-Item -ItemType SymbolicLink -Path " {{ out_dir_link}} " -Target " {{ out_dir}} " | Out-Null
125
+
126
+ [unix ]
127
+ run * ARGS :
128
+ just build
129
+ {{ out_dir}} / bin/ mach {{ ARGS}}
130
+
131
+ [windows ]
132
+ run * ARGS :
133
+ just build
134
+ {{ out_dir}} / bin/ mach.exe {{ ARGS}}
135
+
136
+ [unix ]
137
+ example cmd fixture * ARGS :
138
+ @ just build
139
+ cd ./ examples/ {{ fixture}} && {{ out_dir}} / bin/ mach {{ cmd}} {{ ARGS}}
140
+
141
+ [windows ]
142
+ example cmd fixture * ARGS :
143
+ @ just build
144
+ cd ./ examples/ {{ fixture}} && {{ out_dir}} / bin/ mach.exe {{ cmd}} {{ ARGS}}
145
+
146
+ serve :
147
+ npx http-server -p 3000 ./ examples
148
+
149
+ integration-tests * ARGS :
150
+ node --import ./ testing/ node_modules/ tsx/ dist/ loader.mjs ./ testing/ setup.ts {{ ARGS}}
151
+
152
+ unit-tests :
153
+ cargo test
154
+
155
+ fmt :
156
+ cargo + nightly fmt
157
+ ./ .github/ scripts/ node_modules/ .bin/ prettier ./ npm --write
158
+ ./ .github/ scripts/ node_modules/ .bin/ prettier ./ examples --write
159
+ ./ .github/ scripts/ node_modules/ .bin/ prettier " ./testing/tests" --write
160
+ ./ .github/ scripts/ node_modules/ .bin/ prettier " ./testing/setup.ts" --write
161
+ ./ .github/ scripts/ node_modules/ .bin/ prettier " ./testing/utils" --write
162
+
163
+ [unix ]
164
+ build-publish :
165
+ pnpm i
166
+ just build-publish-common
167
+ just build
168
+ cp " ./README.md" " npm/mach"
169
+
170
+ [windows ]
171
+ build-publish :
172
+ pnpm i
173
+ just build-publish-common
174
+ just build
175
+ Copy-Item " .\R EADME.md" -Destination " npm\m ach" | Out-Null
176
+
177
+ [private ]
178
+ build-publish-common :
179
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ string-replace .mjs \
180
+ " ./crates/mach_bundler_cli/Cargo.toml" \
181
+ " 0.0.0-local" \
182
+ {{ MACH_VERSION}}
183
+
184
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ string-replace .mjs \
185
+ " ./crates/mach_bundler_core/Cargo.toml" \
186
+ " 0.0.0-local" \
187
+ {{ MACH_VERSION}}
188
+
189
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ string-replace .mjs \
190
+ " ./npm/mach/package.json" \
191
+ " 0.0.0-local" \
192
+ " {{ MACH_VERSION}} "
193
+
194
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ json.mjs \
195
+ " ./npm/mach-os-arch/package.json" \
196
+ " name" \
197
+ " @alshdavid/mach-{{ os }} -{{ arch }} "
198
+
199
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ json.mjs \
200
+ " ./npm/mach-os-arch/package.json" \
201
+ " version" \
202
+ " {{ MACH_VERSION}} "
203
+
204
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ json.mjs \
205
+ " ./npm/mach-os-arch/package.json" \
206
+ " os.0" \
207
+ $(node " {{ justfile_directory ()}} /.github/scripts/ci/map.mjs" " os" {{os }})
208
+
209
+ node {{ justfile_directory ()}} / .github/ scripts/ ci/ json.mjs \
210
+ " ./npm/mach-os-arch/package.json" \
211
+ " cpu.0" \
212
+ $(node " {{ justfile_directory ()}} /.github/scripts/ci/map.mjs" " arch" {{arch }})
213
+
214
+ benchmark project = " mach" count = " 50" script = " build" * ARGS = " ":
215
+ @ just {{ if project == " mach" { " build" } else { " _skip" } }}
216
+ just benchmark-generate {{ project}} {{ count}}
217
+ cd benchmarks/ {{ project}} _{{ count}} && \
218
+ rm -rf dist && \
219
+ CMD=" console.log(require(\" ./package.json\" ).scripts[\" build\" ])" && \
220
+ CMD=" $(echo $CMD | node)" && \
221
+ echo $CMD && \
222
+ mach_profiler=../ {{ project}} _{{ count}} .csv \
223
+ time bash -c " $CMD {{ ARGS}} "
224
+
225
+ benchmark-generate project = " mach" count = " 50":
226
+ PROJECT={{ project}} \
227
+ BENCH_COPIES={{ count}} \
228
+ node .github/ scripts/ ci/ generate_benchmark.mjs
0 commit comments