diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-04-07 01:09:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-07 16:09:02 +0800 |
| commit | edb7289383538c3356ca2d5f7c37f41821bbf252 (patch) | |
| tree | 3ebe39fb2854d2b18ea04cf414093260640ed0e3 | |
| parent | ce87ab925d06a784eec194081e00a1b4c9b94d0c (diff) | |
Use GITHUB_TOKEN for fetching prebuilt (#6712)
* Use GITHUB_TOKEN for fetching prebuilt
This PR extends Commit c6b702c to use GITHUB_TOKEN if set for fetching
prebuilt binaries.
This allows webgpu-dawn and slang-tint to be downloaded for certain IPs
where the github API rate is limited.
Fixes #6689
* Don't ignore download failure if github token is provided
* Update readme for getting github access token
* format code
* combine cmake_parse_arguments calls
* format code
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Jay Kwak <82421531+jkwak-work@users.noreply.github.com>
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | CONTRIBUTING.md | 10 | ||||
| -rw-r--r-- | cmake/FetchedSharedLibrary.cmake | 33 |
3 files changed, 32 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c6b5eb93..081a40fb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,6 +375,7 @@ if(SLANG_WEBGPU_DAWN_BINARY_URL) "webgpu_dawn" "${SLANG_WEBGPU_DAWN_BINARY_URL}" IGNORE_FAILURE + SLANG_GITHUB_TOKEN ${SLANG_GITHUB_TOKEN} ) endif() @@ -387,6 +388,7 @@ if(SLANG_SLANG_TINT_BINARY_URL) "slang-tint" "${SLANG_SLANG_TINT_BINARY_URL}" IGNORE_FAILURE + SLANG_GITHUB_TOKEN ${SLANG_GITHUB_TOKEN} ) endif() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 822d44f08..36d297214 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -170,15 +170,11 @@ Call Stack (most recent call first): CMakeLists.txt:141 (get_best_slang_binary_release_url) ``` -The limit is higher when you use your personal account with a "Passkey". +The limit is higher when you use your personal account with a "personal access token". -To generate a "Passkey" on GitHub: - 1. Go to GitHub "Settings" for your account. - 2. Go to "Password and Authentication". - 3. Click "Add a passkey" button. - 4. GitHub will generate a "Passkey". +To generate a "personal access token" on GitHub, follow steps in [Creating a personal access token (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) -Use the generated "Passkey" with a cmake option "-DSLANG_GITHUB_TOKEN=your-pass-key-here". +Use the generated "token" with a cmake option "-DSLANG_GITHUB_TOKEN=your-token-here". ### Making Changes Make your changes and ensure to follow our [Design Decisions](docs/design/README.md). diff --git a/cmake/FetchedSharedLibrary.cmake b/cmake/FetchedSharedLibrary.cmake index e2bd29b93..08a346da6 100644 --- a/cmake/FetchedSharedLibrary.cmake +++ b/cmake/FetchedSharedLibrary.cmake @@ -6,6 +6,7 @@ endif() # Helper function to download and extract an archive function(download_and_extract archive_name url) + cmake_parse_arguments(ARG "" "SLANG_GITHUB_TOKEN" "" ${ARGN}) cmake_path(GET url FILENAME filename_with_ext) cmake_path(GET url STEM LAST_ONLY file_stem) set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${filename_with_ext}") @@ -26,15 +27,28 @@ function(download_and_extract archive_name url) "Using existing archive for ${archive_name}: ${archive_path}" ) else() - message(STATUS "Fetching ${archive_name} from ${url}") - file(DOWNLOAD ${url} ${archive_path} STATUS status) + set(download_args ${url} ${archive_path} STATUS status) + if(ARG_SLANG_GITHUB_TOKEN) + list( + APPEND + download_args + HTTPHEADER + "Authorization: token ${ARG_SLANG_GITHUB_TOKEN}" + ) + endif() + + file(DOWNLOAD ${download_args}) list(GET status 0 status_code) list(GET status 1 status_string) if(NOT status_code EQUAL 0) message( WARNING - "Failed to download ${archive_name} from ${url}: ${status_string}" + "Failed to download ${archive_name} from ${url}: ${status_string} with status code ${status_code}" + ) + message( + WARNING + "If API rate limit is exceeded, Github allows a higher limit when you use token. Try a cmake option -DSLANG_GITHUB_TOKEN=your_token_here" ) return() endif() @@ -55,8 +69,11 @@ endfunction() # Otherwise, the 'url' is interpreted as an URL, and the content of the URL will be fetched, extracted and searched # for the shared library to produce the install rule. function(copy_fetched_shared_library library_name url) - cmake_parse_arguments(ARG "IGNORE_FAILURE" "" "" ${ARGN}) - if(ARG_IGNORE_FAILURE) + cmake_parse_arguments(ARG "IGNORE_FAILURE" "SLANG_GITHUB_TOKEN" "" ${ARGN}) + + # Don't ignore failure if a Github token is provided; + # as we assume that the token will fix the rate limit issue. + if(ARG_IGNORE_FAILURE AND NOT ARG_SLANG_GITHUB_TOKEN) set(error_type STATUS) else() set(error_type SEND_ERROR) @@ -95,7 +112,11 @@ function(copy_fetched_shared_library library_name url) set(source_object "${url}") else() # Otherwise, download and extract from whatever URL we have - download_and_extract("${library_name}" "${url}") + download_and_extract( + "${library_name}" + "${url}" + SLANG_GITHUB_TOKEN ${ARG_SLANG_GITHUB_TOKEN} + ) if(DEFINED ${library_name}_SOURCE_DIR) from_glob(${${library_name}_SOURCE_DIR}) elseif(ARG_IGNORE_FAILURE) |
