Skip to content

Commit

Permalink
Fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
gleocadie committed Jun 10, 2022
1 parent 9c2d602 commit 8571b62
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,51 @@ 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
if: '${{ always() }}'
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 .
20 changes: 18 additions & 2 deletions ddprof-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
Expand All @@ -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
Expand Down
17 changes: 16 additions & 1 deletion examples/ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion examples/ffi/exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {
#include <thread>

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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/ffi/profiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8571b62

Please sign in to comment.