From 540451a66da2097b25e7d328221eb90506279f1d Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 10 May 2019 14:42:48 -0400 Subject: [PATCH] Fix cbindgen macro expansion and CI --- .travis.yml | 39 ++++++++++++------ Makefile | 4 +- examples/hello_triangle_c/CMakeLists.txt | 6 +-- ffi/wgpu-remote.h | 2 +- ffi/wgpu.h | 51 +++++++++++++++++++++--- wgpu-native/cbindgen.toml | 3 +- wgpu-remote/cbindgen.toml | 4 ++ 7 files changed, 84 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index e6b23e4c9..16b8ecbe4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: rust +sudo: false +dist: xenial matrix: include: @@ -6,9 +8,11 @@ matrix: - os: linux rust: stable compiler: gcc - - os: linux - rust: nightly - compiler: gcc + #TODO: unlock when libglfw3 on Ubuntu comes with Vulkan support + # or when we add a GL backend. + #- os: linux + # rust: nightly + # compiler: gcc # Windows 64bit - os: windows rust: stable @@ -19,11 +23,11 @@ matrix: rust: stable osx_image: xcode9.4 compiler: clang - #- env: MACOSX_DEPLOYMENT_TARGET=10.9 - # os: osx - # rust: nightly - # osx_image: xcode9.4 - # compiler: clang + - env: MACOSX_DEPLOYMENT_TARGET=10.9 + os: osx + rust: nightly + osx_image: xcode9.4 + compiler: clang # iPhoneOS 64bit #- env: TARGET=aarch64-apple-ios @@ -31,16 +35,27 @@ matrix: # osx_image: xcode9.4 # rust: nightly +addons: + apt: + packages: + - cmake + - libglfw3-dev + homebrew: + update: true + packages: + - cmake + - glfw3 + choco: + packages: + - make + branches: except: - staging.tmp before_install: - # Do not run bors builds against the nightly compiler. - # We want to find out about nightly bugs, so they're done in master, but we don't block on them. - - if [[ $TRAVIS_RUST_VERSION == "nightly" && $TRAVIS_BRANCH == "staging" ]]; then exit; fi - if [[ $TRAVIS_OS_NAME == "windows" ]]; then choco install make; fi script: - cargo test - - if [[ $TRAVIS_OS_NAME == "osx" ]]; then (brew update && brew upgrade cmake && brew install glfw3 && cargo install cbindgen && make ffi-examples); fi + - if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo +nightly install cbindgen && make VERBOSE=1; fi diff --git a/Makefile b/Makefile index 0c1246ba3..8f5bb9825 100644 --- a/Makefile +++ b/Makefile @@ -54,10 +54,10 @@ lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(wildcard wgpu-native/**/*.rs wgp cargo build --manifest-path wgpu-remote/Cargo.toml --features $(FEATURE_RUST) ffi/wgpu.h: wgpu-native/cbindgen.toml $(wildcard wgpu-native/**/*.rs) - cbindgen wgpu-native >ffi/wgpu.h + rustup run nightly cbindgen wgpu-native >ffi/wgpu.h ffi/wgpu-remote.h: wgpu-remote/cbindgen.toml $(wildcard wgpu-native/**/*.rs wgpu-remote/**/*.rs) - cbindgen wgpu-remote >ffi/wgpu-remote.h + rustup run nightly cbindgen wgpu-remote >ffi/wgpu-remote.h examples-native: lib-native ffi/wgpu.h examples/hello_triangle_c/main.c cd examples/hello_triangle_c && mkdir -p build && cd build && cmake .. && make diff --git a/examples/hello_triangle_c/CMakeLists.txt b/examples/hello_triangle_c/CMakeLists.txt index 3803b384e..f3d9d3fca 100644 --- a/examples/hello_triangle_c/CMakeLists.txt +++ b/examples/hello_triangle_c/CMakeLists.txt @@ -7,17 +7,17 @@ set(TARGET_NAME hello_triangle) add_executable(hello_triangle main.c) if(MSVC) + add_definitions(-DWGPU_TARGET=WGPU_TARGET_WINDOWS) target_compile_options(${TARGET_NAME} PRIVATE /W4) - add_compile_definitions(WGPU_TARGET=WGPU_TARGET_WINDOWS) set(GLFW_LIBRARY glfw3) elseif(APPLE) - add_compile_definitions(WGPU_TARGET=WGPU_TARGET_MACOS) + add_definitions(-DWGPU_TARGET=WGPU_TARGET_MACOS) set(OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore") target_compile_options(${TARGET_NAME} PRIVATE -x objective-c) set(GLFW_LIBRARY glfw) else(MSVC) + add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX) target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic) - add_compile_definitions(WGPU_TARGET=WGPU_TARGET_LINUX) set(GLFW_LIBRARY glfw) endif(MSVC) diff --git a/ffi/wgpu-remote.h b/ffi/wgpu-remote.h index fe38e949e..dd528251f 100644 --- a/ffi/wgpu-remote.h +++ b/ffi/wgpu-remote.h @@ -1,6 +1,6 @@ -/* Generated with cbindgen:0.8.3 */ +/* Generated with cbindgen:0.8.6 */ #include #include diff --git a/ffi/wgpu.h b/ffi/wgpu.h index b427c7c6e..03c9085cc 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -1,6 +1,6 @@ +#define WGPU_LOCAL - -/* Generated with cbindgen:0.8.3 */ +/* Generated with cbindgen:0.8.6 */ #include #include @@ -630,7 +630,9 @@ typedef struct { +#if defined(WGPU_LOCAL) WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, const WGPUDeviceDescriptor *desc); +#endif void wgpu_bind_group_destroy(WGPUBindGroupId bind_group_id); @@ -672,10 +674,14 @@ void wgpu_command_buffer_copy_texture_to_texture(WGPUCommandBufferId command_buf const WGPUTextureCopyView *destination, WGPUExtent3d copy_size); +#if defined(WGPU_LOCAL) WGPUComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId command_encoder_id); +#endif +#if defined(WGPU_LOCAL) WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId command_encoder_id, WGPURenderPassDescriptor desc); +#endif WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId command_encoder_id); @@ -691,42 +697,68 @@ void wgpu_compute_pass_set_bind_group(WGPUComputePassId pass_id, void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id); +#if defined(WGPU_LOCAL) WGPUInstanceId wgpu_create_instance(void); +#endif +#if defined(WGPU_LOCAL) WGPUBindGroupId wgpu_device_create_bind_group(WGPUDeviceId device_id, const WGPUBindGroupDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUBindGroupLayoutId wgpu_device_create_bind_group_layout(WGPUDeviceId device_id, const WGPUBindGroupLayoutDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUBufferId wgpu_device_create_buffer(WGPUDeviceId device_id, const WGPUBufferDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUBufferId wgpu_device_create_buffer_mapped(WGPUDeviceId device_id, const WGPUBufferDescriptor *desc, uint8_t **mapped_ptr_out); +#endif +#if defined(WGPU_LOCAL) WGPUCommandEncoderId wgpu_device_create_command_encoder(WGPUDeviceId device_id, const WGPUCommandEncoderDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUComputePipelineId wgpu_device_create_compute_pipeline(WGPUDeviceId device_id, const WGPUComputePipelineDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUPipelineLayoutId wgpu_device_create_pipeline_layout(WGPUDeviceId device_id, const WGPUPipelineLayoutDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPURenderPipelineId wgpu_device_create_render_pipeline(WGPUDeviceId device_id, const WGPURenderPipelineDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUSamplerId wgpu_device_create_sampler(WGPUDeviceId device_id, const WGPUSamplerDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUShaderModuleId wgpu_device_create_shader_module(WGPUDeviceId device_id, const WGPUShaderModuleDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id, WGPUSurfaceId surface_id, const WGPUSwapChainDescriptor *desc); +#endif +#if defined(WGPU_LOCAL) WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc); +#endif void wgpu_device_destroy(WGPUDeviceId device_id); @@ -734,24 +766,27 @@ WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id); void wgpu_device_poll(WGPUDeviceId device_id, bool force_wait); +#if defined(WGPU_LOCAL) WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id, void *layer); +#endif +#if defined(WGPU_LOCAL) WGPUSurfaceId wgpu_instance_create_surface_from_windows_hwnd(WGPUInstanceId instance_id, void *hinstance, void *hwnd); - -#if defined(WGPU_WINDOW_WINIT) -WGPUSurfaceId wgpu_instance_create_surface_from_winit(WGPUInstanceId instance_id, - const WGPUWindow *window); #endif +#if defined(WGPU_LOCAL) WGPUSurfaceId wgpu_instance_create_surface_from_xlib(WGPUInstanceId instance_id, const void **display, uint64_t window); +#endif +#if defined(WGPU_LOCAL) WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, const WGPUAdapterDescriptor *desc); +#endif void wgpu_queue_submit(WGPUQueueId queue_id, const WGPUCommandBufferId *command_buffer_ptr, @@ -801,10 +836,14 @@ WGPUSwapChainOutput wgpu_swap_chain_get_next_texture(WGPUSwapChainId swap_chain_ void wgpu_swap_chain_present(WGPUSwapChainId swap_chain_id); +#if defined(WGPU_LOCAL) WGPUTextureViewId wgpu_texture_create_default_view(WGPUTextureId texture_id); +#endif +#if defined(WGPU_LOCAL) WGPUTextureViewId wgpu_texture_create_view(WGPUTextureId texture_id, const WGPUTextureViewDescriptor *desc); +#endif void wgpu_texture_destroy(WGPUTextureId texture_id); diff --git a/wgpu-native/cbindgen.toml b/wgpu-native/cbindgen.toml index 5ac37d90e..42a9acb0e 100644 --- a/wgpu-native/cbindgen.toml +++ b/wgpu-native/cbindgen.toml @@ -1,4 +1,4 @@ -header = "" +header = "#define WGPU_LOCAL" include_version = true braces = "SameLine" line_length = 100 @@ -14,6 +14,7 @@ exclude = ["BufferMapResult"] parse_deps = false [parse.expand] +crates = ["wgpu-native"] features = ["local"] [fn] diff --git a/wgpu-remote/cbindgen.toml b/wgpu-remote/cbindgen.toml index c0c50b493..ead37a089 100644 --- a/wgpu-remote/cbindgen.toml +++ b/wgpu-remote/cbindgen.toml @@ -7,11 +7,15 @@ language = "C" [export] prefix = "WGPU" +exclude = ["BufferMapResult"] [parse] parse_deps = true include = ["wgpu_native"] +[parse.expand] +crates = ["wgpu-native"] + [fn] [struct]