Skip to content

Commit dc4b820

Browse files
committed
build: do not add -static for NixOS, make the output more readable
1 parent 7bb1aee commit dc4b820

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

build.vsh

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const bin_path = './bin/v-analyzer' + $if windows { '.exe' } $else { '' }
1414
const build_commit = os.execute('git rev-parse --short HEAD').output.trim_space()
1515
const build_time = time.now()
1616
const build_datetime = build_time.format_ss()
17-
const gcheck = term.green('✓')
17+
const gcheck = term.bold(term.green('✓'))
18+
const ynote = term.bold(term.gray('ⓘ'))
19+
const is_nixos = os.exists('/etc/NIXOS')
1820

1921
enum ReleaseMode {
2022
release
@@ -23,7 +25,25 @@ enum ReleaseMode {
2325
}
2426

2527
fn eline(msg string) {
26-
eprintln('${term.red('[ERROR]')} ${msg}')
28+
eprintln('${term.bold(term.red('[ERROR]'))} ${msg}')
29+
}
30+
31+
fn detect_build_os() {
32+
$if windows {
33+
println('${ynote} Detected Windows .')
34+
}
35+
$if macos {
36+
println('${ynote} Detected macOS .')
37+
}
38+
$if linux {
39+
println('${ynote} Detected Linux .')
40+
}
41+
$if freebsd {
42+
println('${ynote} Detected FreeBSD .')
43+
}
44+
if is_nixos {
45+
println('${ynote} NIXOS detected ... The build *should NOT* be static .')
46+
}
2747
}
2848

2949
fn (m ReleaseMode) compile_cmd() string {
@@ -39,15 +59,21 @@ fn (m ReleaseMode) compile_cmd() string {
3959
''
4060
}
4161
}
62+
4263
cflags := $if cross_compile_macos_arm64 ? {
4364
'-cflags "-target arm64-apple-darwin"'
4465
} $else $if cross_compile_macos_x86_64 ? {
4566
'-cflags "-target x86_64-apple-darwin"'
4667
} $else $if linux {
47-
if m == .release { '-cflags -static' } else { '' }
68+
if !is_nixos && m == .release {
69+
'-cflags -static'
70+
} else {
71+
''
72+
}
4873
} $else {
4974
''
5075
}
76+
5177
libbacktrace := $if windows { '' } $else { '-d use_libbacktrace' }
5278
build_cmd := '${base_build_cmd} ${cc} ${cflags}'.trim_space()
5379
mut resulting_cmd := match m {
@@ -74,17 +100,19 @@ fn prepare_output_dir() string {
74100
}
75101

76102
fn build(mode ReleaseMode, explicit_debug bool) {
77-
vexe_version := os.execute('${os.quoted_path(vexe)} version').output.trim_space()
78-
println('${gcheck} Building with ${vexe_version} .')
79-
println('${gcheck} Building v-analyzer at commit: ${build_commit} .')
80-
println('${gcheck} Building start time: ${build_datetime} .')
81-
82103
odir := prepare_output_dir()
83104
println('${gcheck} Prepared output directory `${odir}` .')
84105

106+
detect_build_os()
107+
108+
vexe_version := os.execute('${os.quoted_path(vexe)} version').output.trim_space()
109+
println('${ynote} Building with ${vexe_version} .')
110+
println('${ynote} Building v-analyzer at commit: ${build_commit} .')
111+
println('${ynote} Building start time: ${build_datetime} .')
112+
85113
cmd := mode.compile_cmd()
86-
println('Building v-analyzer in ${term.bold(mode.str())} mode, using:')
87-
println(' ${cmd}')
114+
println('${ynote} Compiling v-analyzer in ${term.bold(mode.str())} mode, using:')
115+
println(cmd)
88116
if mode == .release {
89117
println('This may take 1-2 minutes... Please wait.')
90118
}
@@ -105,8 +133,8 @@ fn build(mode ReleaseMode, explicit_debug bool) {
105133

106134
final_path := abs_path(bin_path)
107135
nbytes := os.file_size(final_path)
108-
println('The binary size in bytes is: ${nbytes} .')
109-
println('The binary is located at ${term.bold(final_path)} .')
136+
println('${ynote} The binary size in bytes is: ${nbytes:8} .')
137+
println('${ynote} The binary is located here: ${term.bold(final_path)} .')
110138
elapsed_ms := f64((time.now() - build_time).milliseconds())
111139
println('${gcheck} Successfully built v-analyzer, in ${elapsed_ms / 1000.0:5.3f}s .')
112140
}

0 commit comments

Comments
 (0)