Skip to content

Commit

Permalink
Fix binary releases (#92)
Browse files Browse the repository at this point in the history
* make builds every time (but release only on tags)

* fix libclang issue for windows

* include webgpu.h

* re-implement wgpuGetVersion

* Tweak versioning

* comment

* try to fix linux32 ci build

* run release-builds on release only

* adjust comment
  • Loading branch information
almarklein authored Apr 28, 2021
1 parent f534de7 commit 691468c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
42 changes: 31 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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/)).
Expand All @@ -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 }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}));
Expand Down
26 changes: 26 additions & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>() {
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,
Expand Down

0 comments on commit 691468c

Please sign in to comment.