Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/sdk-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,17 @@ This sets:
- `RANLIB=wasm32posix-ranlib`
- `NM=wasm32posix-nm`
- `STRIP=wasm32posix-strip`
- `--host=wasm32-unknown-none`
- `--host=wasm32-unknown-linux-musl`
- `--build` (auto-detected from host system)

The `--host` tuple describes Kandelo's musl userland to GNU build systems.
GNU `config.sub` only accepts musl when paired with a Linux kernel component,
so this is the canonical tuple that lets Autoconf and gnulib select musl ABI
and libc behavior. It is not the compiler code-generation triple and does not
promise a Linux kernel: `wasm32posix-cc` continues to invoke Clang with
`--target=wasm32-unknown-unknown`, and Kandelo's documented POSIX surface
remains authoritative.

The wrapper also loads `sdk/config.site`. That file is authoritative for
shared target facts that cross-compilation cannot discover reliably, including
functions present in the Kandelo musl sysroot and extension functions that are
Expand Down
2 changes: 1 addition & 1 deletion packages/registry/curl/test/curl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe.skipIf(!READY)("curl CLI package", () => {
expect(stderr).toBe("");
expect(exitCode).toBe(0);
expect(stdout).toContain(
"curl 8.11.1 (wasm32-unknown-none) libcurl/8.11.1 OpenSSL/3.3.2 zlib/1.3.1",
"curl 8.11.1 (wasm32-unknown-linux-musl) libcurl/8.11.1 OpenSSL/3.3.2 zlib/1.3.1",
);
expect(stdout).toContain("Protocols: file ftp ftps http https");
}, 60_000);
Expand Down
19 changes: 18 additions & 1 deletion packages/registry/netcat/build-netcat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ if ! command -v wasm32posix-cc &>/dev/null; then
exit 1
fi

if ! command -v automake &>/dev/null; then
echo "ERROR: automake not found in the Kandelo dev shell." >&2
exit 1
fi

if [ ! -f "$SYSROOT/lib/libc.a" ]; then
echo "ERROR: sysroot not found. Run: bash scripts/build-musl.sh" >&2
exit 1
Expand Down Expand Up @@ -60,6 +65,19 @@ fi

cd "$SRC_DIR"

# GNU Netcat 0.7.1 predates Wasm and musl target tuples. Use the canonical
# helpers from the declared Automake build input so configure can validate the
# SDK's truthful wasm*-unknown-linux-musl host identity on every POSIX builder.
AUTOMAKE_AUX_DIR="$(automake --print-libdir)"
for auxiliary in config.sub config.guess; do
source_auxiliary="$AUTOMAKE_AUX_DIR/$auxiliary"
if [ ! -f "$source_auxiliary" ] || [ -L "$source_auxiliary" ]; then
echo "ERROR: Automake support file is unavailable: $source_auxiliary" >&2
exit 1
fi
install -m 0755 "$source_auxiliary" "$SRC_DIR/$auxiliary"
done

