diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6dfada092..18720947a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,20 +43,37 @@ jobs: - platform: "ubuntu-latest" rust_version: "${RUST_VERSION}" steps: + - name: Checkout sources uses: actions/checkout@v2 + + - name: Setup output dir + shell: bash + run: | + WORKSPACE_PATH=${{ github.workspace }} + if [[ "${{ matrix.platform }}" == "windows-latest" ]]; then + WORKSPACE_PATH=$(cygpath -ua '${{ github.workspace }}') + fi + echo "OUTPUT_FOLDER=$WORKSPACE_PATH/artifacts" >> $GITHUB_ENV + - name: Cache uses: ./.github/actions/cache with: rust_version: ${{ matrix.rust_version }} build_profile: "release" + - name: Install Rust ${{ matrix.rust_version }} if: ${{ matrix.rust_version != '' }} run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }} + - id: rust-version run: "echo ::set-output name=version::$(rustc --version)" + - name: "Generate FFI" - run: bash ffi-build.sh /tmp/libddprof + shell: bash + run: | + chmod +x ffi-build.sh + ./ffi-build.sh ${OUTPUT_FOLDER} - name: 'Publish libdatadog' uses: actions/upload-artifact@v2 @@ -64,8 +81,13 @@ jobs: with: if-no-files-found: error name: libdatadog.${{ matrix.platform }} - path: /tmp/libddprof + path: ${{ github.workspace }}/artifacts retention-days: 1 - name: "Test building C bindings" - run: mkdir examples/ffi/build && cd examples/ffi/build && cmake -S .. -DDDProf_ROOT=/tmp/libddprof && cmake --build . + shell: bash + run: | + mkdir examples/ffi/build + cd examples/ffi/build + cmake -S .. -DDDProf_ROOT=$OUTPUT_FOLDER + cmake --build . diff --git a/ddprof-ffi/cbindgen.toml b/ddprof-ffi/cbindgen.toml index 25b044b33..05c4be309 100644 --- a/ddprof-ffi/cbindgen.toml +++ b/ddprof-ffi/cbindgen.toml @@ -14,8 +14,24 @@ sys_includes = ["stdbool.h", "stddef.h", "stdint.h"] after_includes = """ +#if defined(_MSC_VER) #define DDPROF_FFI_CHARSLICE_C(string) \\ - /* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddprof_ffi_CharSlice) {.ptr = "" string, .len = sizeof(string) - 1})""" +/* NOTE: Compilation fails if you pass in a char* instead of a literal */ ddprof_ffi_CharSlice{.ptr = "" string, .len = sizeof(string) - 1} +#else +#define DDPROF_FFI_CHARSLICE_C(string) \\ +/* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddprof_ffi_CharSlice){ .ptr = "" string, .len = sizeof(string) - 1 }) +#endif + +#if defined(__cplusplus) && (__cplusplus >= 201703L) +# define DD_CHECK_RETURN [[nodiscard]] +#elif defined(_Check_return_) /* SAL */ +# define DD_CHECK_RETURN _Check_return_ +#elif (defined(__has_attribute) && __has_attribute(warn_unused_result)) || \\ + (defined(__GNUC__) && (__GNUC__ >= 4)) +# define DD_CHECK_RETURN __attribute__((__warn_unused_result__)) +#else +# define DD_CHECK_RETURN +#endif""" [export] prefix = "ddprof_ffi_" @@ -28,7 +44,7 @@ prefix_with_name = true rename_variants = "ScreamingSnakeCase" [fn] -must_use = "__attribute__((warn_unused_result))" +must_use = "DD_CHECK_RETURN" [parse] parse_deps = true diff --git a/examples/ffi/CMakeLists.txt b/examples/ffi/CMakeLists.txt index 3ceffc5a6..fd0aade7f 100644 --- a/examples/ffi/CMakeLists.txt +++ b/examples/ffi/CMakeLists.txt @@ -4,7 +4,22 @@ cmake_minimum_required(VERSION 3.19) find_package(DDProf) add_executable(exporter exporter.cpp) -target_compile_features(exporter PRIVATE cxx_std_11) + +if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + target_compile_features(exporter PRIVATE cxx_std_20) # needed for designated initializers + target_compile_definitions(exporter PUBLIC _CRT_SECURE_NO_WARNINGS) + target_link_libraries(exporter + NtDll + UserEnv + Bcrypt + crypt32 + wsock32 + ws2_32 + shlwapi) +else() + target_compile_features(exporter PRIVATE cxx_std_11) +endif() + target_link_libraries(exporter DDProf::FFI) add_executable(profiles profiles.c) target_link_libraries(profiles DDProf::FFI) diff --git a/examples/ffi/exporter.cpp b/examples/ffi/exporter.cpp index a1f18a176..c432b9f08 100644 --- a/examples/ffi/exporter.cpp +++ b/examples/ffi/exporter.cpp @@ -9,7 +9,7 @@ extern "C" { #include static ddprof_ffi_Slice_c_char to_slice_c_char(const char *s) { - return (ddprof_ffi_Slice_c_char){.ptr = s, .len = strlen(s)}; + return ddprof_ffi_Slice_c_char({.ptr = s, .len = strlen(s)}); } struct Deleter { diff --git a/examples/ffi/profiles.c b/examples/ffi/profiles.c index 9c5292947..d184d637a 100644 --- a/examples/ffi/profiles.c +++ b/examples/ffi/profiles.c @@ -31,7 +31,7 @@ int main(void) { struct ddprof_ffi_Location root_location = { // yes, a zero-initialized mapping is valid - .mapping = (struct ddprof_ffi_Mapping){}, + .mapping = (struct ddprof_ffi_Mapping){0}, .lines = (struct ddprof_ffi_Slice_line){&root_line, 1}, }; int64_t value = 10;