Skip to content

Commit b0bf163

Browse files
authored
Merge pull request #13 from arighi/fix-clang-version
scx_utils::BpfBuilder: properly detect clang version in Ubuntu
2 parents 11c6a80 + 7ceccf6 commit b0bf163

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

rust/scx_utils/src/bpf_builder.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ pub struct BpfBuilder {
217217
}
218218

219219
impl BpfBuilder {
220+
fn skip_clang_version_prefix(line: &str) -> &str {
221+
if let Some(index) = line.find("clang version") {
222+
&line[index..]
223+
} else {
224+
line
225+
}
226+
}
227+
220228
fn find_clang() -> Result<(String, String, String)> {
221229
let clang = env::var("BPF_CLANG").unwrap_or("clang".into());
222230
let output = Command::new(&clang)
@@ -227,7 +235,10 @@ impl BpfBuilder {
227235
let stdout = String::from_utf8(output.stdout)?;
228236
let (mut ver, mut arch) = (None, None);
229237
for line in stdout.lines() {
230-
if let Ok(v) = sscanf!(line, "clang version {String}") {
238+
if let Ok(v) = sscanf!(
239+
Self::skip_clang_version_prefix(line),
240+
"clang version {String}"
241+
) {
231242
// Version could be followed by (URL SHA1). Only take
232243
// the first word.
233244
ver = Some(v.split_whitespace().next().unwrap().to_string());

0 commit comments

Comments
 (0)