mirror of
https://github.com/open-goal/jak-project
synced 2026-08-27 08:28:03 -04:00
5d5e35fb9b
## Problem Windows builds break with a current local toolchain (Scoop LLVM 22.1.8, CMake 4.4.0, VS 2026), in two independent ways: 1. The build stops at curl's deliberate guard: `#error "no non-blocking method was found/used/set"` in `third-party/curl/lib/nonblock.c`. 2. From the second configure onward, `cmake --build` re-runs CMake in an endless loop (observed 42 consecutive reconfigure cycles in a single build). Likely the same mechanism behind the "endlessly building" VS 2026 note in `docs/setup/dev/vs.md`. ## Root cause 1. `third-party/curl/CMake/CurlTests.c` passes `int *` to `ioctlsocket()`, whose third parameter is `u_long *`. Clang 22 promotes `-Wincompatible-pointer-types` to a hard error in C, so the `HAVE_IOCTLSOCKET_FIONBIO` try_compile silently fails and `curl_config.h` never defines it. Upstream CI does not see this because the windows-2022 runner image ships an older LLVM. GCC 14 promotes the same warning to a hard error, which is very likely the `CurlTests.c.obj` failure reported from MSYS2 in open-goal/jak-project#3551. Upstream curl hit the identical problem with GCC 14 and fixed the probe in curl 8.8.0 (curl/curl#13578). 2. The root CMakeLists copies the build tree's `compile_commands.json` into `<src>/build/` for clangd using `configure_file()`, which registers its input as a configure dependency. CMake rewrites `compile_commands.json` late in every generation, after `CTestTestfile.cmake` and `cmake_install.cmake` (outputs of the same Ninja regen rule), so once the dependency is registered the rule is deterministically dirty and every `ninja` invocation re-runs CMake. A pristine first configure is safe (the file does not exist yet, so the `if(EXISTS ...)` guard skips the copy), which is why the loop looks machine- or IDE-specific. ## Fix 1. Per review, re-vendor `third-party/curl` at the `curl-8_21_0` tag (previously `curl-8_3_0`), which carries the upstream probe fix plus two years of upstream development; `vendor.yaml` updated to match. Adjustments the version jump forced: - curl 8.15 removed the native macOS Secure Transport backend (`CURL_USE_SECTRANSP`), so macOS now builds curl against OpenSSL like Linux. The two macOS workflows install Homebrew `openssl@3` and export `OPENSSL_ROOT_DIR` (keg-only), and the macOS setup docs gained the same two lines. - `CURL_BROTLI` / `CURL_ZSTD` switched to AUTO-detection in curl 8.10; pinned OFF to keep the previous no-compression behavior and avoid silently linking whatever the CI images happen to have. - curl's new top-level `BUILD_EXAMPLES` cache option (default ON) leaked into discord-rpc's identically named option and broke configure at a nonexistent `examples/send-presence` directory; pinned OFF ahead of the third-party subdirectories. The diff is dominated by the mechanical tag-tree swap under `third-party/curl` (linguist-vendored, collapsed in review). The hand-written changes are `CMakeLists.txt`, the two macOS workflows, `docs/setup/system/macos.md`, and `vendor.yaml`. 2. Swap `configure_file()` for `file(COPY ...)`: the same clangd copy with no configure dependency registered. (`file(COPY_FILE ... ONLY_IF_DIFFERENT)` would be cleaner still but requires CMake 3.21, above the declared `cmake_minimum_required(VERSION 3.10)`.) ## Test plan - [x] Fresh `cmake --preset Release-windows-clang` (LLVM 22, no cache seeding) completes and logs `Enabled SSL backends: Schannel`; the FIONBIO probe passes without the previous `#error` - [x] Full Windows Release build from scratch in the branch worktree (all 1422 targets) - [x] goalc-test suite: 1509 passed, 0 failed - [x] Second consecutive configure with `compile_commands.json` present: the regen rule in `build.ninja` has no `compile_commands.json` input; `<src>/build/compile_commands.json` is still refreshed for clangd - [x] Repeated `ninja` invocations after a full build no longer re-run CMake - [x] macOS Intel and ARM CI green (first exercise of the OpenSSL backend switch) --- I work off a self-hosted forge, so this GitHub account is quiet; the configure logs and ninja dirty-node traces from the investigation are available if anyone wants the raw data. (AI-assisted)
268 lines
7.6 KiB
C
Vendored
Generated
268 lines
7.6 KiB
C
Vendored
Generated
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
|
|
/* Base64 encoding/decoding */
|
|
|
|
#include "curl_setup.h"
|
|
|
|
#include "curlx/base64.h"
|
|
|
|
/* ---- Base64 Encoding/Decoding Table --- */
|
|
const char curlx_base64encdec[] =
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
/* The Base 64 encoding with a URL and filename safe alphabet, RFC 4648
|
|
section 5 */
|
|
static const char base64url[] =
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
|
|
static const unsigned char decodetable[] = {
|
|
62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255,
|
|
255, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
|
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
|
|
255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
|
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
|
};
|
|
/*
|
|
* curlx_base64_decode()
|
|
*
|
|
* Given a base64 null-terminated string at src, decode it and return a
|
|
* pointer in *outptr to a newly allocated memory area holding decoded data.
|
|
* Size of decoded data is returned in variable pointed by outlen.
|
|
*
|
|
* Returns CURLE_OK on success, otherwise specific error code. Function
|
|
* output shall not be considered valid unless CURLE_OK is returned.
|
|
*
|
|
* When decoded data length is 0, returns NULL in *outptr.
|
|
*
|
|
* @unittest: 1302
|
|
*/
|
|
CURLcode curlx_base64_decode(const char *src,
|
|
uint8_t **outptr, size_t *outlen)
|
|
{
|
|
size_t srclen = 0;
|
|
size_t padding = 0;
|
|
size_t i;
|
|
size_t numQuantums;
|
|
size_t fullQuantums;
|
|
size_t rawlen = 0;
|
|
unsigned char *pos;
|
|
unsigned char *newstr;
|
|
unsigned char lookup[256];
|
|
|
|
*outptr = NULL;
|
|
*outlen = 0;
|
|
srclen = strlen(src);
|
|
|
|
/* Check the length of the input string is valid */
|
|
if(!srclen || srclen % 4)
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
/* srclen is at least 4 here */
|
|
while(src[srclen - 1 - padding] == '=') {
|
|
/* count padding characters */
|
|
padding++;
|
|
/* A maximum of two = padding characters is allowed */
|
|
if(padding > 2)
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
}
|
|
|
|
/* Calculate the number of quantums */
|
|
numQuantums = srclen / 4;
|
|
fullQuantums = numQuantums - (padding ? 1 : 0);
|
|
|
|
/* Calculate the size of the decoded string */
|
|
rawlen = (numQuantums * 3) - padding;
|
|
|
|
/* Allocate our buffer including room for a null-terminator */
|
|
newstr = curlx_malloc(rawlen + 1);
|
|
if(!newstr)
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
pos = newstr;
|
|
|
|
memset(lookup, 0xff, sizeof(lookup));
|
|
memcpy(&lookup['+'], decodetable, sizeof(decodetable));
|
|
|
|
/* Decode the complete quantums first */
|
|
for(i = 0; i < fullQuantums; i++) {
|
|
unsigned char val;
|
|
unsigned int x = 0;
|
|
int j;
|
|
|
|
for(j = 0; j < 4; j++) {
|
|
val = lookup[(unsigned char)*src++];
|
|
if(val == 0xff) /* bad symbol */
|
|
goto bad;
|
|
x = (x << 6) | val;
|
|
}
|
|
pos[2] = x & 0xff;
|
|
pos[1] = (x >> 8) & 0xff;
|
|
pos[0] = (x >> 16) & 0xff;
|
|
pos += 3;
|
|
}
|
|
if(padding) {
|
|
/* this means either 8 or 16 bits output */
|
|
unsigned char val;
|
|
unsigned int x = 0;
|
|
int j;
|
|
size_t padc = 0;
|
|
for(j = 0; j < 4; j++) {
|
|
if(*src == '=') {
|
|
x <<= 6;
|
|
src++;
|
|
if(++padc > padding)
|
|
/* this is a badly placed '=' symbol! */
|
|
goto bad;
|
|
}
|
|
else {
|
|
val = lookup[(unsigned char)*src++];
|
|
if(val == 0xff) /* bad symbol */
|
|
goto bad;
|
|
x = (x << 6) | val;
|
|
}
|
|
}
|
|
if(padding == 1)
|
|
pos[1] = (x >> 8) & 0xff;
|
|
pos[0] = (x >> 16) & 0xff;
|
|
pos += 3 - padding;
|
|
}
|
|
|
|
/* Null-terminate */
|
|
*pos = '\0';
|
|
|
|
/* Return the decoded data */
|
|
*outptr = newstr;
|
|
*outlen = rawlen;
|
|
|
|
return CURLE_OK;
|
|
bad:
|
|
curlx_free(newstr);
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
}
|
|
|
|
static CURLcode base64_encode(const char *table64,
|
|
uint8_t padbyte,
|
|
const uint8_t *inputbuff, size_t insize,
|
|
char **outptr, size_t *outlen)
|
|
{
|
|
char *output;
|
|
char *base64data;
|
|
const unsigned char *in = (const unsigned char *)inputbuff;
|
|
|
|
*outptr = NULL;
|
|
*outlen = 0;
|
|
|
|
if(!insize)
|
|
return CURLE_OK;
|
|
|
|
/* safety precaution */
|
|
DEBUGASSERT(insize <= CURL_MAX_BASE64_INPUT);
|
|
if(insize > CURL_MAX_BASE64_INPUT)
|
|
return CURLE_TOO_LARGE;
|
|
|
|
base64data = output = curlx_malloc(((insize + 2) / 3 * 4) + 1);
|
|
if(!output)
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
while(insize >= 3) {
|
|
*output++ = table64[in[0] >> 2];
|
|
*output++ = table64[((in[0] & 0x03) << 4) | (in[1] >> 4)];
|
|
*output++ = table64[((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6)];
|
|
*output++ = table64[in[2] & 0x3F];
|
|
insize -= 3;
|
|
in += 3;
|
|
}
|
|
if(insize) {
|
|
/* this is only one or two bytes now */
|
|
*output++ = table64[in[0] >> 2];
|
|
if(insize == 1) {
|
|
*output++ = table64[((in[0] & 0x03) << 4)];
|
|
if(padbyte) {
|
|
*output++ = padbyte;
|
|
*output++ = padbyte;
|
|
}
|
|
}
|
|
else {
|
|
/* insize == 2 */
|
|
*output++ = table64[((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4)];
|
|
*output++ = table64[((in[1] & 0x0F) << 2)];
|
|
if(padbyte)
|
|
*output++ = padbyte;
|
|
}
|
|
}
|
|
|
|
/* Null-terminate */
|
|
*output = '\0';
|
|
|
|
/* Return the pointer to the new data (allocated memory) */
|
|
*outptr = base64data;
|
|
|
|
/* Return the length of the new data */
|
|
*outlen = (size_t)(output - base64data);
|
|
|
|
return CURLE_OK;
|
|
}
|
|
|
|
/*
|
|
* curlx_base64_encode()
|
|
*
|
|
* Given a pointer to an input buffer and an input size, encode it and
|
|
* return a pointer in *outptr to a newly allocated memory area holding
|
|
* encoded data. Size of encoded data is returned in variable pointed by
|
|
* outlen.
|
|
*
|
|
* Returns CURLE_OK on success, otherwise specific error code. Function
|
|
* output shall not be considered valid unless CURLE_OK is returned.
|
|
*
|
|
* @unittest: 1302
|
|
*/
|
|
CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize,
|
|
char **outptr, size_t *outlen)
|
|
{
|
|
return base64_encode(curlx_base64encdec, '=',
|
|
inputbuff, insize, outptr, outlen);
|
|
}
|
|
|
|
/*
|
|
* curlx_base64url_encode()
|
|
*
|
|
* Given a pointer to an input buffer and an input size, encode it and
|
|
* return a pointer in *outptr to a newly allocated memory area holding
|
|
* encoded data. Size of encoded data is returned in variable pointed by
|
|
* outlen.
|
|
*
|
|
* Input length of 0 indicates input buffer holds a null-terminated string.
|
|
*
|
|
* Returns CURLE_OK on success, otherwise specific error code. Function
|
|
* output shall not be considered valid unless CURLE_OK is returned.
|
|
*
|
|
* @unittest: 1302
|
|
*/
|
|
CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize,
|
|
char **outptr, size_t *outlen)
|
|
{
|
|
return base64_encode(base64url, 0, inputbuff, insize, outptr, outlen);
|
|
}
|