Skip to content
Draft
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
46 changes: 46 additions & 0 deletions .github/probe/common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Shared by the Windows probe scripts. Prints and never asserts.
$ErrorActionPreference = 'Continue'
$PSNativeCommandUseErrorActionPreference = $false
function Say($m) { Write-Host "`n===== $m =====" }
function Show([scriptblock]$b, [int]$last = 0) {
Write-Host ('$ ' + $b.ToString().Trim())
$out = & $b 2>&1 | ForEach-Object { "$_" }
if ($last -gt 0) { $out | Select-Object -Last $last | ForEach-Object { Write-Host $_ } }
else { $out | ForEach-Object { Write-Host $_ } }
Write-Host "[exit $LASTEXITCODE]"
}
$T = Join-Path $env:RUNNER_TEMP 'probe'
New-Item -ItemType Directory -Force $T | Out-Null

function Get-Mcpp {
$zip = Join-Path $T 'mcpp.zip'
if (-not (Test-Path $zip)) {
Invoke-WebRequest -Uri "https://github.com/mcpp-community/mcpp/releases/download/v$($env:MCPP_VERSION)/mcpp-windows-x86_64.zip" -OutFile $zip
Expand-Archive -LiteralPath $zip -DestinationPath (Join-Path $T 'mcpp') -Force
}
(Get-ChildItem -LiteralPath (Join-Path $T 'mcpp') -Recurse -Filter mcpp.exe | Select-Object -First 1).FullName
}

function Get-Alias-Drive([string]$target) {
foreach ($l in 'Z','Y','X','W','V') {
if (-not (Test-Path "${l}:\")) {
& subst "${l}:" $target | Out-Null
if (Test-Path "${l}:\") { return "${l}:" }
}
}
return $null
}

function New-Hello([string]$dir) {
New-Item -ItemType Directory -Force (Join-Path $dir 'src') | Out-Null
@"
[package]
name = "hello"
version = "0.1.0"

[targets.hello]
kind = "bin"
main = "src/main.cpp"
"@ | Set-Content -Encoding utf8 (Join-Path $dir 'mcpp.toml')
"#include <cstdio>`nint main() { std::puts(`"hello`"); return 0; }`n" | Set-Content -Encoding utf8 (Join-Path $dir 'src\main.cpp')
}
59 changes: 59 additions & 0 deletions .github/probe/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Shared by the probe scripts: fetch the released mcpp and xlings, print helpers.
# Sourced; prints and never asserts.

say() { printf '\n===== %s =====\n' "$*"; }
show() { printf '$ %s\n' "$*"; "$@" 2>&1; printf '[exit %s]\n' "$?"; }
tailed() { # $1 = lines, rest = command; prints the tail and the exit status
local n="$1"; shift
printf '$ %s\n' "$*"
"$@" > "$PROBE_TMP/last.log" 2>&1
local rc=$?
tail -n "$n" "$PROBE_TMP/last.log"
printf '[exit %s]\n' "$rc"
return 0
}

PROBE_TMP="${RUNNER_TEMP:-/tmp}/probe"
mkdir -p "$PROBE_TMP"

fetch_mcpp() {
local os arch asset
case "$(uname -s)" in Linux) os=linux ;; Darwin) os=macosx ;; esac
case "$(uname -m)" in x86_64) arch=x86_64 ;; arm64|aarch64) arch=$([ "$os" = macosx ] && echo arm64 || echo aarch64) ;; esac
asset="mcpp-${os}-${arch}.tar.gz"
curl -fsSL -o "$PROBE_TMP/$asset" \
"https://github.com/mcpp-community/mcpp/releases/download/v${MCPP_VERSION}/${asset}"
mkdir -p "$PROBE_TMP/mcpp"
tar -xzf "$PROBE_TMP/$asset" -C "$PROBE_TMP/mcpp"
MCPP="$(find "$PROBE_TMP/mcpp" -type f -name mcpp -perm -u+x | head -1)"
export MCPP
echo "MCPP=$MCPP"
"$MCPP" --version
}