PATCH_MARKER="$SRC_DIR/.kandelo-patches-applied"
PATCH_SET=(
"listen-success-exit.patch"
Expand Down Expand Up @@ -121,7 +139,6 @@ if [ ! -f Makefile ]; then
export gl_cv_func_gettimeofday_clobber=no

wasm32posix-configure \
--build=arm-apple-darwin \
--disable-nls \
--without-included-gettext \
2>&1 | tail -40
Expand Down
2 changes: 1 addition & 1 deletion packages/registry/netcat/build.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
script_path = "packages/registry/netcat/build-netcat.sh"
repo_url = "https://github.com/brandonpayton/kandelo.git"
commit = "2e6293a50ccf996b1a434aa701057b862a46c587"
revision = 2
revision = 3

[binary]
index_url = "https://github.com/Automattic/kandelo/releases/download/binaries-abi-v{abi}/index.toml"
16 changes: 14 additions & 2 deletions packages/registry/php/build-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1073,22 +1073,34 @@ fi
# itself is unaffected). A macro undefined for a symbol the package does export
# silently compiles the feature out — here, the "table" key of
# PDOStatement::getColumnMeta() (#577).
# PHP's fopencookie probe is also distorted by wasm cross-linking. Kandelo's
# PHP's fopencookie probe is also distorted by cross-compilation. Kandelo's
# musl sysroot provides fopencookie(3), and PHP uses it for generic stream →
# stdio casts rather than requiring every user stream wrapper to implement its
# own stream_cast method.
# own stream_cast method. PHP cannot run its callback-signature probe while
# cross-compiling and assumes every *linux* host uses glibc's off64_t callback.
# musl's cookie_seek_function_t uses off_t instead, so keep fopencookie enabled
# while rejecting that glibc-only fallback.
if [ -f main/php_config.h ]; then
sed -i.bak \
-e 's|^/\* #undef HAVE_SQLITE3_EXPANDED_SQL \*/|#define HAVE_SQLITE3_EXPANDED_SQL 1|' \
-e 's|^/\* #undef HAVE_SQLITE3_COLUMN_TABLE_NAME \*/|#define HAVE_SQLITE3_COLUMN_TABLE_NAME 1|' \
-e 's|^/\* #undef SQLITE_OMIT_LOAD_EXTENSION \*/|#define SQLITE_OMIT_LOAD_EXTENSION 1|' \
-e 's|^/\* #undef HAVE_FOPENCOOKIE \*/|#define HAVE_FOPENCOOKIE 1|' \
-e 's|^#define COOKIE_SEEKER_USES_OFF64_T 1|/* #undef COOKIE_SEEKER_USES_OFF64_T */|' \
-e 's|^/\* #undef HAVE_PRCTL \*/|#define HAVE_PRCTL 1|' \
-e 's|^#define HAVE_FORKX 1|/* #undef HAVE_FORKX */|' \
-e 's|^#define HAVE_RFORK 1|/* #undef HAVE_RFORK */|' \
-e 's|^#define PHP_OS .*|#define PHP_OS "Kandelo"|' \
-e 's|^#define PHP_UNAME .*|#define PHP_UNAME "Kandelo wasm32-posix-kernel"|' \
main/php_config.h && rm -f main/php_config.h.bak
grep -q '^#define HAVE_FOPENCOOKIE 1$' main/php_config.h || {
echo "ERROR: PHP config did not retain Kandelo musl fopencookie support" >&2
exit 1
}
if grep -q '^#define COOKIE_SEEKER_USES_OFF64_T 1$' main/php_config.h; then
echo "ERROR: PHP config retained the glibc-only fopencookie callback type" >&2
exit 1
fi
# PHP's generated object dependencies do not reliably notice the
# php_config.h feature override above after an incremental rebuild. Force
# the stream-casting unit to be rebuilt so generic stream→FILE* casts use
Expand Down
6 changes: 6 additions & 0 deletions sdk/config.site
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# compilation (link tests fail, run tests impossible). Values reflect our
# musl libc + selected Wasm target.
#
# The configure wrapper identifies that userland to GNU build systems as
# wasm*-unknown-linux-musl because config.sub only accepts musl with a Linux
# kernel component. LLVM code generation remains wasm*-unknown-unknown. The
# configure identity selects musl libc contracts; it does not promise Linux
# kernel behavior or define __linux__ in compiled programs.
#
# IMPORTANT: Function availability is based on what musl libc provides
# (i.e., what links), NOT on kernel implementation completeness. If
# `wasm32posix-nm sysroot/lib/libc.a | grep ' T funcname'` shows the
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/bin/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { runPassthrough } from '../lib/exec.ts';
import { isMain } from '../lib/is-main.ts';
import { type WasmArch, detectArch, hostTriple, toolPrefix } from '../lib/arch.ts';
import { type WasmArch, autoconfHostTriple, detectArch, toolPrefix } from '../lib/arch.ts';

const __configure_filename = fileURLToPath(import.meta.url);
const SDK_ROOT = resolve(dirname(__configure_filename), '../..');
Expand Down Expand Up @@ -41,7 +41,7 @@ export function buildConfigureEnv(arch: WasmArch = 'wasm32'): Record<string, str

export function buildConfigureArgs(userArgs: string[], arch: WasmArch = 'wasm32'): string[] {
return [
`--host=${hostTriple(arch)}`,
`--host=${autoconfHostTriple(arch)}`,
'--prefix=/usr',
...userArgs,
];
Expand Down
13 changes: 11 additions & 2 deletions sdk/src/lib/arch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ export function targetTriple(arch: WasmArch): string {
return `${arch}-unknown-unknown`;
}

export function hostTriple(arch: WasmArch): string {
return `${arch}-unknown-none`;
/**
* GNU build-system identity for Kandelo's musl userland.
*
* This is deliberately separate from targetTriple(): config.sub requires a
* Linux kernel component for a musl tuple, while LLVM does not support that
* tuple for Wasm code generation. The value lets Autoconf and gnulib select
* musl ABI and libc behavior; it does not claim that Kandelo has a Linux
* kernel or define __linux__ for compiled programs.
*/
export function autoconfHostTriple(arch: WasmArch): string {
return `${arch}-unknown-linux-musl`;
}

export function toolPrefix(arch: WasmArch): string {
Expand Down
6 changes: 5 additions & 1 deletion sdk/test/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ function gnulibSiteFacts(overrides: Record<string, string> = {}): string[] {
describe('buildConfigureArgs', () => {
it('includes --host and --prefix', () => {
const args = buildConfigureArgs([]);
expect(args).toContain('--host=wasm32-unknown-none');
expect(args).toContain('--host=wasm32-unknown-linux-musl');
expect(args).toContain('--prefix=/usr');
});

it('uses the musl userland identity for wasm64 as well', () => {
expect(buildConfigureArgs([], 'wasm64')).toContain('--host=wasm64-unknown-linux-musl');
});

it('forwards extra user args', () => {
const args = buildConfigureArgs(['--disable-shared', '--without-pear']);
expect(args).toContain('--disable-shared');
Expand Down
Loading