codegen: avoid lossy string conversion

This can't possibly work right if lossy conversion is required.
reviewable/pr1167/r1
Tamir Duberstein 3 weeks ago
parent 665d4f20bb
commit ee7861a6ed

@ -15,23 +15,9 @@ fn codegen_internal_btf_bindings(libbpf_dir: &Path) -> Result<(), anyhow::Error>
let generated = dir.join("src/generated"); let generated = dir.join("src/generated");
let mut bindgen = bindgen::user_builder() let mut bindgen = bindgen::user_builder()
.clang_arg(format!( .clang_args(["-I", libbpf_dir.join("include/uapi").to_str().unwrap()])
"-I{}", .clang_args(["-I", libbpf_dir.join("include").to_str().unwrap()])
libbpf_dir .header(libbpf_dir.join("src/libbpf_internal.h").to_str().unwrap())
.join("include/uapi")
.canonicalize()
.unwrap()
.to_string_lossy()
))
.clang_arg(format!(
"-I{}",
libbpf_dir
.join("include")
.canonicalize()
.unwrap()
.to_string_lossy()
))
.header(libbpf_dir.join("src/libbpf_internal.h").to_string_lossy())
.constified_enum_module("bpf_core_relo_kind"); .constified_enum_module("bpf_core_relo_kind");
let types = ["bpf_core_relo", "btf_ext_header"]; let types = ["bpf_core_relo", "btf_ext_header"];
@ -177,9 +163,9 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh
let builder = || { let builder = || {
bindgen::user_builder() bindgen::user_builder()
.header(dir.join("include/linux_wrapper.h").to_string_lossy()) .header(dir.join("include/linux_wrapper.h").to_str().unwrap())
.clang_args(&["-I", &*libbpf_dir.join("include/uapi").to_string_lossy()]) .clang_args(["-I", libbpf_dir.join("include/uapi").to_str().unwrap()])
.clang_args(&["-I", &*libbpf_dir.join("include").to_string_lossy()]) .clang_args(["-I", libbpf_dir.join("include").to_str().unwrap()])
}; };
for arch in Architecture::supported() { for arch in Architecture::supported() {
@ -209,7 +195,7 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh
Architecture::S390X => s390x_sysroot, Architecture::S390X => s390x_sysroot,
Architecture::Mips => mips_sysroot, Architecture::Mips => mips_sysroot,
}; };
bindgen = bindgen.clang_args(&["-I", &*sysroot.to_string_lossy()]); bindgen = bindgen.clang_args(["-I", sysroot.to_str().unwrap()]);
for x in &types { for x in &types {
bindgen = bindgen.allowlist_type(x); bindgen = bindgen.allowlist_type(x);

@ -29,13 +29,13 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
let builder = || { let builder = || {
let mut bindgen = bindgen::bpf_builder() let mut bindgen = bindgen::bpf_builder()
.header(&*dir.join("include/bindings.h").to_string_lossy()) .header(dir.join("include/bindings.h").to_str().unwrap())
// aya-tool uses aya_ebpf::cty. We can't use that here since aya-bpf // aya-tool uses aya_ebpf::cty. We can't use that here since aya-bpf
// depends on aya-ebpf-bindings so it would create a circular dep. // depends on aya-ebpf-bindings so it would create a circular dep.
.ctypes_prefix("::aya_ebpf_cty") .ctypes_prefix("::aya_ebpf_cty")
.clang_args(&["-I", &*libbpf_dir.join("include/uapi").to_string_lossy()]) .clang_args(["-I", libbpf_dir.join("include/uapi").to_str().unwrap()])
.clang_args(&["-I", &*libbpf_dir.join("include").to_string_lossy()]) .clang_args(["-I", libbpf_dir.join("include").to_str().unwrap()])
.clang_args(&["-I", &*libbpf_dir.join("src").to_string_lossy()]) .clang_args(["-I", libbpf_dir.join("src").to_str().unwrap()])
// BPF_F_LINK is defined twice. Once in an anonymous enum // BPF_F_LINK is defined twice. Once in an anonymous enum
// which bindgen will constify, and once via #define macro // which bindgen will constify, and once via #define macro
// which generates a duplicate const. // which generates a duplicate const.
@ -95,7 +95,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
Architecture::S390X => "s390x-unknown-linux-gnu", Architecture::S390X => "s390x-unknown-linux-gnu",
Architecture::Mips => "mips-unknown-linux-gnu", Architecture::Mips => "mips-unknown-linux-gnu",
}; };
bindgen = bindgen.clang_args(&["-target", target]); bindgen = bindgen.clang_args(["-target", target]);
// Set the sysroot. This is needed to ensure that the correct arch // Set the sysroot. This is needed to ensure that the correct arch
// specific headers are imported. // specific headers are imported.
@ -108,7 +108,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
Architecture::S390X => s390x_sysroot, Architecture::S390X => s390x_sysroot,
Architecture::Mips => mips_sysroot, Architecture::Mips => mips_sysroot,
}; };
bindgen = bindgen.clang_args(&["-I", &*sysroot.to_string_lossy()]); bindgen = bindgen.clang_args(["-I", sysroot.to_str().unwrap()]);
let bindings = bindgen let bindings = bindgen
.generate() .generate()

Loading…
Cancel
Save