fetch_xlings() {
local asset="xlings-${XLINGS_VERSION}-linux-x86_64.tar.gz"
curl -fsSL -o "$PROBE_TMP/$asset" \
"https://github.com/openxlings/xlings/releases/download/v${XLINGS_VERSION}/${asset}"
mkdir -p "$PROBE_TMP/xlings"
tar -xzf "$PROBE_TMP/$asset" -C "$PROBE_TMP/xlings"
XLINGS_BIN="$(find "$PROBE_TMP/xlings" -type f -name xlings -perm -u+x | head -1)"
export XLINGS_BIN
echo "XLINGS_BIN=$XLINGS_BIN"
find "$PROBE_TMP/xlings" -maxdepth 3 | head -30
"$XLINGS_BIN" --version
}

hello_project() { # $1 = directory
mkdir -p "$1/src"
cat > "$1/mcpp.toml" <<'TOML'
[package]
name = "hello"
version = "0.1.0"

[targets.hello]
kind = "bin"
main = "src/main.cpp"
TOML
printf '#include <cstdio>\nint main() { std::puts("hello"); return 0; }\n' > "$1/src/main.cpp"
}
63 changes: 63 additions & 0 deletions .github/probe/m1_windows_alias.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# M1: the image name and the working directory a program reads when mcpp starts
# it from a substituted drive, beside the same program started directly.
. "$PSScriptRoot\common.ps1"
$mcpp = Get-Mcpp
Write-Host "mcpp: $mcpp"
Show { & $mcpp --version }

Say 'a program that reports how it was started'
$spySrc = Join-Path $T 'spy.c'
@'
#include <windows.h>
#include <stdio.h>
int main(void) {
char image[4096]; char cwd[4096];
GetModuleFileNameA(NULL, image, sizeof image);
GetCurrentDirectoryA(sizeof cwd, cwd);
fprintf(stderr, "[spy] module=%s | cwd=%s | drives=0x%08lx | command=%s\n",
image, cwd, (unsigned long)GetLogicalDrives(), GetCommandLineA());
return 86;
}
'@ | Set-Content -Encoding ascii $spySrc
$spy = Join-Path $T 'spy.exe'
$gcc = Get-Command gcc -ErrorAction SilentlyContinue
if ($gcc) {
Show { & gcc $spySrc -o $spy -static }
} else {
$vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
Show { cmd /c "`"$vs\VC\Auxiliary\Build\vcvars64.bat`" >nul && cl /nologo /MT `"$spySrc`" /Fe:`"$spy`"" }
}
Write-Host "spy built: $(Test-Path $spy)"

$stage = Join-Path $T 'stage'
New-Item -ItemType Directory -Force (Join-Path $stage 'tc\bin') | Out-Null
Copy-Item $spy (Join-Path $stage 'tc\bin\clang++.exe') -Force
Copy-Item $spy (Join-Path $stage 'tc\bin\clang.exe') -Force
$Z = Get-Alias-Drive $stage
Write-Host "alias drive: $Z -> $stage"
Show { & subst }

Say 'M1 control: started directly'
Show { & "$Z\tc\bin\clang++.exe" --version }
Show { & (Join-Path $stage 'tc\bin\clang++.exe') --version }

$env:MCPP_HOME = Join-Path $T 'mh'
New-Hello (Join-Path $stage 'proj')

Say 'M1: started by mcpp, toolchain named on the alias, project on the alias'
$env:MCPP_TOOLCHAIN = "path:$Z/tc"
Push-Location "$Z\proj"
Show { & $mcpp build } 12
Pop-Location

Say 'M1: started by mcpp, toolchain named on the alias, project on the physical path'
Push-Location (Join-Path $stage 'proj')
Show { & $mcpp build } 12
Pop-Location

