BPF 工程實現可執行文件與 BPF 文件獨立編譯 #5940
Answered
by
Carryme1899
Carryme1899
asked this question in
Q&A
-
參考 libbpf-bootstrap 我想使用 gcc 編譯鏈結 minimal.c: toolchain("my-gcc")
set_kind("standalone")
set_sdkdir("/path/to/my-gcc")
toolchain_end()
target("minimal-bpfobj")
set_toolchains("@llvm")
set_kind("object")
add_rules("platform.linux.bpf")
add_deps("libbpf")
add_files("src/minimal.bpf.c")
target_end()
target("minimal-bin")
set_toolchains("my-gcc")
set_kind("binary")
add_deps("libbpf")
add_files("src/minimal.c")
add_includedirs("/path/to/.gens/minimal-bpfobj/rules/bpf/")
target_end() .gens 底下能產生正確的 bpf object 和 .skel.h 試過修改內置規則,導出 .skel.h 所在路徑,並於 target bin 加入依賴 target bpfobj -- built-in rules
rule("platform.linux.bpf")
...
-- target:add("includedirs", headerdir)
target:add("includedirs", headerdir, {public = true}) target("minimal-bin")
set_toolchains("my-gcc")
set_kind("binary")
add_deps("libbpf", "minimal-bpfobj")
... 這個方式需先建置 target bpfobj,確定 skel.h 存在/更新後才能建置 target bin |
Beta Was this translation helpful? Give feedback.
Answered by
Carryme1899
Dec 9, 2024
Replies: 1 comment 1 reply
-
没懂,自己参考内置 rule ,实现个 custom rule 搞搞不就好了么。 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以了,在 target bpfobj 指定 set_policy("build.fence", true) 就行
我以為 add_deps 就足以保證構建順序,但忘了併行化的影響
原先問題是這樣的,target bin 的 header 依賴 target bpfobj 編譯後用 bpftool 生成
實際上需求就和 #5003 (comment) 描述相同