From ab7fa12f72be67d475b8cb80fe614c18f53eeae2 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 27 Feb 2022 00:02:26 -0700 Subject: [PATCH] gpu-dawn: include full target triple in binary releases Fixes hexops/mach#170 Signed-off-by: Stephen Gutekanst --- .github/workflows/ci.yml | 24 ++++++++++++------------ .github/workflows/m1_ci.yml | 12 ++++++------ build.zig | 28 ++++++++++------------------ 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56848c618..db719a928 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,18 +23,18 @@ jobs: run: zig build install -Dfrom-source=true -Dtarget=x86_64-linux - name: upload (debug) run: | - mv zig-out/lib/libdawn.a zig-out/lib/libdawn_linux-x86_64_debug.a - gzip -9 zig-out/lib/libdawn_linux-x86_64_debug.a - gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_linux-x86_64_debug.a.gz + mv zig-out/lib/libdawn.a zig-out/lib/libdawn_x86_64-linux-gnu_debug.a + gzip -9 zig-out/lib/libdawn_x86_64-linux-gnu_debug.a + gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_x86_64-linux-gnu_debug.a.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: install (release-fast) run: zig build install -Dfrom-source=true -Drelease-fast=true -Dtarget=x86_64-linux - name: upload (release-fast) run: | - mv zig-out/lib/libdawn.a zig-out/lib/libdawn_linux-x86_64_release-fast.a - gzip -9 zig-out/lib/libdawn_linux-x86_64_release-fast.a - gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_linux-x86_64_release-fast.a.gz + mv zig-out/lib/libdawn.a zig-out/lib/libdawn_x86_64-linux-gnu_release-fast.a + gzip -9 zig-out/lib/libdawn_x86_64-linux-gnu_release-fast.a + gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_x86_64-linux-gnu_release-fast.a.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # TODO(build-system): enable windows CI here once gpu-dawn builds under Windows @@ -77,9 +77,9 @@ jobs: AGREE: true - name: upload (debug) run: | - mv zig-out/lib/libdawn.a zig-out/lib/libdawn_macos-x86_64_debug.a - gzip -9 zig-out/lib/libdawn_macos-x86_64_debug.a - gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_macos-x86_64_debug.a.gz + mv zig-out/lib/libdawn.a zig-out/lib/libdawn_x86_64-macos.12.1...12.1-gnu_debug.a + gzip -9 zig-out/lib/libdawn_x86_64-macos.12.1...12.1-gnu_debug.a + gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_x86_64-macos.12.1...12.1-gnu_debug.a.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: install (release-fast) @@ -88,8 +88,8 @@ jobs: AGREE: true - name: upload (release-fast) run: | - mv zig-out/lib/libdawn.a zig-out/lib/libdawn_macos-x86_64_release-fast.a - gzip -9 zig-out/lib/libdawn_macos-x86_64_release-fast.a - gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_macos-x86_64_release-fast.a.gz + mv zig-out/lib/libdawn.a zig-out/lib/libdawn_x86_64-macos.12.1...12.1-gnu_release-fast.a + gzip -9 zig-out/lib/libdawn_x86_64-macos.12.1...12.1-gnu_release-fast.a + gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_x86_64-macos.12.1...12.1-gnu_release-fast.a.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/m1_ci.yml b/.github/workflows/m1_ci.yml index 87904baa7..9db46aeed 100644 --- a/.github/workflows/m1_ci.yml +++ b/.github/workflows/m1_ci.yml @@ -29,9 +29,9 @@ jobs: AGREE: true - name: upload (debug) run: | - mv zig-out/lib/libdawn.a zig-out/lib/libdawn_macos-aarch64_debug.a - gzip -9 zig-out/lib/libdawn_macos-aarch64_debug.a - gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_macos-aarch64_debug.a.gz + mv zig-out/lib/libdawn.a zig-out/lib/libdawn_aarch64-macos.12.1...12.1-gnu_debug.a + gzip -9 zig-out/lib/libdawn_aarch64-macos.12.1...12.1-gnu_debug.a + gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_aarch64-macos.12.1...12.1-gnu_debug.a.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: install (release-fast) @@ -40,8 +40,8 @@ jobs: AGREE: true - name: upload (release-fast) run: | - mv zig-out/lib/libdawn.a zig-out/lib/libdawn_macos-aarch64_release-fast.a - gzip -9 zig-out/lib/libdawn_macos-aarch64_release-fast.a - gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_macos-aarch64_release-fast.a.gz + mv zig-out/lib/libdawn.a zig-out/lib/libdawn_aarch64-macos.12.1...12.1-gnu_release-fast.a + gzip -9 zig-out/lib/libdawn_aarch64-macos.12.1...12.1-gnu_release-fast.a + gh release upload "release-$(git rev-parse --short HEAD)" zig-out/lib/libdawn_aarch64-macos.12.1...12.1-gnu_release-fast.a.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.zig b/build.zig index c116dc18a..9d967bded 100644 --- a/build.zig +++ b/build.zig @@ -191,24 +191,16 @@ fn ensureSubmodules(allocator: std.mem.Allocator) !void { pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void { const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target; - // If it's not the default ABI, we have no binaries available. - const default_abi = std.Target.Abi.default(target.cpu.arch, target.os); - if (target.abi != default_abi) return linkFromSource(b, step, options); - - const triple = blk: { - if (target.cpu.arch.isX86()) switch (target.os.tag) { - .windows => return linkFromSource(b, step, options), // break :blk "windows-x86_64", - .linux => break :blk "linux-x86_64", - .macos => break :blk "macos-x86_64", - else => return linkFromSource(b, step, options), - }; - if (target.cpu.arch.isAARCH64()) switch (target.os.tag) { - .macos => break :blk "macos-aarch64", - else => return linkFromSource(b, step, options), - }; - return linkFromSource(b, step, options); + const have_binaries = switch (target.os.tag) { + .windows => false, // TODO(build-system): add Windows binaries + .linux => target.cpu.arch.isX86() and target.abi.isGnu(), + .macos => (target.cpu.arch.isX86() or target.cpu.arch.isAARCH64()) and target.abi == .macabi, + else => false, }; - ensureBinaryDownloaded(b.allocator, triple, b.is_release, options.binary_version); + if (!have_binaries) return linkFromSource(b, step, options); + + const zig_triple = target.zigTriple(b.allocator) catch unreachable; + ensureBinaryDownloaded(b.allocator, zig_triple, b.is_release, options.binary_version); const current_git_commit = getCurrentGitCommit(b.allocator) catch unreachable; const base_cache_dir_rel = std.fs.path.join(b.allocator, &.{ "zig-cache", "mach", "gpu-dawn" }) catch unreachable; @@ -216,7 +208,7 @@ pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Opti const base_cache_dir = std.fs.cwd().realpathAlloc(b.allocator, base_cache_dir_rel) catch unreachable; const commit_cache_dir = std.fs.path.join(b.allocator, &.{ base_cache_dir, current_git_commit }) catch unreachable; const release_tag = if (b.is_release) "release-fast" else "debug"; - const target_cache_dir = std.fs.path.join(b.allocator, &.{ commit_cache_dir, triple, release_tag }) catch unreachable; + const target_cache_dir = std.fs.path.join(b.allocator, &.{ commit_cache_dir, zig_triple, release_tag }) catch unreachable; step.addLibraryPath(target_cache_dir); step.linkSystemLibrary("dawn");