forked from bpftrace/bpftrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resources: generate c++ file instead of c file
If we use clang to build bpftrace instead of GCC, it will complain about trying to use the `-std-c++14` flag to comile headers.c. If we force cmake to skip this flag on `.c` files, clang is not able to link libresources.a correctly. This patch changes the resources workflow to generate a .cpp file instead, and to have a `src/headers.h` with all headers we currently use. With this approach we get a safer linkage because the same definition for the header strings is being used in clang_parser.cpp and in headers.cpp. Fixes: bpftrace#350
- Loading branch information
Showing
3 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
add_library(resources headers.c) | ||
add_library(resources headers.cpp) | ||
|
||
target_include_directories(resources PUBLIC ../src) | ||
|
||
function(embed_headers output) | ||
file(WRITE ${output} "") | ||
file(WRITE ${output} "#include \"headers.h\"\n\nnamespace bpftrace {\n") | ||
file(GLOB headers *.h) | ||
foreach(header ${headers}) | ||
get_filename_component(filename ${header} NAME) | ||
string(MAKE_C_IDENTIFIER ${filename} varname) | ||
file(READ ${header} contents) | ||
file(APPEND ${output} "const char ${varname}[] = R\"CONTENTS(${contents})CONTENTS\";\nconst unsigned ${varname}_len = sizeof(${varname});\n") | ||
endforeach() | ||
file(APPEND ${output} "} // namespace bpftrace") | ||
endfunction() | ||
|
||
embed_headers(${CMAKE_BINARY_DIR}/resources/headers.c) | ||
embed_headers(${CMAKE_BINARY_DIR}/resources/headers.cpp) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
namespace bpftrace { | ||
|
||
// These externs are provided by our build system. See resources/CMakeLists.txt | ||
extern const char __stddef_max_align_t_h[]; | ||
extern const unsigned __stddef_max_align_t_h_len; | ||
extern const char float_h[]; | ||
extern const unsigned float_h_len; | ||
extern const char limits_h[]; | ||
extern const unsigned limits_h_len; | ||
extern const char stdarg_h[]; | ||
extern const unsigned stdarg_h_len; | ||
extern const char stddef_h[]; | ||
extern const unsigned stddef_h_len; | ||
extern const char stdint_h[]; | ||
extern const unsigned stdint_h_len; | ||
|
||
} // namespace bpftrace |