Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.2] - 2026-06-05
### Added
- Added explicit `STACKMAN_ABI` override support in the Makefile and ABI probe script for deterministic cross-build packaging

Comment thread
kristjanvalur marked this conversation as resolved.
### Changed
- Windows MSVC library projects now compile with `/Zl` to omit embedded default runtime library directives from generated object files
- Windows static libraries no longer carry `/DEFAULTLIB:"MSVCRTD"` metadata, reducing unintended CRT coupling for downstream linkers
- Normalized Windows ARM64 ABI naming to `win_arm64` and kept compatibility mapping for legacy `win_aarch64` inputs
- ABI probe diagnostics now query compiler target triple and emit clearer mismatch guidance when target intent is not fully propagated through wrapper/toolchain settings
- Target triple probing now prefers `CC` with `CFLAGS` (with fallback probing) so clang-style cross-target flags are reflected in secondary detection

## [1.2.1] - 2026-05-09

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ CXX = $(PLATFORM_PREFIX)-g++
LD = $(PLATFORM_PREFIX)-ld
AR = $(PLATFORM_PREFIX)-ar
endif
# run c preprocessor with any cflags to get cross compilation result, then run regular compile in native
# Allow explicit ABI selection for deterministic cross-build packaging.
# If not provided, auto-detect from compiler macros.
ifeq ($(strip $(STACKMAN_ABI)),)
ABI := $(shell sh tools/abiname.sh "$(CC)" "$(CFLAGS)")
else
# Accept legacy alias for backward compatibility.
ABI := $(patsubst win_aarch64,win_arm64,$(STACKMAN_ABI))
Comment thread
kristjanvalur marked this conversation as resolved.
Outdated
endif
ifndef ABI
$(error Could not determine platform)
endif
Expand Down
2 changes: 1 addition & 1 deletion stackman/platforms/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#elif defined(_M_ARM64)
#include "switch_arm64_msvc.h" /* MS Visual Studio on ARM */
#define _STACKMAN_PLATFORM arm64_msvc
#define _STACKMAN_ABI win_aarch64
#define _STACKMAN_ABI win_arm64
#endif


Expand Down
69 changes: 68 additions & 1 deletion tools/abiname.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,54 @@
# run the provided code.
set -eu
here=$(dirname "$0")

canonicalize_abi() {
case "$1" in
win_aarch64) printf '%s\n' "win_arm64" ;;
*) printf '%s\n' "$1" ;;
esac
}

detect_target_triple() {
# Prefer querying with CFLAGS so explicit target flags (for example
# --target=... in clang-based cross builds) are reflected.
if ${CC} ${CFLAGS} -dumpmachine >/dev/null 2>&1; then
${CC} ${CFLAGS} -dumpmachine
return 0
fi
if ${CC} ${CFLAGS} --print-target-triple >/dev/null 2>&1; then
${CC} ${CFLAGS} --print-target-triple
return 0
fi
# Fall back to no CFLAGS in case unrelated build flags make the query fail.
if ${CC} -dumpmachine >/dev/null 2>&1; then
${CC} -dumpmachine
return 0
fi
if ${CC} --print-target-triple >/dev/null 2>&1; then
${CC} --print-target-triple
return 0
fi
printf '%s\n' ""
}

abi_from_target_triple() {
triple=$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')
case "${triple}" in
*x86_64*apple-darwin*|*x86_64*darwin*) printf '%s\n' "darwin_x86_64" ;;
*arm64*apple-darwin*|*aarch64*apple-darwin*|*arm64*darwin*|*aarch64*darwin*) printf '%s\n' "darwin_arm64" ;;
*x86_64*linux*) printf '%s\n' "sysv_amd64" ;;
*i?86*linux*) printf '%s\n' "sysv_i386" ;;
*aarch64*linux*) printf '%s\n' "aarch64" ;;
*arm*linux*gnueabi*|*armv7*linux*|*armv6*linux*) printf '%s\n' "arm32" ;;
*riscv64*linux*) printf '%s\n' "riscv64" ;;
*aarch64*w64*mingw*|*arm64*windows*|*aarch64*windows*) printf '%s\n' "win_arm64" ;;
*x86_64*w64*mingw*|*x86_64*windows*) printf '%s\n' "win_x64" ;;
*i?86*w64*mingw*|*i?86*windows*) printf '%s\n' "win_x86" ;;
*) printf '%s\n' "" ;;
esac
}

mkdir -p "${here}/tmp"
# Clean up any stale temp files first
rm -f "${here}/tmp"/abiname*.c "${here}/tmp"/abiname*.c.out
Expand All @@ -18,8 +66,27 @@ tmp=$(mktemp "${here}/tmp/abinameXXX.c")
#1 create the preprocessed file
CC=${1:-cc}
CFLAGS=${2:-}
ABI_OVERRIDE=${3:-${STACKMAN_ABI:-}}
target_triple=$(detect_target_triple)
if [ -n "${ABI_OVERRIDE}" ]; then
abi=$(canonicalize_abi "${ABI_OVERRIDE}")
if [ -n "${STACKMAN_ABI_DEBUG:-}" ] || [ -n "${STACKMAN_ABI_TRACE:-}" ]; then
printf '%s\n' "stackman abiname: cc=${CC} target=${target_triple:-unknown} abi=${abi} source=override" >&2
fi
printf '%s\n' "${abi}"
exit 0
fi
Comment thread
kristjanvalur marked this conversation as resolved.
${CC} ${CFLAGS} -I${here}/../stackman -E -o "${tmp}" "${here}/abiname.c"
#2 compile resulting file
cc -o "${tmp}.out" "${tmp}"
#3 run it
"${tmp}.out"
abi=$("${tmp}.out")
abi=$(canonicalize_abi "${abi}")
target_abi=$(abi_from_target_triple "${target_triple}")
if [ -n "${target_abi}" ] && [ "${target_abi}" != "${abi}" ]; then
printf '%s\n' "warning: stackman ABI mismatch: compiler target '${target_triple}' suggests '${target_abi}', macro probe selected '${abi}'. This usually means target intent was not fully propagated (flags/wrapper selection). Consider setting STACKMAN_ABI explicitly for deterministic packaging." >&2
fi
if [ -n "${STACKMAN_ABI_DEBUG:-}" ] || [ -n "${STACKMAN_ABI_TRACE:-}" ]; then
printf '%s\n' "stackman abiname: cc=${CC} target=${target_triple:-unknown} abi=${abi} source=macro" >&2
fi
printf '%s\n' "${abi}"