Say 'M1: started by mcpp, toolchain named by the physical path'
$env:MCPP_TOOLCHAIN = "path:$($stage -replace '\\','/')/tc"
Push-Location "$Z\proj"
Show { & $mcpp build } 12
Pop-Location
Remove-Item Env:MCPP_TOOLCHAIN
70 changes: 70 additions & 0 deletions .github/probe/m2_xlings_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# M2: an environment declares one version of a compiler; a payload installed into
# it depends on another. What xlings does, and what mcpp does with the same two
# statements. Prints, never asserts.
. "$(dirname "$0")/common.sh"
export XLINGS_AGENT_MODE=1
fetch_xlings
export XLINGS_HOME="$PROBE_TMP/xlings-home"
mkdir -p "$XLINGS_HOME"
say "a home for the released xlings"
show "$XLINGS_BIN" self install --help
tailed 15 "$XLINGS_BIN" --version
X="$XLINGS_BIN"

cat > "$PROBE_TMP/probe-sdk.lua" <<'LUA'
package = {
spec = "1",
name = "probe-sdk",
description = "probe: a library payload that depends on one version of a compiler",
licenses = {"MIT"},
type = "package",
archs = {"x86_64"},
status = "dev",
xpm = {
linux = {
deps = { "xim:gcc@16.1.0" },
["latest"] = { ref = "1.0.0" },
["1.0.0"] = {},
},
},
}
function installed() return false end
function install() return true end
function uninstall() return true end
LUA

P="$PROBE_TMP/m2-project"; mkdir -p "$P"; cd "$P"
printf '{ "workspace": { "gcc": { "linux": "15.1.0" } } }\n' > .xlings.json
say "M2 step 1: the project declares gcc 15.1.0"
tailed 25 "$X" install
show cat .xlings.json
show sh -c 'ls -la .xlings 2>/dev/null; ls .xlings/subos 2>/dev/null; ls .xlings/subos/_/bin 2>/dev/null | head -20'
GCC_SHIM="$(ls "$P"/.xlings/subos/_/bin/gcc "$XLINGS_HOME"/subos/*/bin/gcc 2>/dev/null | head -1)"
echo "GCC_SHIM=$GCC_SHIM"
[ -n "$GCC_SHIM" ] && show "$GCC_SHIM" --version
show sh -c "ls $XLINGS_HOME/data/xpkgs 2>/dev/null; ls $XLINGS_HOME/data/xpkgs/xim-x-gcc 2>/dev/null"

say "M2 step 2: a payload that depends on xim:gcc@16.1.0 is installed into the project"
tailed 20 "$X" config --add-xpkg "$PROBE_TMP/probe-sdk.lua"
tailed 10 "$X" config --list-xpkg
tailed 40 "$X" install probe-sdk@1.0.0
show cat .xlings.json
show sh -c "ls $XLINGS_HOME/data/xpkgs/xim-x-gcc 2>/dev/null"
[ -n "$GCC_SHIM" ] && show "$GCC_SHIM" --version
show sh -c 'cat .xlings/subos/_/.xlings.json 2>/dev/null | head -60'
tailed 30 "$X" list
tailed 30 "$X" self doctor

say "M2 step 3: the same two statements through mcpp ([toolchain] and [xlings.workspace])"
export MCPP_HOME="$PROBE_TMP/mcpp-home"
fetch_mcpp
M="$PROBE_TMP/m2-mcpp"; hello_project "$M"
printf '\n[toolchain]\nlinux = "gcc@15.1.0"\n\n[xlings.workspace]\n"xim:gcc" = "16.1.0"\n' >> "$M/mcpp.toml"
( cd "$M" && tailed 40 "$MCPP" build )
show sh -c "ls $MCPP_HOME/registry/data/xpkgs/xim-x-gcc 2>/dev/null"
say "M2 step 4: a floor instead of a version"
sed -i 's/"xim:gcc" = "16.1.0"/"xim:gcc" = ">=16.1.0"/' "$M/mcpp.toml"
( cd "$M" && tailed 40 "$MCPP" build )
say "M2 step 5: how a library payload of the index states its runtime (for comparison)"
show sh -c "grep -n 'deps' $XLINGS_HOME/data/xim-pkgindex/pkgs/l/libxcb.lua $XLINGS_HOME/data/xim-pkgindex/pkgs/h/harfbuzz.lua 2>/dev/null | head"
93 changes: 93 additions & 0 deletions .github/probe/m3_emscripten_longjmp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# M3: on wasm32-emscripten, which units receive the long-jump model, under the
# row's default and under each statement. Prints, never asserts.
. "$(dirname "$0")/common.sh"
export MCPP_HOME="$PROBE_TMP/mcpp-home"
fetch_mcpp

