build: improve justfile

This commit is contained in:
dusk 2024-11-28 23:14:20 +03:00
parent 7de1e84d98
commit 96f8c884b7
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 35 additions and 8 deletions

View File

@ -1,8 +1,9 @@
set shell := ['nu', '-c'] set shell := ['nu', 'justfile.nu']
set export
profile := 'dev' profile := 'dev'
host-target := `rustc -vV | lines | skip 1 | to text | from csv -s : --noheaders | reduce -f {} {|el, acc| $acc | upsert $el.column0 $el.column1 } | get host` host-target := `rustc -vV | lines | skip 1 | to text | from csv -s : --noheaders | reduce -f {} {|el, acc| $acc | upsert $el.column0 $el.column1 } | get host | str trim`
artifact-dir := 'addons/boids/lib' artifact-dir := 'addons/boids/lib'
[private] [private]
@ -17,15 +18,19 @@ just-cmd *FLAGS="":
@just -f {{justfile()}} {{FLAGS}} @just -f {{justfile()}} {{FLAGS}}
build ext $target=(host-target) *FLAGS="": setup-env build $target=(host-target) *FLAGS="": setup-env
cd rust; cross build {{FLAGS}} --profile {{profile}} --target {{target}} cd rust; cross build {{FLAGS}} --profile {{profile}} --target {{target}}
mv -f rust/target/{{target}}/{{ if profile == 'dev' { 'debug' } else { profile } }}/{{ if target =~ 'linux' { 'lib' } else { '' } }}boids.{{ext}} {{artifact-dir}}/boids.{{`$env.target | split row - | first`}}.{{ext}}
build-wasm: (build 'wasm' 'wasm32-unknown-emscripten' '+nightly' '-Zbuild-std') install $target=(host-target): setup-env
build-windows: (build 'dll' 'x86_64-pc-windows-msvc') mv -f rust/target/{{target}}/{{`$env.profiledir`}}/{{`$env.libprefix`}}boids.{{`$env.ext`}} {{artifact-dir}}/boids.{{`$env.arch`}}.{{`$env.ext`}}
build-linux: (build 'so' 'x86_64-unknown-linux-gnu')
build-all: (just-cmd '--timestamp' 'profile=release' 'build-linux' 'build-windows' 'build-wasm') build-install target *FLAGS="": (build target FLAGS) (install target)
wasm: (build-install 'wasm32-unknown-emscripten' '+nightly' '-Zbuild-std')
windows: (build-install 'x86_64-pc-windows-msvc')
linux: (build-install 'x86_64-unknown-linux-gnu')
all: (just-cmd '--timestamp' 'profile=release' 'linux' 'windows' 'wasm')
package: package:

22
justfile.nu Normal file
View File

@ -0,0 +1,22 @@
let exts = {
wasm32-unknown-emscripten: "wasm"
x86_64-pc-windows-msvc: "dll"
x86_64-unknown-linux-gnu: "so"
}
def getext [] { $exts | get $env.target }
def getlibprefix [] { if ($env.target | str contains "linux") { "lib" } else { "" } }
def getarch [] { $env.target | split row - | first }
def getprofiledir [] { if ($env.profile == 'dev') { "debug" } else { $env.profile }}
def main [command: string] {
if ('target' in $env) {
$env.ext = getext
$env.libprefix = getlibprefix
$env.arch = getarch
}
if ('profile' in $env) {
$env.profiledir = getprofiledir
}
nu -c $command
}