Skip to content

Commit 8aab8ed

Browse files
authored
feat: add LLVM backend version reporting and improve help formatting (#246)
Add compile-time LLVM version detection and display in --version output, plus improve help text readability with aligned columns. Changes: - Set LLVM version at build time via cargo:rustc-env: - Export WAVE_LLVM_MAJOR=14 in all platform-specific linkers - Linux (linux_original), macOS (link_macos), Windows (link_windows) - Add backend() function to llvm_temporary/lib.rs: - Retrieve WAVE_LLVM_MAJOR from compile-time environment - Return formatted string "LLVM {version}" or None - Display backend version in --version output: - Call llvm_temporary::backend() from version_wave() - Print "backend: LLVM 14" with gray color formatting - Fallback to "backend: unknown backend" if unavailable - Improve help text formatting in print_help(): - Use consistent column width alignment ({:<18}, {:<22}) - Add descriptive text for each command and option - Group related options (Commands, Optimization, Debug) - Expand optimization flag descriptions (-O0..-O3, -Oz, -Ofast) - Clarify debug option purposes (tokens, AST, IR, MC, hex) - Keep practical usage examples at bottom Output example: wavec 0.1.5-pre-beta (Linux 6.x.x) backend: LLVM 14 This provides transparency about the compiler toolchain configuration and improves CLI user experience with readable help formatting. Signed-off-by: LunaStev <luna@lunastev.org>
1 parent 321012b commit 8aab8ed

File tree

4 files changed

+84
-13
lines changed

4 files changed

+84
-13
lines changed

llvm_temporary/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ fn linux_original() {
2727
println!("cargo:rustc-link-lib=llvm-14");
2828
println!("cargo:rustc-link-search=native=/usr/lib/llvm-14/lib");
2929

30+
println!("cargo:rustc-env=WAVE_LLVM_MAJOR=14");
31+
3032
println!("cargo:rustc-link-lib=stdc++");
3133
println!("cargo:rustc-link-lib=ffi");
3234
println!("cargo:rustc-link-lib=z");
@@ -53,6 +55,7 @@ fn try_macos_paths() {
5355
}
5456

5557
fn link_macos(prefix: PathBuf) {
58+
println!("cargo:rustc-env=WAVE_LLVM_MAJOR=14");
5659
let lib = prefix.join("lib");
5760

5861
println!("cargo:rustc-link-search=native={}", lib.display());
@@ -83,6 +86,7 @@ fn try_windows_paths() {
8386
}
8487

8588
fn link_windows(prefix: PathBuf) {
89+
println!("cargo:rustc-env=WAVE_LLVM_MAJOR=14");
8690
let lib = prefix.join("lib");
8791

8892
println!("cargo:rustc-link-search=native={}", lib.display());

llvm_temporary/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
pub mod llvm_temporary;
2+
3+
pub fn backend() -> Option<String> {
4+
option_env!("WAVE_LLVM_MAJOR")
5+
.map(|v| format!("LLVM {}", v))
6+
}

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use colorex::Colorize;
88
use crate::version::get_os_pretty_name;
99

1010
use commands::DebugFlags;
11+
use llvm_temporary::backend;
1112

1213
pub unsafe fn compile_and_run(path: &Path, opt_flag: &str, debug: &DebugFlags) {
1314
runner::run_wave_file(path, opt_flag, debug);
@@ -26,4 +27,10 @@ pub fn version_wave() {
2627
version::version().color("2,161,47"),
2728
os
2829
);
30+
31+
if let Some(backend) = backend() {
32+
println!(" backend: {}", backend.color("117,117,117"));
33+
} else {
34+
println!("{}", " backend: unknown backend".color("117,117,117"));
35+
}
2936
}

src/main.rs

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,84 @@ fn print_usage() {
8585
}
8686

8787
fn print_help() {
88-
println!("{}", "Wave Compiler — Commands & Options".color("145,161,2"));
88+
println!("{}", "Wave Compiler".color("145,161,2"));
89+
println!("{}", "Commands & Options");
8990
print_usage();
9091

9192
println!("\nCommands:");
92-
println!(" {} {}", "run <file>".color("38,139,235"), "Execute Wave file");
93-
println!(" {} {}", "build <file>".color("38,139,235"), "Compile Wave file");
94-
println!(" {} {}", "--help".color("38,139,235"), "Show help");
95-
println!(" {} {}", "--version".color("38,139,235"), "Show version");
93+
println!(
94+
" {:<18} {}",
95+
"run <file>".color("38,139,235"),
96+
"Execute Wave file"
97+
);
98+
println!(
99+
" {:<18} {}",
100+
"build <file>".color("38,139,235"),
101+
"Compile Wave file"
102+
);
103+
println!(
104+
" {:<18} {}",
105+
"--help".color("38,139,235"),
106+
"Show this help message"
107+
);
108+
println!(
109+
" {:<18} {}",
110+
"--version".color("38,139,235"),
111+
"Show compiler version"
112+
);
96113

97114
println!("\nOptimization:");
98-
println!(" -O0, -O1, -O2, -O3, -Oz, -Ofast");
115+
println!(
116+
" {:<18} {}",
117+
"-O0 .. -O3".color("38,139,235"),
118+
"Set optimization level"
119+
);
120+
println!(
121+
" {:<18} {}",
122+
"-Oz".color("38,139,235"),
123+
"Optimize for binary size"
124+
);
125+
println!(
126+
" {:<18} {}",
127+
"-Ofast".color("38,139,235"),
128+
"Enable aggressive optimizations"
129+
);
99130

100131
println!("\nDebug options:");
101-
println!(" --debug-wave=tokens");
102-
println!(" --debug-wave=ast");
103-
println!(" --debug-wave=ir");
104-
println!(" --debug-wave=mc");
105-
println!(" --debug-wave=hex");
106-
println!(" --debug-wave=all");
132+
println!(
133+
" {:<22} {}",
134+
"--debug-wave=tokens".color("38,139,235"),
135+
"Print lexer tokens"
136+
);
137+
println!(
138+
" {:<22} {}",
139+
"--debug-wave=ast".color("38,139,235"),
140+
"Print AST"
141+
);
142+
println!(
143+
" {:<22} {}",
144+
"--debug-wave=ir".color("38,139,235"),
145+
"Print LLVM IR"
146+
);
147+
println!(
148+
" {:<22} {}",
149+
"--debug-wave=mc".color("38,139,235"),
150+
"Print machine code"
151+
);
152+
println!(
153+
" {:<22} {}",
154+
"--debug-wave=hex".color("38,139,235"),
155+
"Print raw hex output"
156+
);
157+
println!(
158+
" {:<22} {}",
159+
"--debug-wave=all".color("38,139,235"),
160+
"Enable all debug outputs"
161+
);
107162

108163
println!("\nExamples:");
109164
println!(" wavec run test.wave");
110165
println!(" wavec run -O3 test.wave");
111166
println!(" wavec run --debug-wave=ir test.wave");
112167
println!(" wavec run -Ofast --debug-wave=all test.wave");
113-
}
168+
}

0 commit comments

Comments
 (0)