W="$PROBE_TMP/m3"; rm -rf "$W"; mkdir -p "$W"

jump_c() {
cat > "$1" <<'C'
#include <setjmp.h>
static jmp_buf where;
static void fail(int code) { longjmp(where, code); }
int jumped(int code) {
if (setjmp(where)) return 1;
fail(code);
return 0;
}
C
}
main_cpp() {
cat > "$1" <<'CPP'
#include <cstdio>
#include <stdexcept>
extern "C" int jumped(int code);
int main() {
try {
if (jumped(7) != 1) throw std::runtime_error("longjmp did not come back");
} catch (const std::exception& error) {
std::puts(error.what());
return 1;
}
std::puts("ok");
return 0;
}
CPP
}

# $1 = name, $2 = where the C unit is (root|dep), $3 = abi table body or empty
variant() {
local name="$1" where="$2" abi="$3" d="$W/$1"
mkdir -p "$d/app/src"
main_cpp "$d/app/src/main.cpp"
{
printf '[package]\nname = "app"\nversion = "0.1.0"\n\n[targets.app]\nkind = "bin"\nmain = "src/main.cpp"\n'
if [ "$where" = dep ]; then printf '\n[dependencies]\njumplib = { path = "../jumplib" }\n'
else printf '\n[build]\nsources = ["src/*.c"]\n'; fi
if [ -n "$abi" ]; then printf "\n[target.'cfg(os = \"emscripten\")'.abi]\n%s\n" "$abi"; fi
} > "$d/app/mcpp.toml"
if [ "$where" = dep ]; then
mkdir -p "$d/jumplib/src"
jump_c "$d/jumplib/src/jump.c"
printf '[package]\nname = "jumplib"\nversion = "0.1.0"\n\n[targets.jumplib]\nkind = "lib"\n\n[build]\nsources = ["src/*.c"]\n' > "$d/jumplib/mcpp.toml"
else
jump_c "$d/app/src/jump.c"
fi
say "M3 $name: C unit in the $where package; abi: ${abi:-<none stated>}"
( cd "$d/app" && "$MCPP" build --target wasm32-emscripten -v > "$d/build.log" 2>&1; echo "[exit $?]" >> "$d/build.log" )
echo "-- the words of the C unit's compile that concern the model:"
grep -E 'jump\.c' "$d/build.log" | grep -E -- ' -c ' | head -2 \
| grep -oE -- '(emcc|em\+\+|clang[^ ]*)|-fwasm-exceptions|-fexceptions|-sSUPPORT_LONGJMP=[a-z]+|-pthread' | tr '\n' ' '
echo
echo "-- the words of the C++ unit's compile:"
grep -E 'main\.cpp' "$d/build.log" | grep -E -- ' -c ' | head -1 \
| grep -oE -- '-fwasm-exceptions|-fexceptions|-sSUPPORT_LONGJMP=[a-z]+' | tr '\n' ' '
echo
echo "-- the words of the link:"
grep -E -- '-o bin/app' "$d/build.log" | head -1 \
| grep -oE -- '-fwasm-exceptions|-fexceptions|-sSUPPORT_LONGJMP=[a-z]+' | tr '\n' ' '
echo
echo "-- errors and the end of the build:"
grep -nE 'error|undefined symbol|emscripten_longjmp' "$d/build.log" | head -8
tail -n 4 "$d/build.log"
local js; js=$(find "$d/app/target" -name 'app.js' 2>/dev/null | head -1)
if [ -n "$js" ] && command -v node >/dev/null; then echo "-- run:"; node "$js"; echo "[run exit $?]"; fi
}

