From a97924f884e6b62c0e775bf311a7b35c4e74dfc9 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 8 Jul 2023 14:34:35 -0700 Subject: [PATCH] gpu-dawn: move to github.com/hexops/mach-gpu-dawn Signed-off-by: Stephen Gutekanst --- libs/gpu-dawn/.gitattributes | 2 - libs/gpu-dawn/.github/FUNDING.yml | 1 - .../gpu-dawn/.github/pull_request_template.md | 5 - libs/gpu-dawn/.github/workflows/ci.yml | 249 --- .../.github/workflows/draft_release.yml | 16 - libs/gpu-dawn/.github/workflows/m1_ci.yml | 35 - .../.github/workflows/publish_release.yml | 45 - libs/gpu-dawn/.gitignore | 21 - libs/gpu-dawn/LICENSE | 13 - libs/gpu-dawn/LICENSE-APACHE | 202 -- libs/gpu-dawn/LICENSE-MIT | 25 - libs/gpu-dawn/README.md | 98 - libs/gpu-dawn/build.zig | 1752 ----------------- libs/gpu-dawn/build.zig.zon | 30 - libs/gpu-dawn/dev/bundle-release.sh | 30 - libs/gpu-dawn/dev/dir_to_json.py | 12 - libs/gpu-dawn/dev/upload-release.sh | 26 - libs/gpu-dawn/src/dawn/mingw_helpers.cpp | 56 - .../src/dawn/zig_mingw_pthread/pthread.h | 0 libs/gpu-dawn/src/main.zig | 1 - 20 files changed, 2619 deletions(-) delete mode 100644 libs/gpu-dawn/.gitattributes delete mode 100644 libs/gpu-dawn/.github/FUNDING.yml delete mode 100644 libs/gpu-dawn/.github/pull_request_template.md delete mode 100644 libs/gpu-dawn/.github/workflows/ci.yml delete mode 100644 libs/gpu-dawn/.github/workflows/draft_release.yml delete mode 100644 libs/gpu-dawn/.github/workflows/m1_ci.yml delete mode 100644 libs/gpu-dawn/.github/workflows/publish_release.yml delete mode 100644 libs/gpu-dawn/.gitignore delete mode 100644 libs/gpu-dawn/LICENSE delete mode 100644 libs/gpu-dawn/LICENSE-APACHE delete mode 100644 libs/gpu-dawn/LICENSE-MIT delete mode 100644 libs/gpu-dawn/README.md delete mode 100644 libs/gpu-dawn/build.zig delete mode 100644 libs/gpu-dawn/build.zig.zon delete mode 100755 libs/gpu-dawn/dev/bundle-release.sh delete mode 100644 libs/gpu-dawn/dev/dir_to_json.py delete mode 100755 libs/gpu-dawn/dev/upload-release.sh delete mode 100644 libs/gpu-dawn/src/dawn/mingw_helpers.cpp delete mode 100644 libs/gpu-dawn/src/dawn/zig_mingw_pthread/pthread.h delete mode 100644 libs/gpu-dawn/src/main.zig diff --git a/libs/gpu-dawn/.gitattributes b/libs/gpu-dawn/.gitattributes deleted file mode 100644 index ba1273bd..00000000 --- a/libs/gpu-dawn/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -* text=auto eol=lf -upstream/** linguist-vendored diff --git a/libs/gpu-dawn/.github/FUNDING.yml b/libs/gpu-dawn/.github/FUNDING.yml deleted file mode 100644 index 99fd1066..00000000 --- a/libs/gpu-dawn/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -github: slimsag diff --git a/libs/gpu-dawn/.github/pull_request_template.md b/libs/gpu-dawn/.github/pull_request_template.md deleted file mode 100644 index 390d0a35..00000000 --- a/libs/gpu-dawn/.github/pull_request_template.md +++ /dev/null @@ -1,5 +0,0 @@ -Please send your change to [the main repository](https://github.com/hexops/mach/tree/main/libs/gpu-dawn) instead, sorry for the trouble! - -This helps us avoid some complex merge conflicts we run into when changes are made to both repositories and history needs to be reconciled. Keeping PRs in just that repository enables us to use `git subtree` to trivially keep the two repositories in sync. - -Once your PR is merged over there, it'll automatically sync to this repository. diff --git a/libs/gpu-dawn/.github/workflows/ci.yml b/libs/gpu-dawn/.github/workflows/ci.yml deleted file mode 100644 index 420b6fb9..00000000 --- a/libs/gpu-dawn/.github/workflows/ci.yml +++ /dev/null @@ -1,249 +0,0 @@ -name: CI -on: - workflow_run: - workflows: ["Draft release"] - types: - - completed -jobs: - x86_64-linux-gnu_debug: - runs-on: ubuntu-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Zig - run: | - sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - - name: install (debug) - run: zig build install # -Dtarget=x86_64-linux-gnu # TODO(libx11) https://github.com/hexops/mach/issues/845 - - name: upload (debug) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: x86_64-linux-gnu_debug - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - x86_64-linux-gnu_release-fast: - runs-on: ubuntu-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Zig - run: | - sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - - name: install (release-fast) - run: zig build install -Doptimize=ReleaseFast # -Dtarget=x86_64-linux-gnu # TODO(libx11) https://github.com/hexops/mach/issues/845 - - name: upload (release-fast) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: x86_64-linux-gnu_release-fast - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # TODO(libx11) https://github.com/hexops/mach/issues/845 - # x86_64-linux-musl_debug: - # runs-on: ubuntu-latest - # # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # # to the branch. - # if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - # steps: - # - name: Checkout - # uses: actions/checkout@v2 - # - name: Setup Zig - # run: | - # sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - # sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - # - name: install (debug) - # run: zig build install -Dtarget=x86_64-linux-musl - # - name: upload (debug) - # run: ./dev/upload-release.sh - # env: - # RELEASE_NAME: x86_64-linux-musl_debug - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # x86_64-linux-musl_release-fast: - # runs-on: ubuntu-latest - # # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # # to the branch. - # if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - # steps: - # - name: Checkout - # uses: actions/checkout@v2 - # - name: Setup Zig - # run: | - # sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - # sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - # - name: install (release-fast) - # run: zig build install -Doptimize=ReleaseFast -Dtarget=x86_64-linux-musl - # - name: upload (release-fast) - # run: ./dev/upload-release.sh - # env: - # RELEASE_NAME: x86_64-linux-musl_release-fast - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - aarch64-linux-gnu_debug: - runs-on: ubuntu-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Zig - run: | - sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - - name: install (debug) - run: zig build install # -Dtarget=aarch64-linux-gnu # TODO(libx11) https://github.com/hexops/mach/issues/845 - - name: upload (debug) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: aarch64-linux-gnu_debug - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - aarch64-linux-gnu_release-fast: - runs-on: ubuntu-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Zig - run: | - sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - - name: install (release-fast) - run: zig build install -Doptimize=ReleaseFast # -Dtarget=aarch64-linux-gnu # TODO(libx11) https://github.com/hexops/mach/issues/845 - - name: upload (release-fast) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: aarch64-linux-gnu_release-fast - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # TODO(libx11) https://github.com/hexops/mach/issues/845 - # aarch64-linux-musl_debug: - # runs-on: ubuntu-latest - # # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # # to the branch. - # if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - # steps: - # - name: Checkout - # uses: actions/checkout@v2 - # - name: Setup Zig - # run: | - # sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - # sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - # - name: install (debug) - # run: zig build install -Dtarget=aarch64-linux-musl - # - name: upload (debug) - # run: ./dev/upload-release.sh - # env: - # RELEASE_NAME: aarch64-linux-musl_debug - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # aarch64-linux-musl_release-fast: - # runs-on: ubuntu-latest - # # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # # to the branch. - # if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - # steps: - # - name: Checkout - # uses: actions/checkout@v2 - # - name: Setup Zig - # run: | - # sudo apt install xz-utils libx11-dev # TODO(libx11) https://github.com/hexops/mach/issues/845 - # sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - # - name: install (release-fast) - # run: zig build install -Doptimize=ReleaseFast -Dtarget=aarch64-linux-musl - # - name: upload (release-fast) - # run: ./dev/upload-release.sh - # env: - # RELEASE_NAME: aarch64-linux-musl_release-fast - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - x86_64-windows-gnu_debug: - runs-on: windows-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Zig - run: | - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -Uri "https://ziglang.org/builds/zig-windows-x86_64-0.11.0-dev.3883+7166407d8.zip" -OutFile "C:\zig.zip" - cd C:\ - 7z x zig.zip - Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.11.0-dev.3883+7166407d8\" - - name: install (debug) - run: zig build install -Dtarget=x86_64-windows-gnu - - name: upload (debug) - run: ./dev/upload-release.sh - shell: bash - env: - WINDOWS: true - RELEASE_NAME: x86_64-windows-gnu_debug - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - x86_64-windows-gnu_release-fast: - runs-on: windows-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Zig - run: | - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -Uri "https://ziglang.org/builds/zig-windows-x86_64-0.11.0-dev.3883+7166407d8.zip" -OutFile "C:\zig.zip" - cd C:\ - 7z x zig.zip - Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.11.0-dev.3883+7166407d8\" - - name: install (release-fast) - run: zig build install -Dtarget=x86_64-windows-gnu -Doptimize=ReleaseFast - - name: upload (release-fast) - run: ./dev/upload-release.sh - shell: bash - env: - WINDOWS: true - RELEASE_NAME: x86_64-windows-gnu_release-fast - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - x86_64-macos_debug: - runs-on: macos-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Zig - run: | - brew uninstall --ignore-dependencies libx11 # https://github.com/ziglang/zig/issues/11066 - brew install xz - sudo sh -c 'wget -c https://ziglang.org/builds/zig-macos-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - - name: install (debug) - run: zig build install -Dtarget=x86_64-macos - - name: upload (debug) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: x86_64-macos-none_debug - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - x86_64-macos_release-fast: - runs-on: macos-latest - # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push - # to the branch. - if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Zig - run: | - brew uninstall --ignore-dependencies libx11 # https://github.com/ziglang/zig/issues/11066 - brew install xz - sudo sh -c 'wget -c https://ziglang.org/builds/zig-macos-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin' - - name: install (release-fast) - run: zig build install -Doptimize=ReleaseFast -Dtarget=x86_64-macos - - name: upload (release-fast) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: x86_64-macos-none_release-fast - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/libs/gpu-dawn/.github/workflows/draft_release.yml b/libs/gpu-dawn/.github/workflows/draft_release.yml deleted file mode 100644 index d3f5c27d..00000000 --- a/libs/gpu-dawn/.github/workflows/draft_release.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Draft release -on: - push: - branches: - - 'main' -jobs: - draft: - if: ${{ !contains(github.event.head_commit.message, 'update to latest binary release') }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Create draft - run: gh release create "release-$(git rev-parse --short HEAD)" --title "Automatic release of main @ $(git rev-parse --short HEAD)" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/libs/gpu-dawn/.github/workflows/m1_ci.yml b/libs/gpu-dawn/.github/workflows/m1_ci.yml deleted file mode 100644 index b06c77ed..00000000 --- a/libs/gpu-dawn/.github/workflows/m1_ci.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: M1 -on: - workflow_run: - workflows: ["Draft release"] - types: - - completed -jobs: - aarch64-macos: - if: ${{ github.repository == 'hexops/mach-gpu-dawn' && github.event.workflow_run.conclusion == 'success' }} - runs-on: [self-hosted, macOS, ARM64] - defaults: - run: - shell: "/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}" - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: install (debug) - run: zig build install -Dtarget=aarch64-macos - - name: upload (debug) - run: | - ./dev/upload-release.sh - # HACK: without this we encounter error: StreamTooLong on the next `zig build` below. - # no clue why. - rm -rf zig-cache zig-out - env: - RELEASE_NAME: aarch64-macos-none_debug - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: install (release-fast) - run: zig build install -Doptimize=ReleaseFast -Dtarget=aarch64-macos - - name: upload (release-fast) - run: ./dev/upload-release.sh - env: - RELEASE_NAME: aarch64-macos-none_release-fast - UPLOAD_HEADERS: true - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/libs/gpu-dawn/.github/workflows/publish_release.yml b/libs/gpu-dawn/.github/workflows/publish_release.yml deleted file mode 100644 index dcaee665..00000000 --- a/libs/gpu-dawn/.github/workflows/publish_release.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Publish release -on: - workflow_run: - workflows: ["CI"] - types: - - completed -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true -jobs: - publish: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Record latest release version - id: recorded_release_version - # Note: we find the latest non-'update to latest binary release' commit here, which is not - # necessarily HEAD because another build could have succeeded before us and HEAD may now refer - # to 'update to latest binary release' instead of the commit we were building. - # By doing this, we ensure any update we push would refer to the absolute latest binary - # release even if *this* CI run is older. - run: echo "recorded_release_version=$(git log --oneline | grep -v 'update to latest binary release' | head -n1 | cut -d " " -f1)" >> $GITHUB_ENV - # - name: Publish release - # run: echo "TODO(build-system): gh CLI has no way to mark draft as published?" - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout hexops/mach monorepo - uses: actions/checkout@v2 - with: - repository: hexops/mach - token: ${{ secrets.HEXOPS_MACH_GPU_DAWN_PUSH }} - - name: 'gpu/dawn: update hard-coded binary release version' - env: - RELEASE_COMMIT: ${{env.recorded_release_version}} - run: | - sed -i "/binary_version: \[\]const u8 =/c\ binary_version: []const u8 = \"release-$RELEASE_COMMIT\"," ./libs/gpu-dawn/build.zig - - name: 'gpu/dawn: use latest binary release' - run: | - git config user.name 'Release automation' - git config user.email 'stephen@hexops.com' - git add . - git commit -m 'gpu-dawn: update to latest binary release' - git push -u origin HEAD diff --git a/libs/gpu-dawn/.gitignore b/libs/gpu-dawn/.gitignore deleted file mode 100644 index ea8441ad..00000000 --- a/libs/gpu-dawn/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -# This file is for zig-specific build artifacts. -# If you have OS-specific or editor-specific files to ignore, -# such as *.swp or .DS_Store, put those in your global -# ~/.gitignore and put this in your ~/.gitconfig: -# -# [core] -# excludesfile = ~/.gitignore -# -# Cheers! -# -andrewrk - -zig-cache/ -zig-out/ -/release/ -/debug/ -/build/ -/build-*/ -/docgen_tmp/ - -libs/DirectXShaderCompiler -libs/dawn \ No newline at end of file diff --git a/libs/gpu-dawn/LICENSE b/libs/gpu-dawn/LICENSE deleted file mode 100644 index ba6099da..00000000 --- a/libs/gpu-dawn/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2021, Hexops Contributors (given via the Git commit history). - -All documentation, image, sound, font, and 2D/3D model files are CC-BY-4.0 licensed unless -otherwise noted. You may get a copy of this license at https://creativecommons.org/licenses/by/4.0 - -Files in a directory with a separate LICENSE file may contain files under different license terms, -described within that LICENSE file. - -All other files are licensed under the Apache License, Version 2.0 (see LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) -or the MIT license (see LICENSE-MIT or http://opensource.org/licenses/MIT), at your option. - -All files in the project without exclusions may not be copied, modified, or distributed except -according to the terms above. \ No newline at end of file diff --git a/libs/gpu-dawn/LICENSE-APACHE b/libs/gpu-dawn/LICENSE-APACHE deleted file mode 100644 index d6456956..00000000 --- a/libs/gpu-dawn/LICENSE-APACHE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/libs/gpu-dawn/LICENSE-MIT b/libs/gpu-dawn/LICENSE-MIT deleted file mode 100644 index 14cd7973..00000000 --- a/libs/gpu-dawn/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2021 Hexops Contributors (given via the Git commit history). - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/libs/gpu-dawn/README.md b/libs/gpu-dawn/README.md deleted file mode 100644 index 06998f63..00000000 --- a/libs/gpu-dawn/README.md +++ /dev/null @@ -1,98 +0,0 @@ -# mach/gpu-dawn, WebGPU/Dawn built with Zig Hexops logo - -`mach/gpu-dawn` builds [Dawn](https://dawn.googlesource.com/dawn/), Google Chrome's WebGPU implementation, requiring nothing more than `zig` and `git` to build and cross-compile a static Dawn library for every OS: - -* No cmake -* No ninja -* No `gn` -* No system dependencies (xcode, etc.) -* Automagic cross compilation out of the box with nothing more than `zig` and `git`! -* Builds a single static `libdawn.a` with everything you need. - -This repository is a separate copy of the same library in the [main Mach repository](https://github.com/hexops/mach), and is automatically kept in sync, so that anyone can use this library in their own project / engine if they like! - -## Building from source - -Building Dawn from source using this method is simple: - -```sh -git clone https://github.com/hexops/mach-gpu-dawn -cd mach-gpu-dawn - -rm -rf libs/mach-glfw -git clone --recursive https://github.com/hexops/mach-glfw libs/mach-glfw - -zig build -``` - -(Please make sure to use Zig nightly, e.g. v0.10, not v0.9, which you can get a binary release of at the very top of this page: https://ziglang.org/download/) - -This will take ~10 minutes to finish (see the 'binary releases' section below.) You can add the following options: - -| Option | Description | -|-------------------------------|------------------------------------------------------------| -| `-Doptimize=ReleaseFast` | Build a release binary instead of a debug binary (default) | -| `-Dtarget=x86_64-macos` | Cross compile to macOS (Intel chipsets) | -| `-Dtarget=aarch64-macos` | Cross compile to macOS (Apple Silicon) | -| `-Dtarget=x86_64-linux-gnu` | Cross compile to x86_64 Linux (glibc) | -| `-Dtarget=x86_64-linux-musl` | Cross compile to x86_64 Linux (musl libc) | -| `-Dtarget=x86_64-windows-gnu` | Cross compile to x86_64 Windows | - -The following platforms are not yet supported, but we hope to support soon: - -* iOS (Dawn does not officially support it yet) -* Android (Dawn does not officially support it yet) -* ARM Linux (aarch64) -* Windows msvc target (Zig targets MinGW libc on Windows currently, msvc support should not be hard to add.) - -## Binary releases - -Dawn (specifically all the shader compilers, and the DirectXShaderCompiler) is a large C++ codebase and takes 5-10 minutes to build on a modern laptop. Since waiting is no fun, we also have binary releases produced by our GitHub actions: - -**[View binary releases](https://github.com/hexops/mach-gpu-dawn/releases/latest)** - -Here's how to read the downloads provided: - -* `_debug.tar.gz` and `_release-fast.tar.gz` are tarballs of the static library + headers for each OS and debug/release mode, respectively. -* `headers.json.gz` is a JSON archive of all the Dawn/WebGPU headers. -* Files ending in `.a.gz` and `.lib.gz` are the individual static `libdawn.a` and `dawn.lib` (Windows) gzippped and distributed. These are provided as individual downloads so there is no need to extract a tarball. - -## Important: Building WebGPU API symbols - -Dawn and other WebGPU implementations (like the Rust one) do not agree on a standard `webgpu.h` API. Aspirationally, they aim to target the same https://github.com/webgpu-native/webgpu-headers header, but in practice they expose different APIs which are not ABI compatible. - -When you call a Dawn `webgpu.h` function, Dawn internally diverts this call through a vtable which must be initialized using a call to `dawnProcSetProcs`. - -`mach/gpu-dawn` builds since Oct 17th 2022 no longer include the `webgpu.h` symbols by default. If you intend to actually call the WebGPU API, you should build these two source files as part of your application: - -1. [`dawn_proc.c`](https://raw.githubusercontent.com/hexops/dawn/generated-2023-06-30.1688174725/out/Debug/gen/src/dawn/dawn_proc.c) -2. [`webgpu_dawn_native_proc.cpp`](https://raw.githubusercontent.com/hexops/dawn/generated-2023-06-30.1688174725/out/Debug/gen/src/dawn/native/webgpu_dawn_native_proc.cpp) - -And call `dawnProcSetProcs` to set up the proc table. - -## A warning about API stability - -You should be aware: - -* WebGPU's API is not formalized yet. -* Dawn's API is still changing. -* The `webgpu.h` API is still changing -* Dawn and gfx-rs/wgpu, although both try to implement `webgpu.h`, do not exactly implement the same interface. There are subtle differences in device discovery & creation for example. - -## Generated code - -Dawn itself relies on a fairly large amount of dependencies, generated code, etc. To avoid having any dependency on Google build tools, code generation, etc. we maintain [a minor fork of Dawn which has generated code and third-party dependencies comitted in "generated" branches.](https://github.com/hexops/dawn/tree/main/mach) We are usually up-to-date with the upstream within a few weeks on average. - -It also provides a [few small patches to enable building Dawn with the Zig compiler](https://github.com/hexops/mach/issues/168) which we plan to upstream soon, as well as some [patches to build the DirectXShaderCompiler with Zig](https://github.com/hexops/mach/issues/151). - -## Join the community - -Join the Mach engine community [on Discord](https://discord.gg/XNG3NZgCqp) to discuss this project, ask questions, get help, etc. - -## Issues - -Issues are tracked in the [main Mach repository](https://github.com/hexops/mach/issues?q=is%3Aissue+is%3Aopen+label%3Agpu-dawn). - -## License - -All Mach code (this repository) is under the Apache and MIT license at your choosing described in the `LICENSE` file. Dawn itself is [similarly permissively licensed](https://github.com/hexops/dawn/blob/main/LICENSE). diff --git a/libs/gpu-dawn/build.zig b/libs/gpu-dawn/build.zig deleted file mode 100644 index 822f7a19..00000000 --- a/libs/gpu-dawn/build.zig +++ /dev/null @@ -1,1752 +0,0 @@ -const std = @import("std"); -const Build = std.Build; - -pub fn build(b: *Build) !void { - const optimize = b.standardOptimizeOption(.{}); - const target = b.standardTargetOptions(.{}); - - const options = Options{ - .install_libs = true, - .from_source = true, - }; - // Just to demonstrate/test linking. This is not a functional example, see the mach/gpu examples - // or Dawn C++ examples for functional example code. - const example = b.addExecutable(.{ - .name = "dawn-example", - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, - }); - try link(b, example, options); - const glfw_dep = b.dependency("mach_glfw", .{ - .target = example.target, - .optimize = example.optimize, - }); - example.linkLibrary(glfw_dep.artifact("mach-glfw")); - example.addModule("mach-glfw", glfw_dep.module("mach-glfw")); - b.installArtifact(example); -} - -pub const Options = struct { - /// Defaults to true on Windows - d3d12: ?bool = null, - - /// Defaults to true on Darwin - metal: ?bool = null, - - /// Defaults to true on Linux, Fuchsia - // TODO(build-system): enable on Windows if we can cross compile Vulkan - vulkan: ?bool = null, - - /// Defaults to true on Linux - desktop_gl: ?bool = null, - - /// Defaults to true on Android, Linux, Windows, Emscripten - // TODO(build-system): not respected at all currently - opengl_es: ?bool = null, - - /// Whether or not minimal debug symbols should be emitted. This is -g1 in most cases, enough to - /// produce stack traces but omitting debug symbols for locals. For spirv-tools and tint in - /// specific, -g0 will be used (no debug symbols at all) to save an additional ~39M. - debug: bool = false, - - /// Whether or not to produce separate static libraries for each component of Dawn (reduces - /// iteration times when building from source / testing changes to Dawn source code.) - separate_libs: bool = false, - - /// Whether or not to produce shared libraries instead of static ones - shared_libs: bool = false, - - /// Whether to build Dawn from source or not. - from_source: bool = false, - - /// Produce static libraries at zig-out/lib - install_libs: bool = false, - - /// The binary release version to use from https://github.com/hexops/mach-gpu-dawn/releases - binary_version: []const u8 = "release-ac4e82f", - - /// Detects the default options to use for the given target. - pub fn detectDefaults(self: Options, target: std.Target) Options { - const tag = target.os.tag; - - var options = self; - if (options.d3d12 == null) options.d3d12 = tag == .windows; - if (options.metal == null) options.metal = tag.isDarwin(); - if (options.vulkan == null) options.vulkan = tag == .fuchsia or isLinuxDesktopLike(tag); - - // TODO(build-system): technically Dawn itself defaults desktop_gl to true on Windows. - if (options.desktop_gl == null) options.desktop_gl = isLinuxDesktopLike(tag); - - // TODO(build-system): OpenGL ES - options.opengl_es = false; - // if (options.opengl_es == null) options.opengl_es = tag == .windows or tag == .emscripten or target.isAndroid() or linux_desktop_like; - - return options; - } -}; - -pub fn link(b: *Build, step: *std.build.CompileStep, options: Options) !void { - const opt = options.detectDefaults(step.target_info.target); - - if (step.target_info.target.os.tag == .windows) @import("direct3d_headers").addLibraryPath(step); - if (step.target_info.target.os.tag == .macos) { - // TODO(build-system): This cannot be imported with the Zig package manager - // error: TarUnsupportedFileType - // - // step.linkLibrary(b.dependency("xcode_frameworks", .{ - // .target = step.target, - // .optimize = step.optimize, - // }).artifact("xcode-frameworks")); - // @import("xcode_frameworks").addPaths(step); - xcode_frameworks.addPaths(b, step); - } - - try if (options.from_source) - linkFromSource(b, step, opt) - else - linkFromBinary(b, step, opt); -} - -fn linkFromSource(b: *Build, step: *std.build.CompileStep, options: Options) !void { - try ensureGitRepoCloned(b.allocator, "https://github.com/hexops/dawn", "generated-2023-06-30.1688174725", sdkPath("/libs/dawn")); - - // branch: mach - try ensureGitRepoCloned(b.allocator, "https://github.com/hexops/DirectXShaderCompiler", "cff9a6f0b7f961748b822e1d313a7205dfdecf9d", sdkPath("/libs/DirectXShaderCompiler")); - - step.addIncludePath(sdkPath("/libs/dawn/out/Debug/gen/include")); - step.addIncludePath(sdkPath("/libs/dawn/include")); - step.addIncludePath(sdkPath("/src/dawn")); - - if (options.separate_libs) { - const lib_dawn_common = try buildLibDawnCommon(b, step, options); - const lib_dawn_platform = try buildLibDawnPlatform(b, step, options); - const lib_abseil_cpp = try buildLibAbseilCpp(b, step, options); - const lib_dawn_native = try buildLibDawnNative(b, step, options); - const lib_dawn_wire = try buildLibDawnWire(b, step, options); - const lib_spirv_tools = try buildLibSPIRVTools(b, step, options); - const lib_tint = try buildLibTint(b, step, options); - - step.linkLibrary(lib_dawn_common); - step.linkLibrary(lib_dawn_platform); - step.linkLibrary(lib_abseil_cpp); - step.linkLibrary(lib_dawn_native); - step.linkLibrary(lib_dawn_wire); - step.linkLibrary(lib_spirv_tools); - step.linkLibrary(lib_tint); - - if (options.d3d12.?) { - const lib_dxcompiler = try buildLibDxcompiler(b, step, options); - step.linkLibrary(lib_dxcompiler); - } - return; - } - - const lib_dawn = if (options.shared_libs) b.addSharedLibrary(.{ - .name = "dawn", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "dawn", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - step.linkLibrary(lib_dawn); - - _ = try buildLibDawnCommon(b, lib_dawn, options); - _ = try buildLibDawnPlatform(b, lib_dawn, options); - _ = try buildLibAbseilCpp(b, lib_dawn, options); - _ = try buildLibDawnNative(b, lib_dawn, options); - _ = try buildLibDawnWire(b, lib_dawn, options); - _ = try buildLibSPIRVTools(b, lib_dawn, options); - _ = try buildLibTint(b, lib_dawn, options); - if (options.d3d12.?) _ = try buildLibDxcompiler(b, lib_dawn, options); -} - -fn ensureGitRepoCloned(allocator: std.mem.Allocator, clone_url: []const u8, revision: []const u8, dir: []const u8) !void { - if (isEnvVarTruthy(allocator, "NO_ENSURE_SUBMODULES") or isEnvVarTruthy(allocator, "NO_ENSURE_GIT")) { - return; - } - - ensureGit(allocator); - - if (std.fs.openDirAbsolute(dir, .{})) |_| { - const current_revision = try getCurrentGitRevision(allocator, dir); - if (!std.mem.eql(u8, current_revision, revision)) { - // Reset to the desired revision - exec(allocator, &[_][]const u8{ "git", "fetch" }, dir) catch |err| std.debug.print("warning: failed to 'git fetch' in {s}: {s}\n", .{ dir, @errorName(err) }); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - } - return; - } else |err| return switch (err) { - error.FileNotFound => { - std.log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, dir }); - - try exec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, dir }, sdkPath("/")); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - return; - }, - else => err, - }; -} - -fn exec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void { - var child = std.ChildProcess.init(argv, allocator); - child.cwd = cwd; - _ = try child.spawnAndWait(); -} - -fn getCurrentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 { - const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = &.{ "git", "rev-parse", "HEAD" }, .cwd = cwd }); - allocator.free(result.stderr); - if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline - return result.stdout; -} - -fn ensureGit(allocator: std.mem.Allocator) void { - const argv = &[_][]const u8{ "git", "--version" }; - const result = std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = argv, - .cwd = ".", - }) catch { // e.g. FileNotFound - std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - }; - defer { - allocator.free(result.stderr); - allocator.free(result.stdout); - } - if (result.term.Exited != 0) { - std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - } -} - -fn isEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool { - if (std.process.getEnvVarOwned(allocator, name)) |truthy| { - defer allocator.free(truthy); - if (std.mem.eql(u8, truthy, "true")) return true; - return false; - } else |_| { - return false; - } -} - -fn getGitHubBaseURLOwned(allocator: std.mem.Allocator) ![]const u8 { - if (std.process.getEnvVarOwned(allocator, "MACH_GITHUB_BASE_URL")) |base_url| { - std.log.info("mach: respecting MACH_GITHUB_BASE_URL: {s}\n", .{base_url}); - return base_url; - } else |_| { - return allocator.dupe(u8, "https://github.com"); - } -} - -pub fn linkFromBinary(b: *Build, step: *std.build.CompileStep, options: Options) !void { - const target = step.target_info.target; - const binaries_available = switch (target.os.tag) { - .windows => target.abi.isGnu(), - .linux => (target.cpu.arch.isX86() or target.cpu.arch.isAARCH64()) and (target.abi.isGnu() or target.abi.isMusl()), - .macos => blk: { - if (!target.cpu.arch.isX86() and !target.cpu.arch.isAARCH64()) break :blk false; - - // The minimum macOS version with which our binaries can be used. - const min_available = std.SemanticVersion{ .major = 11, .minor = 0, .patch = 0 }; - - // If the target version is >= the available version, then it's OK. - const order = target.os.version_range.semver.min.order(min_available); - break :blk (order == .gt or order == .eq); - }, - else => false, - }; - if (!binaries_available) { - const zig_triple = try target.zigTriple(b.allocator); - defer b.allocator.free(zig_triple); - std.log.err("gpu-dawn binaries for {s} not available.", .{zig_triple}); - std.log.err("-> open an issue: https://github.com/hexops/mach/issues", .{}); - std.log.err("-> build from source (takes 5-15 minutes):", .{}); - std.log.err(" use -Ddawn-from-source=true or set `Options.from_source = true`\n", .{}); - if (target.os.tag == .macos) { - std.log.err("", .{}); - if (target.cpu.arch.isX86()) std.log.err("-> Did you mean to use -Dtarget=x86_64-macos.12.0...13.1-none ?", .{}); - if (target.cpu.arch.isAARCH64()) std.log.err("-> Did you mean to use -Dtarget=aarch64-macos.12.0...13.1-none ?", .{}); - } - std.process.exit(1); - } - - // Remove OS version range / glibc version from triple (we do not include that in our download - // URLs.) - var binary_target = std.zig.CrossTarget.fromTarget(target); - binary_target.os_version_min = .{ .none = undefined }; - binary_target.os_version_max = .{ .none = undefined }; - binary_target.glibc_version = null; - const zig_triple = try binary_target.zigTriple(b.allocator); - defer b.allocator.free(zig_triple); - try ensureBinaryDownloaded(b.allocator, zig_triple, options.debug, target.os.tag == .windows, options.binary_version); - - const base_cache_dir_rel = try std.fs.path.join(b.allocator, &.{ "zig-cache", "mach", "gpu-dawn" }); - try std.fs.cwd().makePath(base_cache_dir_rel); - const base_cache_dir = try std.fs.cwd().realpathAlloc(b.allocator, base_cache_dir_rel); - const commit_cache_dir = try std.fs.path.join(b.allocator, &.{ base_cache_dir, options.binary_version }); - const release_tag = if (options.debug) "debug" else "release-fast"; - const target_cache_dir = try std.fs.path.join(b.allocator, &.{ commit_cache_dir, zig_triple, release_tag }); - const include_dir = try std.fs.path.join(b.allocator, &.{ commit_cache_dir, "include" }); - defer { - b.allocator.free(base_cache_dir); - b.allocator.free(commit_cache_dir); - b.allocator.free(target_cache_dir); - b.allocator.free(include_dir); - } - - step.addLibraryPath(target_cache_dir); - step.linkSystemLibraryName("dawn"); - step.linkLibCpp(); - - step.addIncludePath(include_dir); - step.addIncludePath(sdkPath("/src/dawn")); - - linkLibDawnCommonDependencies(b, step, options); - linkLibDawnPlatformDependencies(b, step, options); - linkLibDawnNativeDependencies(b, step, options); - linkLibTintDependencies(b, step, options); - linkLibSPIRVToolsDependencies(b, step, options); - linkLibAbseilCppDependencies(b, step, options); - linkLibDawnWireDependencies(b, step, options); - linkLibDxcompilerDependencies(b, step, options); -} - -pub fn ensureBinaryDownloaded( - allocator: std.mem.Allocator, - zig_triple: []const u8, - is_debug: bool, - is_windows: bool, - version: []const u8, -) !void { - // If zig-cache/mach/gpu-dawn/ does not exist: - // If on a commit in the main branch => rm -r zig-cache/mach/gpu-dawn/ - // else => noop - // If zig-cache/mach/gpu-dawn// exists: - // noop - // else: - // Download archive to zig-cache/mach/gpu-dawn/download/macos-aarch64 - // Extract to zig-cache/mach/gpu-dawn//macos-aarch64/libgpu.a - // Remove zig-cache/mach/gpu-dawn/download - - const base_cache_dir_rel = try std.fs.path.join(allocator, &.{ "zig-cache", "mach", "gpu-dawn" }); - try std.fs.cwd().makePath(base_cache_dir_rel); - const base_cache_dir = try std.fs.cwd().realpathAlloc(allocator, base_cache_dir_rel); - const commit_cache_dir = try std.fs.path.join(allocator, &.{ base_cache_dir, version }); - defer { - allocator.free(base_cache_dir_rel); - allocator.free(base_cache_dir); - allocator.free(commit_cache_dir); - } - - if (!dirExists(commit_cache_dir)) { - // Commit cache dir does not exist. If the commit we're on is in the main branch, we're - // probably moving to a newer commit and so we should cleanup older cached binaries. - const current_git_commit = try getCurrentGitCommit(allocator); - if (gitBranchContainsCommit(allocator, "main", current_git_commit) catch false) { - std.fs.deleteTreeAbsolute(base_cache_dir) catch {}; - } - } - - const release_tag = if (is_debug) "debug" else "release-fast"; - const target_cache_dir = try std.fs.path.join(allocator, &.{ commit_cache_dir, zig_triple, release_tag }); - defer allocator.free(target_cache_dir); - if (dirExists(target_cache_dir)) { - return; // nothing to do, already have the binary - } - downloadBinary(allocator, commit_cache_dir, release_tag, target_cache_dir, zig_triple, is_windows, version) catch |err| { - // A download failed, or extraction failed, so wipe out the directory to ensure we correctly - // try again next time. - std.fs.deleteTreeAbsolute(base_cache_dir) catch {}; - std.log.err("mach/gpu-dawn: prebuilt binary download failed: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn downloadBinary( - allocator: std.mem.Allocator, - commit_cache_dir: []const u8, - release_tag: []const u8, - target_cache_dir: []const u8, - zig_triple: []const u8, - is_windows: bool, - version: []const u8, -) !void { - ensureCanDownloadFiles(allocator); - - const download_dir = try std.fs.path.join(allocator, &.{ target_cache_dir, "download" }); - defer allocator.free(download_dir); - try std.fs.cwd().makePath(download_dir); - - // Replace "..." with "---" because GitHub releases has very weird restrictions on file names. - // https://twitter.com/slimsag/status/1498025997987315713 - const github_triple = try std.mem.replaceOwned(u8, allocator, zig_triple, "...", "---"); - defer allocator.free(github_triple); - - // Compose the download URL, e.g.: - // https://github.com/hexops/mach-gpu-dawn/releases/download/release-6b59025/libdawn_x86_64-macos-none_debug.a.gz - const github_base_url = try getGitHubBaseURLOwned(allocator); - defer allocator.free(github_base_url); - const lib_prefix = if (is_windows) "dawn_" else "libdawn_"; - const lib_ext = if (is_windows) ".lib" else ".a"; - const lib_file_name = if (is_windows) "dawn.lib" else "libdawn.a"; - const download_url = try std.mem.concat(allocator, u8, &.{ - github_base_url, - "/hexops/mach-gpu-dawn/releases/download/", - version, - "/", - lib_prefix, - github_triple, - "_", - release_tag, - lib_ext, - ".gz", - }); - defer allocator.free(download_url); - - // Download and decompress libdawn - const gz_target_file = try std.fs.path.join(allocator, &.{ download_dir, "compressed.gz" }); - defer allocator.free(gz_target_file); - try downloadFile(allocator, gz_target_file, download_url); - const target_file = try std.fs.path.join(allocator, &.{ target_cache_dir, lib_file_name }); - defer allocator.free(target_file); - try gzipDecompress(allocator, gz_target_file, target_file); - - // If we don't yet have the headers (these are shared across architectures), download them. - const include_dir = try std.fs.path.join(allocator, &.{ commit_cache_dir, "include" }); - defer allocator.free(include_dir); - if (!dirExists(include_dir)) { - // Compose the headers download URL, e.g.: - // https://github.com/hexops/mach-gpu-dawn/releases/download/release-6b59025/headers.json.gz - const headers_download_url = try std.mem.concat(allocator, u8, &.{ - github_base_url, - "/hexops/mach-gpu-dawn/releases/download/", - version, - "/headers.json.gz", - }); - defer allocator.free(headers_download_url); - - // Download and decompress headers.json.gz - const headers_gz_target_file = try std.fs.path.join(allocator, &.{ download_dir, "headers.json.gz" }); - defer allocator.free(headers_gz_target_file); - try downloadFile(allocator, headers_gz_target_file, headers_download_url); - const headers_target_file = try std.fs.path.join(allocator, &.{ target_cache_dir, "headers.json" }); - defer allocator.free(headers_target_file); - try gzipDecompress(allocator, headers_gz_target_file, headers_target_file); - - // Extract headers JSON archive. - try extractHeaders(allocator, headers_target_file, commit_cache_dir); - } - - try std.fs.deleteTreeAbsolute(download_dir); -} - -fn extractHeaders(allocator: std.mem.Allocator, json_file: []const u8, out_dir: []const u8) !void { - const contents = try std.fs.cwd().readFileAlloc(allocator, json_file, std.math.maxInt(usize)); - defer allocator.free(contents); - - var tree = try std.json.parseFromSlice(std.json.Value, allocator, contents, .{}); - defer tree.deinit(); - - var iter = tree.value.object.iterator(); - while (iter.next()) |f| { - const out_path = try std.fs.path.join(allocator, &.{ out_dir, f.key_ptr.* }); - defer allocator.free(out_path); - try std.fs.cwd().makePath(std.fs.path.dirname(out_path).?); - - var new_file = try std.fs.createFileAbsolute(out_path, .{}); - defer new_file.close(); - try new_file.writeAll(f.value_ptr.*.string); - } -} - -fn dirExists(path: []const u8) bool { - var dir = std.fs.openDirAbsolute(path, .{}) catch return false; - dir.close(); - return true; -} - -fn gzipDecompress(allocator: std.mem.Allocator, src_absolute_path: []const u8, dst_absolute_path: []const u8) !void { - var file = try std.fs.openFileAbsolute(src_absolute_path, .{ .mode = .read_only }); - defer file.close(); - - var buf_stream = std.io.bufferedReader(file.reader()); - var gzip_stream = try std.compress.gzip.decompress(allocator, buf_stream.reader()); - defer gzip_stream.deinit(); - - // Read and decompress the whole file - const buf = try gzip_stream.reader().readAllAlloc(allocator, std.math.maxInt(usize)); - defer allocator.free(buf); - - var new_file = try std.fs.createFileAbsolute(dst_absolute_path, .{}); - defer new_file.close(); - - try new_file.writeAll(buf); -} - -fn gitBranchContainsCommit(allocator: std.mem.Allocator, branch: []const u8, commit: []const u8) !bool { - const result = try std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = &.{ "git", "branch", branch, "--contains", commit }, - .cwd = sdkPath("/"), - }); - defer { - allocator.free(result.stdout); - allocator.free(result.stderr); - } - return result.term.Exited == 0; -} - -fn getCurrentGitCommit(allocator: std.mem.Allocator) ![]const u8 { - const result = try std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = &.{ "git", "rev-parse", "HEAD" }, - .cwd = sdkPath("/"), - }); - defer allocator.free(result.stderr); - if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline - return result.stdout; -} - -fn gitClone(allocator: std.mem.Allocator, repository: []const u8, dir: []const u8) !bool { - const result = try std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = &.{ "git", "clone", repository, dir }, - .cwd = sdkPath("/"), - }); - defer { - allocator.free(result.stdout); - allocator.free(result.stderr); - } - return result.term.Exited == 0; -} - -fn downloadFile(allocator: std.mem.Allocator, target_file: []const u8, url: []const u8) !void { - std.debug.print("downloading {s}..\n", .{url}); - - // Some Windows users experience `SSL certificate problem: unable to get local issuer certificate` - // so we give them the option to disable SSL if they desire / don't want to debug the issue. - var child = if (isEnvVarTruthy(allocator, "CURL_INSECURE")) - std.ChildProcess.init(&.{ "curl", "--insecure", "-L", "-o", target_file, url }, allocator) - else - std.ChildProcess.init(&.{ "curl", "-L", "-o", target_file, url }, allocator); - child.cwd = sdkPath("/"); - child.stderr = std.io.getStdErr(); - child.stdout = std.io.getStdOut(); - _ = try child.spawnAndWait(); -} - -fn ensureCanDownloadFiles(allocator: std.mem.Allocator) void { - const result = std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = &.{ "curl", "--version" }, - .cwd = sdkPath("/"), - }) catch { // e.g. FileNotFound - std.log.err("mach: error: 'curl --version' failed. Is curl not installed?", .{}); - std.process.exit(1); - }; - defer { - allocator.free(result.stderr); - allocator.free(result.stdout); - } - if (result.term.Exited != 0) { - std.log.err("mach: error: 'curl --version' failed. Is curl not installed?", .{}); - std.process.exit(1); - } -} - -fn isLinuxDesktopLike(tag: std.Target.Os.Tag) bool { - return switch (tag) { - .linux, - .freebsd, - .kfreebsd, - .openbsd, - .dragonfly, - => true, - else => false, - }; -} - -pub fn appendFlags(step: *std.build.CompileStep, flags: *std.ArrayList([]const u8), debug_symbols: bool, is_cpp: bool) !void { - if (debug_symbols) try flags.append("-g1") else try flags.append("-g0"); - if (is_cpp) try flags.append("-std=c++17"); - if (isLinuxDesktopLike(step.target_info.target.os.tag)) { - try flags.append("-DDAWN_USE_X11"); - try flags.append("-DDAWN_USE_WAYLAND"); - } -} - -fn linkLibDawnCommonDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - _ = options; - step.linkLibCpp(); - if (step.target_info.target.os.tag == .macos) { - // TODO(build-system): This cannot be imported with the Zig package manager - // error: TarUnsupportedFileType - // - // step.linkLibrary(b.dependency("xcode_frameworks", .{ - // .target = step.target, - // .optimize = step.optimize, - // }).artifact("xcode-frameworks")); - // @import("xcode_frameworks").addPaths(step); - xcode_frameworks.addPaths(b, step); - - step.linkSystemLibraryName("objc"); - step.linkFramework("Foundation"); - } -} - -// Builds common sources; derived from src/common/BUILD.gn -fn buildLibDawnCommon(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "dawn-common", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "dawn-common", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibDawnCommonDependencies(b, lib, options); - - if (lib.target_info.target.os.tag == .linux) lib.linkLibrary(b.dependency("x11_headers", .{ - .target = lib.target, - .optimize = lib.optimize, - }).artifact("x11-headers")); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(&.{ - include("libs/dawn/src"), - include("libs/dawn/out/Debug/gen/include"), - include("libs/dawn/out/Debug/gen/src"), - }); - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/dawn/common/", - "libs/dawn/out/Debug/gen/src/dawn/common/", - }, - .flags = flags.items, - .excluding_contains = &.{ - "test", - "benchmark", - "mock", - "WindowsUtils.cpp", - }, - }); - - var cpp_sources = std.ArrayList([]const u8).init(b.allocator); - if (step.target_info.target.os.tag == .macos) { - // TODO(build-system): pass system SDK options through - const abs_path = sdkPath("/libs/dawn/src/dawn/common/SystemUtils_mac.mm"); - try cpp_sources.append(abs_path); - } - if (step.target_info.target.os.tag == .windows) { - const abs_path = sdkPath("/libs/dawn/src/dawn/common/WindowsUtils.cpp"); - try cpp_sources.append(abs_path); - } - - var cpp_flags = std.ArrayList([]const u8).init(b.allocator); - try cpp_flags.appendSlice(flags.items); - try appendFlags(step, &cpp_flags, options.debug, true); - lib.addCSourceFiles(cpp_sources.items, cpp_flags.items); - return lib; -} - -fn linkLibDawnPlatformDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - _ = b; - _ = options; - step.linkLibCpp(); -} - -// Build dawn platform sources; derived from src/dawn/platform/BUILD.gn -fn buildLibDawnPlatform(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "dawn-platform", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "dawn-platform", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibDawnPlatformDependencies(b, lib, options); - - var cpp_flags = std.ArrayList([]const u8).init(b.allocator); - try appendFlags(step, &cpp_flags, options.debug, true); - try cpp_flags.appendSlice(&.{ - include("libs/dawn/src"), - include("libs/dawn/include"), - - include("libs/dawn/out/Debug/gen/include"), - }); - - var cpp_sources = std.ArrayList([]const u8).init(b.allocator); - inline for ([_][]const u8{ - "src/dawn/platform/DawnPlatform.cpp", - "src/dawn/platform/WorkerThread.cpp", - "src/dawn/platform/tracing/EventTracer.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - - lib.addCSourceFiles(cpp_sources.items, cpp_flags.items); - return lib; -} - -fn appendDawnEnableBackendTypeFlags(flags: *std.ArrayList([]const u8), options: Options) !void { - const d3d12 = "-DDAWN_ENABLE_BACKEND_D3D12"; - const metal = "-DDAWN_ENABLE_BACKEND_METAL"; - const vulkan = "-DDAWN_ENABLE_BACKEND_VULKAN"; - const opengl = "-DDAWN_ENABLE_BACKEND_OPENGL"; - const desktop_gl = "-DDAWN_ENABLE_BACKEND_DESKTOP_GL"; - const opengl_es = "-DDAWN_ENABLE_BACKEND_OPENGLES"; - const backend_null = "-DDAWN_ENABLE_BACKEND_NULL"; - - try flags.append(backend_null); - if (options.d3d12.?) try flags.append(d3d12); - if (options.metal.?) try flags.append(metal); - if (options.vulkan.?) try flags.append(vulkan); - if (options.desktop_gl.?) try flags.appendSlice(&.{ opengl, desktop_gl }); - if (options.opengl_es.?) try flags.appendSlice(&.{ opengl, opengl_es }); -} - -const dawn_d3d12_flags = &[_][]const u8{ - "-DDAWN_NO_WINDOWS_UI", - "-D__EMULATE_UUID=1", - "-Wno-nonportable-include-path", - "-Wno-extern-c-compat", - "-Wno-invalid-noreturn", - "-Wno-pragma-pack", - "-Wno-microsoft-template-shadow", - "-Wno-unused-command-line-argument", - "-Wno-microsoft-exception-spec", - "-Wno-implicit-exception-spec-mismatch", - "-Wno-unknown-attributes", - "-Wno-c++20-extensions", - "-D_CRT_SECURE_NO_WARNINGS", - "-DWIN32_LEAN_AND_MEAN", - "-DD3D10_ARBITRARY_HEADER_ORDERING", - "-DNOMINMAX", -}; - -fn linkLibDawnNativeDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - step.linkLibCpp(); - if (options.d3d12.?) { - step.linkLibrary(b.dependency("direct3d_headers", .{ - .target = step.target, - .optimize = step.optimize, - }).artifact("direct3d-headers")); - } - if (options.metal.?) { - // TODO(build-system): This cannot be imported with the Zig package manager - // error: TarUnsupportedFileType - // - // step.linkLibrary(b.dependency("xcode_frameworks", .{ - // .target = step.target, - // .optimize = step.optimize, - // }).artifact("xcode-frameworks")); - // @import("xcode_frameworks").addPaths(step); - xcode_frameworks.addPaths(b, step); - - step.linkSystemLibraryName("objc"); - step.linkFramework("Metal"); - step.linkFramework("CoreGraphics"); - step.linkFramework("Foundation"); - step.linkFramework("IOKit"); - step.linkFramework("IOSurface"); - step.linkFramework("QuartzCore"); - } - const tag = step.target_info.target.os.tag; - if (isLinuxDesktopLike(tag)) { - step.linkSystemLibraryName("X11"); - } -} - -// Builds dawn native sources; derived from src/dawn/native/BUILD.gn -fn buildLibDawnNative(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "dawn-native", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "dawn-native", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibDawnNativeDependencies(b, lib, options); - - if (options.vulkan.?) lib.linkLibrary(b.dependency("vulkan_headers", .{ - .target = lib.target, - .optimize = lib.optimize, - }).artifact("vulkan-headers")); - if (lib.target_info.target.os.tag == .linux) lib.linkLibrary(b.dependency("x11_headers", .{ - .target = lib.target, - .optimize = lib.optimize, - }).artifact("x11-headers")); - - // MacOS: this must be defined for macOS 13.3 and older. - // Critically, this MUST NOT be included as a -D__kernel_ptr_semantics flag. If it is, - // then this macro will not be defined even if `defineCMacro` was also called! - lib.defineCMacro("__kernel_ptr_semantics", ""); - - lib.defineCMacro("_HRESULT_DEFINED", ""); - lib.defineCMacro("HRESULT", "long"); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try appendDawnEnableBackendTypeFlags(&flags, options); - try flags.appendSlice(&.{ - include("libs/dawn"), - include("libs/dawn/src"), - include("libs/dawn/include"), - include("libs/dawn/third_party/vulkan-deps/spirv-tools/src/include"), - include("libs/dawn/third_party/khronos"), - - "-Wno-deprecated-declarations", - include("libs/dawn/third_party/abseil-cpp"), - - // TODO(build-system): make these optional - "-DTINT_BUILD_SPV_READER=1", - "-DTINT_BUILD_SPV_WRITER=1", - "-DTINT_BUILD_WGSL_READER=1", - "-DTINT_BUILD_WGSL_WRITER=1", - "-DTINT_BUILD_MSL_WRITER=1", - "-DTINT_BUILD_HLSL_WRITER=1", - "-DTINT_BUILD_GLSL_WRITER=1", - "-DDAWN_NO_WINDOWS_UI", - - include("libs/dawn/"), - include("libs/dawn/include/tint"), - include("libs/dawn/third_party/vulkan-deps/vulkan-tools/src/"), - - include("libs/dawn/out/Debug/gen/include"), - include("libs/dawn/out/Debug/gen/src"), - }); - if (options.d3d12.?) try flags.appendSlice(dawn_d3d12_flags); - - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/out/Debug/gen/src/dawn/", - "libs/dawn/src/dawn/native/", - "libs/dawn/src/dawn/native/utils/", - "libs/dawn/src/dawn/native/stream/", - }, - .flags = flags.items, - .excluding_contains = if (options.shared_libs) &.{ - "test", - "benchmark", - "mock", - "SpirvValidation.cpp", - "XlibXcbFunctions.cpp", - "dawn_proc.c", - } else &.{ - "test", - "benchmark", - "mock", - "SpirvValidation.cpp", - "XlibXcbFunctions.cpp", - "dawn_proc.c", - }, - }); - - // dawn_native_gen - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/out/Debug/gen/src/dawn/native/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark", "mock", "webgpu_dawn_native_proc.cpp" }, - }); - - // TODO(build-system): could allow enable_vulkan_validation_layers here. See src/dawn/native/BUILD.gn - // TODO(build-system): allow use_angle here. See src/dawn/native/BUILD.gn - // TODO(build-system): could allow use_swiftshader here. See src/dawn/native/BUILD.gn - - var cpp_sources = std.ArrayList([]const u8).init(b.allocator); - if (options.d3d12.?) { - inline for ([_][]const u8{ - "src/dawn/mingw_helpers.cpp", - }) |path| { - const abs_path = sdkPath("/" ++ path); - try cpp_sources.append(abs_path); - } - - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/dawn/native/d3d/", - "libs/dawn/src/dawn/native/d3d12/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark", "mock" }, - }); - } - if (options.metal.?) { - try appendLangScannedSources(b, lib, .{ - .objc = true, - .rel_dirs = &.{ - "libs/dawn/src/dawn/native/metal/", - "libs/dawn/src/dawn/native/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark", "mock" }, - }); - } - - const tag = step.target_info.target.os.tag; - if (isLinuxDesktopLike(tag)) { - inline for ([_][]const u8{ - "src/dawn/native/XlibXcbFunctions.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - } - - inline for ([_][]const u8{ - "src/dawn/native/null/DeviceNull.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - - if (options.desktop_gl.? or options.vulkan.?) { - inline for ([_][]const u8{ - "src/dawn/native/SpirvValidation.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - } - - if (options.desktop_gl.?) { - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/out/Debug/gen/src/dawn/native/opengl/", - "libs/dawn/src/dawn/native/opengl/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark", "mock" }, - }); - } - - if (options.vulkan.?) { - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/dawn/native/vulkan/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark", "mock" }, - }); - try cpp_sources.append(sdkPath("/libs/dawn/" ++ "src/dawn/native/vulkan/external_memory/MemoryService.cpp")); - try cpp_sources.append(sdkPath("/libs/dawn/" ++ "src/dawn/native/vulkan/external_memory/MemoryServiceImplementation.cpp")); - try cpp_sources.append(sdkPath("/libs/dawn/" ++ "src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp")); - try cpp_sources.append(sdkPath("/libs/dawn/" ++ "src/dawn/native/vulkan/external_semaphore/SemaphoreService.cpp")); - try cpp_sources.append(sdkPath("/libs/dawn/" ++ "src/dawn/native/vulkan/external_semaphore/SemaphoreServiceImplementation.cpp")); - - if (isLinuxDesktopLike(tag)) { - inline for ([_][]const u8{ - "src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp", - "src/dawn/native/vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - } else if (tag == .fuchsia) { - inline for ([_][]const u8{ - "src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.cpp", - "src/dawn/native/vulkan/external_semaphore/SemaphoreServiceImplementationZirconHandle.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - } else if (step.target_info.target.isAndroid()) { - inline for ([_][]const u8{ - "src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp", - "src/dawn/native/vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - try cpp_sources.append("-DDAWN_USE_SYNC_FDS"); - } - } - - // TODO(build-system): fuchsia: add is_fuchsia here from upstream source file - - if (options.vulkan.?) { - // TODO(build-system): vulkan - // if (enable_vulkan_validation_layers) { - // defines += [ - // "DAWN_ENABLE_VULKAN_VALIDATION_LAYERS", - // "DAWN_VK_DATA_DIR=\"$vulkan_data_subdir\"", - // ] - // } - // if (enable_vulkan_loader) { - // data_deps += [ "${dawn_vulkan_loader_dir}:libvulkan" ] - // defines += [ "DAWN_ENABLE_VULKAN_LOADER" ] - // } - } - // TODO(build-system): swiftshader - // if (use_swiftshader) { - // data_deps += [ - // "${dawn_swiftshader_dir}/src/Vulkan:icd_file", - // "${dawn_swiftshader_dir}/src/Vulkan:swiftshader_libvulkan", - // ] - // defines += [ - // "DAWN_ENABLE_SWIFTSHADER", - // "DAWN_SWIFTSHADER_VK_ICD_JSON=\"${swiftshader_icd_file_name}\"", - // ] - // } - // } - - if (options.opengl_es.?) { - // TODO(build-system): gles - // if (use_angle) { - // data_deps += [ - // "${dawn_angle_dir}:libEGL", - // "${dawn_angle_dir}:libGLESv2", - // ] - // } - // } - } - - inline for ([_][]const u8{ - "src/dawn/native/null/NullBackend.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - - if (options.d3d12.?) { - inline for ([_][]const u8{ - "src/dawn/native/d3d12/D3D12Backend.cpp", - }) |path| { - const abs_path = sdkPath("/libs/dawn/" ++ path); - try cpp_sources.append(abs_path); - } - } - - var cpp_flags = std.ArrayList([]const u8).init(b.allocator); - try cpp_flags.appendSlice(flags.items); - try appendFlags(step, &cpp_flags, options.debug, true); - lib.addCSourceFiles(cpp_sources.items, cpp_flags.items); - return lib; -} - -fn linkLibTintDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - _ = b; - _ = options; - step.linkLibCpp(); -} - -// Builds tint sources; derived from src/tint/BUILD.gn -fn buildLibTint(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "tint", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "tint", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibTintDependencies(b, lib, options); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(&.{ - // TODO(build-system): make these optional - "-DTINT_BUILD_SPV_READER=1", - "-DTINT_BUILD_SPV_WRITER=1", - "-DTINT_BUILD_WGSL_READER=1", - "-DTINT_BUILD_WGSL_WRITER=1", - "-DTINT_BUILD_MSL_WRITER=1", - "-DTINT_BUILD_HLSL_WRITER=1", - "-DTINT_BUILD_GLSL_WRITER=1", - - include("libs/dawn/"), - include("libs/dawn/include/tint"), - - // Required for TINT_BUILD_SPV_READER=1 and TINT_BUILD_SPV_WRITER=1, if specified - include("libs/dawn/third_party/vulkan-deps"), - include("libs/dawn/third_party/vulkan-deps/spirv-tools/src"), - include("libs/dawn/third_party/vulkan-deps/spirv-tools/src/include"), - include("libs/dawn/third_party/vulkan-deps/spirv-headers/src/include"), - include("libs/dawn/out/Debug/gen/third_party/vulkan-deps/spirv-tools/src"), - include("libs/dawn/out/Debug/gen/third_party/vulkan-deps/spirv-tools/src/include"), - include("libs/dawn/include"), - include("libs/dawn/third_party/abseil-cpp"), - }); - - // TODO: split out libtint builds, provide an example of building: src/tint/cmd - - // libtint_core_all_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint", - "libs/dawn/src/tint/reader/", - "libs/dawn/src/tint/writer/syntax_tree", - "libs/dawn/src/tint/ir", - "libs/dawn/src/tint/ir/transform", - // "libs/dawn/src/tint/utils/io", - "libs/dawn/src/tint/templates", - "libs/dawn/src/tint/constant/", - "libs/dawn/src/tint/diagnostic/", - "libs/dawn/src/tint/inspector/", - "libs/dawn/src/tint/builtin/", - "libs/dawn/src/tint/resolver/", - "libs/dawn/src/tint/utils/", - "libs/dawn/src/tint/type/", - "libs/dawn/src/tint/transform/", - "libs/dawn/src/tint/writer/", - "libs/dawn/src/tint/ast/", - "libs/dawn/src/tint/ast/transform/", - "libs/dawn/src/tint/ast/transform/utils/", - "libs/dawn/src/tint/val/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench", "printer_windows", "printer_posix", "printer_other", "glsl.cc" }, - }); - - var cpp_sources = std.ArrayList([]const u8).init(b.allocator); - - const tag = step.target_info.target.os.tag; - if (tag == .windows) { - try cpp_sources.append(sdkPath("/libs/dawn/src/tint/diagnostic/printer_windows.cc")); - } else if (tag.isDarwin() or isLinuxDesktopLike(tag)) { - try cpp_sources.append(sdkPath("/libs/dawn/src/tint/diagnostic/printer_posix.cc")); - } else { - try cpp_sources.append(sdkPath("/libs/dawn/src/tint/diagnostic/printer_other.cc")); - } - - // libtint_sem_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/sem/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark" }, - }); - - // libtint_spv_reader_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/reader/spirv/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark" }, - }); - - // libtint_spv_writer_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/writer/spirv/", - // "libs/dawn/src/tint/writer/spirv/ir/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench" }, - }); - - // TODO(build-system): make optional - // libtint_wgsl_reader_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/reader/wgsl/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench" }, - }); - - // TODO(build-system): make optional - // libtint_wgsl_writer_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/writer/wgsl/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench" }, - }); - - // TODO(build-system): make optional - // libtint_msl_writer_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/writer/msl/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench" }, - }); - - // TODO(build-system): make optional - // libtint_hlsl_writer_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/writer/hlsl/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench" }, - }); - - // TODO(build-system): make optional - // libtint_glsl_writer_src - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/src/tint/writer/glsl/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "bench" }, - }); - - var cpp_flags = std.ArrayList([]const u8).init(b.allocator); - try cpp_flags.appendSlice(flags.items); - try appendFlags(step, &cpp_flags, options.debug, true); - lib.addCSourceFiles(cpp_sources.items, cpp_flags.items); - return lib; -} - -fn linkLibSPIRVToolsDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - _ = b; - _ = options; - step.linkLibCpp(); -} - -// Builds third_party/vulkan-deps/spirv-tools sources; derived from third_party/vulkan-deps/spirv-tools/src/BUILD.gn -fn buildLibSPIRVTools(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "spirv-tools", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "spirv-tools", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibSPIRVToolsDependencies(b, lib, options); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(&.{ - include("libs/dawn"), - include("libs/dawn/third_party/vulkan-deps/spirv-tools/src"), - include("libs/dawn/third_party/vulkan-deps/spirv-tools/src/include"), - include("libs/dawn/third_party/vulkan-deps/spirv-headers/src/include"), - include("libs/dawn/out/Debug/gen/third_party/vulkan-deps/spirv-tools/src"), - include("libs/dawn/out/Debug/gen/third_party/vulkan-deps/spirv-tools/src/include"), - include("libs/dawn/third_party/vulkan-deps/spirv-headers/src/include/spirv/unified1"), - }); - - // spvtools - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/third_party/vulkan-deps/spirv-tools/src/source/", - "libs/dawn/third_party/vulkan-deps/spirv-tools/src/source/util/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark" }, - }); - - // spvtools_val - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/third_party/vulkan-deps/spirv-tools/src/source/val/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark" }, - }); - - // spvtools_opt - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/third_party/vulkan-deps/spirv-tools/src/source/opt/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark" }, - }); - - // spvtools_link - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/third_party/vulkan-deps/spirv-tools/src/source/link/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark" }, - }); - return lib; -} - -fn linkLibAbseilCppDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - _ = options; - step.linkLibCpp(); - const target = step.target_info.target; - if (target.os.tag == .macos) { - // TODO(build-system): This cannot be imported with the Zig package manager - // error: TarUnsupportedFileType - // - // step.linkLibrary(b.dependency("xcode_frameworks", .{ - // .target = step.target, - // .optimize = step.optimize, - // }).artifact("xcode-frameworks")); - // @import("xcode_frameworks").addPaths(step); - xcode_frameworks.addPaths(b, step); - - step.linkSystemLibraryName("objc"); - step.linkFramework("CoreFoundation"); - } - if (target.os.tag == .windows) step.linkSystemLibraryName("bcrypt"); -} - -// Builds third_party/abseil sources; derived from: -// -// ``` -// $ find third_party/abseil-cpp/absl | grep '\.cc' | grep -v 'test' | grep -v 'benchmark' | grep -v gaussian_distribution_gentables | grep -v print_hash_of | grep -v chi_square -// ``` -// -fn buildLibAbseilCpp(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "abseil", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "abseil", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibAbseilCppDependencies(b, lib, options); - - const target = step.target_info.target; - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(&.{ - include("libs/dawn"), - include("libs/dawn/third_party/abseil-cpp"), - "-Wno-deprecated-declarations", - - // musl needs this defined in order for off64_t to be a type, which abseil-cpp uses - "-D_FILE_OFFSET_BITS", - "-D_LARGEFILE64_SOURCE", - }); - if (target.os.tag == .windows) try flags.appendSlice(&.{ - "-DABSL_FORCE_THREAD_IDENTITY_MODE=2", - "-DWIN32_LEAN_AND_MEAN", - "-DD3D10_ARBITRARY_HEADER_ORDERING", - "-D_CRT_SECURE_NO_WARNINGS", - "-DNOMINMAX", - include("src/dawn/zig_mingw_pthread"), - }); - - // absl - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/third_party/abseil-cpp/absl/strings/", - "libs/dawn/third_party/abseil-cpp/absl/strings/internal/", - "libs/dawn/third_party/abseil-cpp/absl/strings/internal/str_format/", - "libs/dawn/third_party/abseil-cpp/absl/types/", - "libs/dawn/third_party/abseil-cpp/absl/flags/internal/", - "libs/dawn/third_party/abseil-cpp/absl/flags/", - "libs/dawn/third_party/abseil-cpp/absl/synchronization/", - "libs/dawn/third_party/abseil-cpp/absl/synchronization/internal/", - "libs/dawn/third_party/abseil-cpp/absl/hash/internal/", - "libs/dawn/third_party/abseil-cpp/absl/debugging/", - "libs/dawn/third_party/abseil-cpp/absl/debugging/internal/", - "libs/dawn/third_party/abseil-cpp/absl/status/", - "libs/dawn/third_party/abseil-cpp/absl/time/internal/cctz/src/", - "libs/dawn/third_party/abseil-cpp/absl/time/", - "libs/dawn/third_party/abseil-cpp/absl/container/internal/", - "libs/dawn/third_party/abseil-cpp/absl/numeric/", - "libs/dawn/third_party/abseil-cpp/absl/random/", - "libs/dawn/third_party/abseil-cpp/absl/random/internal/", - "libs/dawn/third_party/abseil-cpp/absl/base/internal/", - "libs/dawn/third_party/abseil-cpp/absl/base/", - }, - .flags = flags.items, - .excluding_contains = &.{ "_test", "_testing", "benchmark", "print_hash_of.cc", "gaussian_distribution_gentables.cc" }, - }); - return lib; -} - -fn linkLibDawnWireDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - _ = b; - _ = options; - step.linkLibCpp(); -} - -// Buids dawn wire sources; derived from src/dawn/wire/BUILD.gn -fn buildLibDawnWire(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "dawn-wire", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "dawn-wire", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibDawnWireDependencies(b, lib, options); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(&.{ - include("libs/dawn"), - include("libs/dawn/src"), - include("libs/dawn/include"), - include("libs/dawn/out/Debug/gen/include"), - include("libs/dawn/out/Debug/gen/src"), - }); - - try appendLangScannedSources(b, lib, .{ - .rel_dirs = &.{ - "libs/dawn/out/Debug/gen/src/dawn/wire/", - "libs/dawn/out/Debug/gen/src/dawn/wire/client/", - "libs/dawn/out/Debug/gen/src/dawn/wire/server/", - "libs/dawn/src/dawn/wire/", - "libs/dawn/src/dawn/wire/client/", - "libs/dawn/src/dawn/wire/server/", - }, - .flags = flags.items, - .excluding_contains = &.{ "test", "benchmark", "mock" }, - }); - return lib; -} - -fn linkLibDxcompilerDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { - if (options.d3d12.?) { - step.linkLibCpp(); - step.linkLibrary(b.dependency("direct3d_headers", .{ - .target = step.target, - .optimize = step.optimize, - }).artifact("direct3d-headers")); - - step.linkSystemLibraryName("oleaut32"); - step.linkSystemLibraryName("ole32"); - step.linkSystemLibraryName("dbghelp"); - } -} - -// Buids dxcompiler sources; derived from libs/DirectXShaderCompiler/CMakeLists.txt -fn buildLibDxcompiler(b: *Build, step: *std.build.CompileStep, options: Options) !*std.build.CompileStep { - const lib = if (!options.separate_libs) step else if (options.shared_libs) b.addSharedLibrary(.{ - .name = "dxcompiler", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }) else b.addStaticLibrary(.{ - .name = "dxcompiler", - .target = step.target, - .optimize = if (options.debug) .Debug else .ReleaseFast, - }); - if (options.install_libs) b.installArtifact(lib); - linkLibDxcompilerDependencies(b, lib, options); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(&.{ - include("libs/"), - include("libs/DirectXShaderCompiler/include/llvm/llvm_assert"), - include("libs/DirectXShaderCompiler/include"), - include("libs/DirectXShaderCompiler/build/include"), - include("libs/DirectXShaderCompiler/build/lib/HLSL"), - include("libs/DirectXShaderCompiler/build/lib/DxilPIXPasses"), - include("libs/DirectXShaderCompiler/build/include"), - "-DUNREFERENCED_PARAMETER(x)=", - "-Wno-inconsistent-missing-override", - "-Wno-missing-exception-spec", - "-Wno-switch", - "-Wno-deprecated-declarations", - "-Wno-macro-redefined", // regex2.h and regcomp.c requires this for OUT redefinition - "-DMSFT_SUPPORTS_CHILD_PROCESSES=1", - "-DHAVE_LIBPSAPI=1", - "-DHAVE_LIBSHELL32=1", - "-DLLVM_ON_WIN32=1", - }); - - try appendLangScannedSources(b, lib, .{ - .debug_symbols = false, - .rel_dirs = &.{ - "libs/DirectXShaderCompiler/lib/Analysis/IPA", - "libs/DirectXShaderCompiler/lib/Analysis", - "libs/DirectXShaderCompiler/lib/AsmParser", - "libs/DirectXShaderCompiler/lib/Bitcode/Writer", - "libs/DirectXShaderCompiler/lib/DxcBindingTable", - "libs/DirectXShaderCompiler/lib/DxcSupport", - "libs/DirectXShaderCompiler/lib/DxilContainer", - "libs/DirectXShaderCompiler/lib/DxilPIXPasses", - "libs/DirectXShaderCompiler/lib/DxilRootSignature", - "libs/DirectXShaderCompiler/lib/DXIL", - "libs/DirectXShaderCompiler/lib/DxrFallback", - "libs/DirectXShaderCompiler/lib/HLSL", - "libs/DirectXShaderCompiler/lib/IRReader", - "libs/DirectXShaderCompiler/lib/IR", - "libs/DirectXShaderCompiler/lib/Linker", - "libs/DirectXShaderCompiler/lib/Miniz", - "libs/DirectXShaderCompiler/lib/Option", - "libs/DirectXShaderCompiler/lib/PassPrinters", - "libs/DirectXShaderCompiler/lib/Passes", - "libs/DirectXShaderCompiler/lib/ProfileData", - "libs/DirectXShaderCompiler/lib/Target", - "libs/DirectXShaderCompiler/lib/Transforms/InstCombine", - "libs/DirectXShaderCompiler/lib/Transforms/IPO", - "libs/DirectXShaderCompiler/lib/Transforms/Scalar", - "libs/DirectXShaderCompiler/lib/Transforms/Utils", - "libs/DirectXShaderCompiler/lib/Transforms/Vectorize", - }, - .flags = flags.items, - }); - - try appendLangScannedSources(b, lib, .{ - .debug_symbols = false, - .rel_dirs = &.{ - "libs/DirectXShaderCompiler/lib/Support", - }, - .flags = flags.items, - .excluding_contains = &.{ - "DynamicLibrary.cpp", // ignore, HLSL_IGNORE_SOURCES - "PluginLoader.cpp", // ignore, HLSL_IGNORE_SOURCES - "Path.cpp", // ignore, LLVM_INCLUDE_TESTS - "DynamicLibrary.cpp", // ignore - }, - }); - - try appendLangScannedSources(b, lib, .{ - .debug_symbols = false, - .rel_dirs = &.{ - "libs/DirectXShaderCompiler/lib/Bitcode/Reader", - }, - .flags = flags.items, - .excluding_contains = &.{ - "BitReader.cpp", // ignore - }, - }); - return lib; -} - -fn appendLangScannedSources( - b: *Build, - step: *std.build.CompileStep, - args: struct { - debug_symbols: bool = false, - flags: []const []const u8, - rel_dirs: []const []const u8 = &.{}, - objc: bool = false, - excluding: []const []const u8 = &.{}, - excluding_contains: []const []const u8 = &.{}, - }, -) !void { - var cpp_flags = std.ArrayList([]const u8).init(b.allocator); - try cpp_flags.appendSlice(args.flags); - try appendFlags(step, &cpp_flags, args.debug_symbols, true); - const cpp_extensions: []const []const u8 = if (args.objc) &.{".mm"} else &.{ ".cpp", ".cc" }; - try appendScannedSources(b, step, .{ - .flags = cpp_flags.items, - .rel_dirs = args.rel_dirs, - .extensions = cpp_extensions, - .excluding = args.excluding, - .excluding_contains = args.excluding_contains, - }); - - var flags = std.ArrayList([]const u8).init(b.allocator); - try flags.appendSlice(args.flags); - try appendFlags(step, &flags, args.debug_symbols, false); - const c_extensions: []const []const u8 = if (args.objc) &.{".m"} else &.{".c"}; - try appendScannedSources(b, step, .{ - .flags = flags.items, - .rel_dirs = args.rel_dirs, - .extensions = c_extensions, - .excluding = args.excluding, - .excluding_contains = args.excluding_contains, - }); -} - -fn appendScannedSources(b: *Build, step: *std.build.CompileStep, args: struct { - flags: []const []const u8, - rel_dirs: []const []const u8 = &.{}, - extensions: []const []const u8, - excluding: []const []const u8 = &.{}, - excluding_contains: []const []const u8 = &.{}, -}) !void { - var sources = std.ArrayList([]const u8).init(b.allocator); - for (args.rel_dirs) |rel_dir| { - try scanSources(b, &sources, rel_dir, args.extensions, args.excluding, args.excluding_contains); - } - step.addCSourceFiles(sources.items, args.flags); -} - -/// Scans rel_dir for sources ending with one of the provided extensions, excluding relative paths -/// listed in the excluded list. -/// Results are appended to the dst ArrayList. -fn scanSources( - b: *Build, - dst: *std.ArrayList([]const u8), - rel_dir: []const u8, - extensions: []const []const u8, - excluding: []const []const u8, - excluding_contains: []const []const u8, -) !void { - const abs_dir = try std.fs.path.join(b.allocator, &.{ sdkPath("/"), rel_dir }); - defer b.allocator.free(abs_dir); - var dir = std.fs.openIterableDirAbsolute(abs_dir, .{}) catch |err| { - std.log.err("mach: error: failed to open: {s}", .{abs_dir}); - return err; - }; - defer dir.close(); - var dir_it = dir.iterate(); - while (try dir_it.next()) |entry| { - if (entry.kind != .file) continue; - var abs_path = try std.fs.path.join(b.allocator, &.{ abs_dir, entry.name }); - abs_path = try std.fs.realpathAlloc(b.allocator, abs_path); - - const allowed_extension = blk: { - const ours = std.fs.path.extension(entry.name); - for (extensions) |ext| { - if (std.mem.eql(u8, ours, ext)) break :blk true; - } - break :blk false; - }; - if (!allowed_extension) continue; - - const excluded = blk: { - for (excluding) |excluded| { - if (std.mem.eql(u8, entry.name, excluded)) break :blk true; - } - break :blk false; - }; - if (excluded) continue; - - const excluded_contains = blk: { - for (excluding_contains) |contains| { - if (std.mem.containsAtLeast(u8, entry.name, 1, contains)) break :blk true; - } - break :blk false; - }; - if (excluded_contains) continue; - - try dst.append(abs_path); - } -} - -fn include(comptime rel: []const u8) []const u8 { - return comptime "-I" ++ sdkPath("/" ++ rel); -} - -fn sdkPath(comptime suffix: []const u8) []const u8 { - if (suffix[0] != '/') @compileError("suffix must be an absolute path"); - return comptime blk: { - const root_dir = std.fs.path.dirname(@src().file) orelse "."; - break :blk root_dir ++ suffix; - }; -} - -// TODO(build-system): This is a workaround that we copy anywhere xcode_frameworks needs to be used. -// With the Zig package manager, it should be possible to remove this entirely and instead just -// write: -// -// ``` -// step.linkLibrary(b.dependency("xcode_frameworks", .{ -// .target = step.target, -// .optimize = step.optimize, -// }).artifact("xcode-frameworks")); -// @import("xcode_frameworks").addPaths(step); -// ``` -// -// However, today this package cannot be imported with the Zig package manager due to `error: TarUnsupportedFileType` -// which would be fixed by https://github.com/ziglang/zig/pull/15382 - so instead for now you must -// copy+paste this struct into your `build.zig` and write: -// -// ``` -// try xcode_frameworks.addPaths(b, step); -// ``` -const xcode_frameworks = struct { - pub fn addPaths(b: *std.Build, step: *std.build.CompileStep) void { - // branch: mach - xEnsureGitRepoCloned(b.allocator, "https://github.com/hexops/xcode-frameworks", "723aa55e9752c8c6c25d3413722b5fe13d72ac4f", xSdkPath("/zig-cache/xcode_frameworks")) catch |err| @panic(@errorName(err)); - - step.addFrameworkPath("zig-cache/xcode_frameworks/Frameworks"); - step.addSystemIncludePath("zig-cache/xcode_frameworks/include"); - step.addLibraryPath("zig-cache/xcode_frameworks/lib"); - } - - fn xEnsureGitRepoCloned(allocator: std.mem.Allocator, clone_url: []const u8, revision: []const u8, dir: []const u8) !void { - if (xIsEnvVarTruthy(allocator, "NO_ENSURE_SUBMODULES") or xIsEnvVarTruthy(allocator, "NO_ENSURE_GIT")) { - return; - } - - xEnsureGit(allocator); - - if (std.fs.openDirAbsolute(dir, .{})) |_| { - const current_revision = try xGetCurrentGitRevision(allocator, dir); - if (!std.mem.eql(u8, current_revision, revision)) { - // Reset to the desired revision - xExec(allocator, &[_][]const u8{ "git", "fetch" }, dir) catch |err| std.debug.print("warning: failed to 'git fetch' in {s}: {s}\n", .{ dir, @errorName(err) }); - try xExec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try xExec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - } - return; - } else |err| return switch (err) { - error.FileNotFound => { - std.log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, dir }); - - try xExec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, dir }, "."); - try xExec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try xExec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - return; - }, - else => err, - }; - } - - fn xExec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void { - var child = std.ChildProcess.init(argv, allocator); - child.cwd = cwd; - _ = try child.spawnAndWait(); - } - - fn xGetCurrentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 { - const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = &.{ "git", "rev-parse", "HEAD" }, .cwd = cwd }); - allocator.free(result.stderr); - if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline - return result.stdout; - } - - fn xEnsureGit(allocator: std.mem.Allocator) void { - const argv = &[_][]const u8{ "git", "--version" }; - const result = std.ChildProcess.exec(.{ - .allocator = allocator, - .argv = argv, - .cwd = ".", - }) catch { // e.g. FileNotFound - std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - }; - defer { - allocator.free(result.stderr); - allocator.free(result.stdout); - } - if (result.term.Exited != 0) { - std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - } - } - - fn xIsEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool { - if (std.process.getEnvVarOwned(allocator, name)) |truthy| { - defer allocator.free(truthy); - if (std.mem.eql(u8, truthy, "true")) return true; - return false; - } else |_| { - return false; - } - } - - fn xSdkPath(comptime suffix: []const u8) []const u8 { - if (suffix[0] != '/') @compileError("suffix must be an absolute path"); - return comptime blk: { - const root_dir = std.fs.path.dirname(@src().file) orelse "."; - break :blk root_dir ++ suffix; - }; - } -}; diff --git a/libs/gpu-dawn/build.zig.zon b/libs/gpu-dawn/build.zig.zon deleted file mode 100644 index 949cf960..00000000 --- a/libs/gpu-dawn/build.zig.zon +++ /dev/null @@ -1,30 +0,0 @@ -.{ - .name = "mach-gpu-dawn", - .version = "0.2.0", - .dependencies = .{ - .mach_glfw = .{ - .url = "https://github.com/hexops/mach-glfw/archive/b119c63dd77764eeafe758d54accd0329821a729.tar.gz", - .hash = "1220fb0fb65621a4fc7406e4f74a87a0c60208f8a257cd7ca4e20da0925f875e70d0", - }, - .glfw = .{ - .url = "https://github.com/hexops/glfw/archive/49c21c3d2fcaf9799b593f5320ce8e598a692c74.tar.gz", - .hash = "12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2", - }, - .direct3d_headers = .{ - .url = "https://github.com/hexops/direct3d-headers/archive/773dce3f079eecdccc7c71d1318a0741649d568b.tar.gz", - .hash = "12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12", - }, - .vulkan_headers = .{ - .url = "https://github.com/hexops/vulkan-headers/archive/e1b061ff624531e82a7daea5dbd56c07e08bf0be.tar.gz", - .hash = "12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b", - }, - .wayland_headers = .{ - .url = "https://github.com/hexops/wayland-headers/archive/7bf46f3d60edab2171643ff85770c392ef62704d.tar.gz", - .hash = "1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a", - }, - .x11_headers = .{ - .url = "https://github.com/hexops/x11-headers/archive/99af89c7bfdc7db503f3a7003571f8e81bcd09f3.tar.gz", - .hash = "1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb", - }, - }, -} diff --git a/libs/gpu-dawn/dev/bundle-release.sh b/libs/gpu-dawn/dev/bundle-release.sh deleted file mode 100755 index 2e413142..00000000 --- a/libs/gpu-dawn/dev/bundle-release.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")"/.. - -rm -rf out/ out.tar.gz headers.json headers.json.gz - -# Prepare the `out/` directory that we will bundle. -mkdir out/ -cp -R libs/dawn/include out/ -cp -R libs/dawn/out/Debug/gen/include/* out/include/ -cp libs/dawn/LICENSE out/ -zig version > out/ZIG_VERSION - -# Bundle headers.json.gz -pushd out -python3 ../dev/dir_to_json.py > ../headers.json -popd -gzip -9 headers.json - -# Copy the binary into the out/ directory -if [[ "${WINDOWS:-"false"}" == "true" ]]; then - cp zig-out/lib/dawn.lib out/ -else - cp zig-out/lib/libdawn.a out/ -fi - -# Create out.tar.gz bundle -pushd out -tar -czvf ../out.tar.gz . -popd diff --git a/libs/gpu-dawn/dev/dir_to_json.py b/libs/gpu-dawn/dev/dir_to_json.py deleted file mode 100644 index a697c08f..00000000 --- a/libs/gpu-dawn/dev/dir_to_json.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -import json - -def dir_to_dict(d): - dict = {} - for dirpath,_,filenames in os.walk(d): - for f in filenames: - path = os.path.join(dirpath, f) - dict[path] = open(path, 'r').read() - return dict - -print(json.dumps(dir_to_dict('.'))) diff --git a/libs/gpu-dawn/dev/upload-release.sh b/libs/gpu-dawn/dev/upload-release.sh deleted file mode 100755 index 1b7fb96c..00000000 --- a/libs/gpu-dawn/dev/upload-release.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")"/.. - -# Prepare tarball, headers.json.gz, etc. -./dev/bundle-release.sh - -if [[ "${UPLOAD_HEADERS:-"false"}" == "true" ]]; then - # Upload headers.json.gz - gh release upload "release-$(git rev-parse --short HEAD)" headers.json.gz -fi - -# Upload static library individually. -if [[ "${WINDOWS:-"false"}" == "true" ]]; then - cp zig-out/lib/dawn.lib "dawn_$RELEASE_NAME.lib" - gzip -9 "dawn_$RELEASE_NAME.lib" - gh release upload "release-$(git rev-parse --short HEAD)" "dawn_$RELEASE_NAME.lib.gz" -else - cp zig-out/lib/libdawn.a "libdawn_$RELEASE_NAME.a" - gzip -9 "libdawn_$RELEASE_NAME.a" - gh release upload "release-$(git rev-parse --short HEAD)" "libdawn_$RELEASE_NAME.a.gz" -fi - -# Upload tarball of static library + headers. -mv out.tar.gz "$RELEASE_NAME.tar.gz" -gh release upload "release-$(git rev-parse --short HEAD)" "$RELEASE_NAME.tar.gz" diff --git a/libs/gpu-dawn/src/dawn/mingw_helpers.cpp b/libs/gpu-dawn/src/dawn/mingw_helpers.cpp deleted file mode 100644 index d9398e1a..00000000 --- a/libs/gpu-dawn/src/dawn/mingw_helpers.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifdef __MINGW32__ -#include -#include - -#define MINGW_UUIDOF(type, spec) \ - extern "C++" { \ - struct __declspec(uuid(spec)) type; \ - template<> const GUID &__mingw_uuidof() { \ - static constexpr IID __uuid_inst = guid_from_string(spec); \ - return __uuid_inst; \ - } \ - template<> const GUID &__mingw_uuidof() { \ - return __mingw_uuidof(); \ - } \ - } - -constexpr uint8_t nybble_from_hex(char c) { - return ((c >= '0' && c <= '9') - ? (c - '0') - : ((c >= 'a' && c <= 'f') - ? (c - 'a' + 10) - : ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) - : /* Should be an error */ -1))); -} - -constexpr uint8_t byte_from_hex(char c1, char c2) { - return nybble_from_hex(c1) << 4 | nybble_from_hex(c2); -} - -constexpr uint8_t byte_from_hexstr(const char str[2]) { - return nybble_from_hex(str[0]) << 4 | nybble_from_hex(str[1]); -} - -constexpr GUID guid_from_string(const char str[37]) { - return GUID{static_cast(byte_from_hexstr(str)) << 24 | - static_cast(byte_from_hexstr(str + 2)) << 16 | - static_cast(byte_from_hexstr(str + 4)) << 8 | - byte_from_hexstr(str + 6), - static_cast( - static_cast(byte_from_hexstr(str + 9)) << 8 | - byte_from_hexstr(str + 11)), - static_cast( - static_cast(byte_from_hexstr(str + 14)) << 8 | - byte_from_hexstr(str + 16)), - {byte_from_hexstr(str + 19), byte_from_hexstr(str + 21), - byte_from_hexstr(str + 24), byte_from_hexstr(str + 26), - byte_from_hexstr(str + 28), byte_from_hexstr(str + 30), - byte_from_hexstr(str + 32), byte_from_hexstr(str + 34)}}; -} - -#endif // __MINGW32__ - -// The point of this helper file is to export the specializations for MINGW_UUIDOF -// below, since MinGW does not have these as part of dxguid yet (not completely up -// to date.) -MINGW_UUIDOF(IDXGraphicsAnalysis, "9f251514-9d4d-4902-9d60-18988ab7d4b5") diff --git a/libs/gpu-dawn/src/dawn/zig_mingw_pthread/pthread.h b/libs/gpu-dawn/src/dawn/zig_mingw_pthread/pthread.h deleted file mode 100644 index e69de29b..00000000 diff --git a/libs/gpu-dawn/src/main.zig b/libs/gpu-dawn/src/main.zig deleted file mode 100644 index 902b554d..00000000 --- a/libs/gpu-dawn/src/main.zig +++ /dev/null @@ -1 +0,0 @@ -pub fn main() void {}