diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71feccb8..ce1e4d4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,14 +102,14 @@ jobs: - run: ${{ matrix.make_command }} shell: bash - # Builds for binary releases. + # Builds for binary releases. Run on tags starting with 'v'. # The Linux builds are performed on a "manylinux2010" container. This container # is designed such that that the resulting binary has minimal dependencies on system # libraries, and thus works on as many linuxes as possible. It's a thing from the # Python world, but generally useful. release-build: name: release-build - ${{ matrix.name }} - if: contains(github.ref, 'tags/v') + if: success() && contains(github.ref, 'tags/v') runs-on: ${{ matrix.os }} strategy: matrix: @@ -144,8 +144,26 @@ jobs: OS_NAME: windows steps: - uses: actions/checkout@v2 + with: + submodules: 'true' + - name: set version (which gets baked into wgpuGetVersion) + run: | + echo "WGPU_NATIVE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + shell: bash + - name: Windows 64 deps + if: success() && matrix.OS_NAME == 'windows' && matrix.ARCH == 64 + run: | + choco install -y --force llvm | exit 0 + echo "LIBCLANG_PATH=C:\Program Files\LLVM\lib" >> $GITHUB_ENV + shell: bash + - name: Windows 32 deps + if: success() && matrix.OS_NAME == 'windows' && matrix.ARCH == 32 + run: | + choco install -y --force --x86 llvm | exit 0 + echo "LIBCLANG_PATH=C:\Program Files (x86)\LLVM\lib" >> $GITHUB_ENV + shell: bash - name: Docker build - if: success() && matrix.OS_NAME == 'Linux' + if: success() && matrix.OS_NAME == 'linux' env: IMAGE: ${{ matrix.IMAGE }} RUST_TOOLCHAIN: ${{ matrix.RUST_TOOLCHAIN }} @@ -158,14 +176,14 @@ jobs: curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none && \ rustup toolchain install --no-self-update $RUST_TOOLCHAIN && \ rustup default $RUST_TOOLCHAIN && \ - yum install zip -y && \ + yum install zip clang -y && \ make package") docker start -ai $CID mkdir -p dist docker cp $CID:/tmp/wgpu-native/dist/. dist/. docker rm $CID - name: Host build - if: success() && matrix.OS_NAME != 'Linux' + if: success() && matrix.OS_NAME != 'linux' env: RUST_TOOLCHAIN: ${{ matrix.RUST_TOOLCHAIN }} MACOSX_DEPLOYMENT_TARGET: ${{ matrix.MACOSX_DEPLOYMENT_TARGET }} @@ -186,6 +204,7 @@ jobs: mv dist/*release*.zip ./dist/wgpu-$OS_NAME-$ARCH-release.zip shell: bash - name: Publish + if: success() uses: actions/upload-artifact@v2 with: path: dist @@ -242,6 +261,10 @@ jobs: if: success() && contains(github.ref, 'tags/v') steps: - uses: actions/checkout@v2 + - name: set version (which gets used as release name) + run: | + echo "WGPU_NATIVE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + shell: bash - name: Download assets uses: actions/download-artifact@v1.0.0 with: @@ -251,16 +274,13 @@ jobs: GITHUB_SHA: ${{ github.sha }} run: | echo $GITHUB_SHA > dist/commit-sha - - name: Get version from git ref - id: get_version - run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - name: Create release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ steps.get_version.outputs.VERSION }} - release_name: Release ${{ steps.get_version.outputs.VERSION }} + tag_name: ${{ env.WGPU_NATIVE_VERSION }} + release_name: ${{ env.WGPU_NATIVE_VERSION }} body: | Autogenerated binary modules. The Linux builds are built on CentOS 6 (glibc 2.12, see [Manylinux2010](https://www.python.org/dev/peps/pep-0571/)). @@ -271,6 +291,6 @@ jobs: # Move back to official action after fix https://github.com/actions/upload-release-asset/issues/4 uses: AButler/upload-release-assets@v2.0 with: - release-tag: ${{ steps.get_version.outputs.VERSION }} + release-tag: ${{ env.WGPU_NATIVE_VERSION }} files: 'dist/*.zip;dist/commit-sha' repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index bb785656..6bab6925 100644 --- a/Makefile +++ b/Makefile @@ -61,9 +61,9 @@ package: lib-native lib-native-release ARCHIVE=wgpu-$$RELEASE-$(OS_NAME)-$(GIT_TAG).zip; \ rm -f dist/$$ARCHIVE; \ if [ $(OS_NAME) = windows ]; then \ - 7z a -tzip dist/$$ARCHIVE ./target/$$RELEASE/$(LIB_NAME).$(LIB_EXTENSION) ./target/$$RELEASE/$(LIB_NAME).$(LIB_EXTENSION).lib ./ffi/*.h ./dist/commit-sha; \ + 7z a -tzip dist/$$ARCHIVE ./target/$$RELEASE/$(LIB_NAME).$(LIB_EXTENSION) ./target/$$RELEASE/$(LIB_NAME).$(LIB_EXTENSION).lib ./ffi/*.h ./ffi/webgpu-headers/*.h ./dist/commit-sha; \ else \ - zip -j dist/$$ARCHIVE target/$$RELEASE/lib$(LIB_NAME).$(LIB_EXTENSION) ffi/*.h dist/commit-sha; \ + zip -j dist/$$ARCHIVE target/$$RELEASE/lib$(LIB_NAME).$(LIB_EXTENSION) ffi/*.h ./ffi/webgpu-headers/*.h dist/commit-sha; \ fi; \ done diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 2bad019c..32e8aaf8 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -35,6 +35,8 @@ void wgpuSetLogCallback(WGPULogCallback callback); void wgpuSetLogLevel(WGPULogLevel level); +uint32_t wgpuGetVersion(void); + void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStage stages, uint32_t offset, uint32_t sizeBytes, void* const data); #endif \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 8ad481d7..7decde6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -260,7 +260,7 @@ unsafe fn map_surface( use raw_window_handle::unix::XlibHandle; return wgpu_create_surface(raw_window_handle::RawWindowHandle::Xlib(XlibHandle { - window: x11.window as u64, + window: x11.window as _, display: x11.display as *mut _, ..XlibHandle::empty() })); diff --git a/src/logging.rs b/src/logging.rs index d5c1680c..2c39aa00 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -2,6 +2,32 @@ use crate::{map_enum, native}; use log::{Level, LevelFilter, Metadata, Record}; use std::ffi::CString; + +#[no_mangle] +pub unsafe extern "C" fn wgpuGetVersion() -> std::os::raw::c_uint { + // Take the string of WGPU_NATIVE_VERSION, strip any leading v's, split on dots, + // and map the first 4 parts to the bytes of an uint32, consuming MSB first. + // e.g. "v4.1" -> 0x04010000 + // "5.4.3.2.1" -> 0x05040302 + let static_str = match option_env!("WGPU_NATIVE_VERSION") { + Some (s) => s.trim().trim_start_matches("v"), + None => "", + }; + let mut version: u32 = 0; + let mut index: i32 = 0; + for part in static_str.split(".") { + let versionpart: u32 = match part.parse::() { + Ok(n) => n, + Err(_e) => 0, + }; + let shift : i32 = 8 * (3 - index); + if shift < 0 {break;} + version += versionpart << shift; + index += 1; + } + version +} + struct Logger { callback: native::WGPULogCallback, initialized: bool,