node --version 2>/dev/null
variant v1-root-default root ''
variant v2-root-exc-wasm root 'exceptions = "wasm"'
variant v3-root-both root 'exceptions = "wasm"
longjmp = "wasm"'
variant v4-dep-default dep ''
variant v5-dep-exc-wasm dep 'exceptions = "wasm"'
variant v6-dep-both dep 'exceptions = "wasm"
longjmp = "wasm"'
variant v7-dep-js dep 'exceptions = "js"'

say "M3: the first failing build log in full (tail 60)"
for v in v1-root-default v4-dep-default v6-dep-both; do
echo "--- $v"; tail -n 60 "$W/$v/build.log" | cut -c1-600
done
45 changes: 45 additions & 0 deletions .github/probe/m4_linux_path_tree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# M4 (Linux): the runner's own compiler tree named by path, with the released
# mcpp. Which builds succeed, and against which C library each program links.
. "$(dirname "$0")/common.sh"
export MCPP_HOME="$PROBE_TMP/mcpp-home"
fetch_mcpp
say "the runner's tree"
show g++ --version
show ls -la /usr/bin/g++ /usr/bin/gcc /usr/bin/ar /usr/bin/ld /usr/bin/clang++
show ldd --version

W="$PROBE_TMP/m4l"; rm -rf "$W"; mkdir -p "$W"
# $1 = name, $2 = toolchain table, $3 = with build program (yes|no)
variant() {
local name="$1" table="$2" bp="$3" d="$W/$1"
hello_project "$d"
printf '\n[toolchain]\nlinux = %s\n' "$table" >> "$d/mcpp.toml"
if [ "$bp" = yes ]; then
printf '#include <cstdio>\n#include <linux/errno.h>\n#if defined(__clang__)\n#error build program compiled by clang\n#endif\nint main() { std::puts("build program ran"); return 0; }\n' > "$d/build.mcpp"
fi
say "M4-linux $name: linux = $table ; build program: $bp"
( cd "$d" && "$MCPP" build -v > "$d/build.log" 2>&1; echo "[exit $?]" >> "$d/build.log" )
grep -nE '^error|error:|warning:|Resolved|Using|Target |compiler |c-abi|c\+\+-abi|build\.mcpp' "$d/build.log" | head -24 | cut -c1-400
tail -n 6 "$d/build.log" | cut -c1-500
local bin; bin=$(find "$d/target" -path '*/bin/hello' -type f 2>/dev/null | head -1)
if [ -n "$bin" ]; then
echo "-- the program: interpreter and needed libraries"
readelf -l "$bin" | grep -i 'interpreter'
readelf -d "$bin" | grep -E 'NEEDED|RPATH|RUNPATH' | cut -c1-300
"$bin"; echo "[run exit $?]"
fi
local n; n=$(find "$d/target/.build-mcpp" -name build.ninja 2>/dev/null | head -1)
if [ -n "$n" ]; then
echo "-- the build programs' sub-build: its tools"
grep -nE '^(cxx|cc|ar) ' "$n" | cut -c1-200
cat "$(dirname "$(dirname "$(dirname "$(dirname "$n")")")")/.mcpp-build-programs" 2>/dev/null
fi
}
variant a-path-only '{ path = "/usr" }' no
variant b-family '{ path = "/usr", family = "gcc" }' no
variant c-family-sysroot '{ path = "/usr", family = "gcc", sysroot = "/" }' no
variant d-bp-family '{ path = "/usr", family = "gcc" }' yes
variant e-bp-sysroot '{ path = "/usr", family = "gcc", sysroot = "/" }' yes
say "M4-linux: full tails"
for v in a-path-only c-family-sysroot e-bp-sysroot; do echo "--- $v"; tail -n 40 "$W/$v/build.log" | cut -c1-700; done
Loading
Loading