Add Windows support and clean up toolchain (#10)
All checks were successful
Builds / XTchain (full, linux) (push) Successful in 1h33m3s
Builds / XTchain (minimal, linux) (push) Successful in 9m16s
Builds / XTchain (minimal, windows) (push) Successful in 1m22s
Builds / XTchain (full, windows) (push) Successful in 52m18s

Reviewed-on: #10
Co-authored-by: Aiken Harris <harraiken@noreply.codingworkshop.git>
Co-committed-by: Aiken Harris <harraiken@noreply.codingworkshop.git>
This commit is contained in:
2025-07-10 12:37:41 +02:00
committed by CodingWorkshop Signing Team
parent ef1065278b
commit 97491fb72a
16 changed files with 793 additions and 3446 deletions

View File

@@ -1,42 +0,0 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/clang-target-wrapper
# DESCRIPTION: CLANG Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
CLANG="$DIR/clang"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
EXECUTABLE="${BASENAME##*-}"
DEFAULT_TARGET="x86_64-w64-mingw32"
ARCH="${TARGET%%-*}"
# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
TARGET="${DEFAULT_TARGET}"
fi
# Set lang-specific flags
case ${EXECUTABLE} in
"clang++"|"g++"|"c++")
FLAGS="$FLAGS --driver-mode=g++"
;;
*)
FLAGS=""
;;
esac
# Set compiler flags
FLAGS="${FLAGS} -target ${TARGET}"
FLAGS="${FLAGS} -rtlib=compiler-rt"
FLAGS="${FLAGS} -stdlib=libc++"
FLAGS="${FLAGS} -fuse-ld=lld"
FLAGS="${FLAGS} -Qunused-arguments"
# Launch the compiler
$CLANG $FLAGS "$@"

View File

@@ -1,42 +0,0 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/dlltool-wrapper
# DESCRIPTION: DLLTOOL Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
DEFAULT_TARGET="x86_64-w64-mingw32"
# Update PATH
export PATH="$DIR":"$PATH"
# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
TARGET="${DEFAULT_TARGET}"
fi
# Set target machine
ARCH="${TARGET%%-*}"
case $ARCH in
aarch64)
M="arm64"
;;
armv7)
M="arm"
;;
i686)
M="i386"
;;
x86_64)
M="i386:x86-64"
;;
esac
# Launch the utility
llvm-dlltool -m ${M} "$@"

View File

@@ -1,42 +0,0 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/ld-wrapper
# DESCRIPTION: LLD Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
DEFAULT_TARGET="x86_64-w64-mingw32"
# Update PATH
export PATH="${DIR}":"${PATH}"
# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
TARGET="${DEFAULT_TARGET}"
fi
# Set target machine
ARCH="${TARGET%%-*}"
case ${ARCH} in
aarch64)
M="arm64pe"
;;
armv7)
M="thumb2pe"
;;
i686)
M="i386pe"
;;
x86_64)
M="i386pep"
;;
esac
# Launch the linker
ld.lld -m ${M} "$@"

View File

@@ -1,46 +0,0 @@
#!/bin/sh
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/objdump-wrapper
# DESCRIPTION: OBJDUMP Wrapper
# DEVELOPERS: Martin Storsjo <martin@martin.st>
# Rafal Kupiec <belliash@codingworkshop.eu.org>
# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
# Update PATH
export PATH="$DIR":"$PATH"
# Libtool can try to run objdump -f and wants to see certain strings in
# the output, to accept it being a valid windows (import) library
if [ "$1" = "-f" ]; then
llvm-readobj $2 | while read -r line; do
case $line in
File:*)
file=$(echo $line | awk '{print $2}')
;;
Format:*)
format=$(echo $line | awk '{print $2}')
case $format in
COFF-i386)
format=pe-i386
;;
COFF-x86-64)
format=pe-x86-64
;;
COFF-ARM*)
# This is wrong; modern COFF armv7 isn't pe-arm-wince, and
# arm64 definitely isn't, but libtool wants to see this
# string (or some of the others) in order to accept it.
format=pe-arm-wince
;;
esac
echo $file: file format $format
;;
esac
done
else
llvm-objdump "$@"
fi

57
scripts/xtchain.ps1 Normal file
View File

@@ -0,0 +1,57 @@
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/xtchain.ps1
# DESCRIPTION: XTchain Entry Script
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
# Get the absolute path to the XTchain
$XTCDIR = (Get-Item -Path ".\").FullName
# Read the XTchain version
$env:XTCVER = Get-Content "${XTCDIR}\Version"
# Load the library (Make sure the xtclib.ps1 file is PowerShell compatible)
. "${XTCDIR}\lib\xtchain\xtclib.ps1"
# Set the target architecture
$env:TARGET = $args[0]
if (-not $env:TARGET) { $env:TARGET = "amd64" }
# Save the source directory
$SRCDIR = $args[1]
if (-not $SRCDIR) { $SRCDIR = (Get-Location).Path }
# Make sure the compiler flags are clean
$env:HOST = $null
$env:CFLAGS = $null
$env:CXXFLAGS = $null
$env:LDFLAGS = $null
# Update PATH
$env:PATH = "${XTCDIR}\bin;" + $env:PATH
# Display banner
version
# Invoke shell with fancy prompt
function global:prompt {
$PROMPT = " XT Toolchain "
$CWD = (Get-Location).Path
$CHEVRON = [char]0xE0B0
$SEGMENTS = @(
@{ TEXT = $PROMPT; BGCOLOR = "Blue"; FGCOLOR = "White" },
@{ TEXT = " $CWD "; BGCOLOR = "DarkCyan"; FGCOLOR = "White" }
)
for ($INDEX = 0; $INDEX -lt $SEGMENTS.Count; $INDEX++) {
$SEGMENT = $SEGMENTS[$INDEX]
$NEXTBG = if ($INDEX + 1 -lt $SEGMENTS.Count) { $SEGMENTS[$INDEX + 1].BGCOLOR } else { "Default" }
Write-Host $SEGMENT.TEXT -NoNewLine -ForegroundColor $SEGMENT.FGCOLOR -BackgroundColor $SEGMENT.BGCOLOR
if ($NEXTBG -ne "Default") {
Write-Host $CHEVRON -NoNewLine -ForegroundColor $SEGMENT.BGCOLOR -BackgroundColor $NEXTBG
} else {
Write-Host $CHEVRON -NoNewLine -ForegroundColor $SEGMENT.BGCOLOR
}
}
return " "
}
Set-Location -Path $SRCDIR

View File

@@ -4,8 +4,20 @@
# FILE: scripts/xtclib
# DESCRIPTION: XTchain library
# DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
# Aiken Harris <harraiken91@gmail.com>
# Prints XTChain banner
banner()
{
local XTC_BANNER="XT Toolchain v${XTCVER} for Linux"
printf "###############################################################################\n\n"
printf "%*s\n\n" $(( (${#XTC_BANNER} + 80) / 2)) "${XTC_BANNER}"
printf "###############################################################################\n\n\n"
}
export -f banner
# Sets the target architecture
charch()
{
@@ -54,51 +66,67 @@ export -f chbuild
# Prints help
help()
{
version
echo "XTChain defines an internal list of commands:"
echo " * charch [arch] - sets the target CPU architecture [aarch64/armv7/i686/amd64]"
echo " * chbuild [type] - sets build type [debug/release]"
echo " * help - prints this message"
echo " * version - prints XTChain and its components version"
echo " * xbuild - builds an application with a Ninja build system"
banner
echo "XTChain defines an internal list of commands:"
echo " * banner - prints XTChain banner"
echo " * charch [arch] - sets the target CPU architecture [aarch64/armv7/i686/amd64]"
echo " * chbuild [type] - sets build type [debug/release]"
echo " * help - prints this message"
echo " * version - prints XTChain and its components version"
echo " * xbuild - builds an application with a Ninja build system"
}
export -f help
# Displays version banner
version()
{
echo "###############################################################################"
echo "# XT Toolchain v${XTCVER} for Linux #"
echo "# by Rafal Kupiec <belliash@codingworkshop.eu.org> #"
echo "###############################################################################"
echo
echo
echo "LLVM Compiler Version: $(${XTCDIR}/bin/clang --version | grep 'clang version' | cut -d' ' -f3)"
echo "LLVM Windres Utility Version: $(${XTCDIR}/bin/i686-w64-mingw32-windres -V | cut -d' ' -f6)"
echo "Mingw IDL Compiler Version: $(${XTCDIR}/bin/i686-w64-mingw32-widl -V | grep 'version' | cut -d' ' -f5)"
echo "Wine Message Compiler Version: $(${XTCDIR}/bin/wmc -V | grep 'version' | cut -d' ' -f5)"
echo "Wine Resource Compiler Version: $(${XTCDIR}/bin/wrc --version | grep 'version' | cut -d' ' -f5)"
echo
local XTCHAIN_EXTTOOLS=false
if [ ! -f ${XTCDIR}/bin/clang ] || [ "$(which clang)" != "${XTCDIR}/bin/clang" ] || [ $(echo ${XTCVER} | grep "min") ]; then
XTCHAIN_EXTTOOLS=true
for TOOL in {clang,clang++,cmake,lld-link,ninja}; do
which ${TOOL} &> /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: You are using minimal version of XTChain and '${TOOL}' has been not found in your system!"
echo "ERROR: Please install all required tools."
exit 1
fi
done
fi
banner
echo -en "\nLLVM/Clang Compiler: $(clang --version | grep 'clang version' | cut -d' ' -f3) ($(which clang))"
echo -en "\nLLVM/LLD Linker: $(lld-link --version | cut -d' ' -f2) ($(which lld-link))"
echo -en "\nLLVM Resource Compiler: $(windres --version | grep version | cut -d' ' -f5) ($(which windres))"
echo -en "\nWine IDL Compiler: $(widl -V | grep 'version' | cut -d' ' -f5) ($(which widl))"
echo -en "\nWine Message Compiler: $(wmc -V | grep 'version' | cut -d' ' -f5) ($(which wmc))"
echo -en "\nWine Resource Compiler: $(wrc --version | grep 'version' | cut -d' ' -f5) ($(which wrc))"
echo -en "\nXT SPEC Compiler: $(xtcspecc --help | grep Version | cut -d' ' -f5) ($(which xtcspecc))"
echo -en "\nCMake Build System: $(cmake --version | grep 'cmake version' | cut -d' ' -f3) ($(which cmake))"
echo -en "\nNinja Build System: $(ninja --version) ($(which ninja))"
echo -en "\n\n"
charch ${TARGET:-amd64}
chbuild ${BUILD_TYPE:-DEBUG}
echo
echo
echo -en "\n\nFor a list of all supported commands, type 'help'"
echo -en "\n-------------------------------------------------\n\n"
}
export -f version
# Builds application (wrapper to Ninja)
xbuild()
{
if [ ! -f build.arch ]; then
ninja "$@"
else
ARCH=$(cat build.arch)
if [ x"${ARCH}" != x"${TARGET}" ]; then
echo "Build is configured for '${ARCH}' while current target set to '${TARGET}'!"
echo "Cannot continue until conflict is resolved ..."
return 1
fi
ninja "$@"
fi
if [ ! -f build.arch ]; then
ninja "$@"
else
ARCH=$(cat build.arch)
if [ x"${ARCH}" != x"${TARGET}" ]; then
echo "Build is configured for '${ARCH}' while current target set to '${TARGET}'!"
echo "Cannot continue until conflict is resolved ..."
return 1
fi
ninja "$@"
fi
}
export -f xbuild

148
scripts/xtclib.ps1 Normal file
View File

@@ -0,0 +1,148 @@
# PROJECT: XTchain
# LICENSE: See the COPYING.md in the top level directory
# FILE: scripts/xtclib.ps1
# DESCRIPTION: XTchain library
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
# Prints XTChain banner
function banner {
param()
$XTC_BANNER = "XT Toolchain v${Env:XTCVER} for Windows"
Write-Host "################################################################################"
Write-Host
Write-Host (' ' * [math]::Floor((80 - $XTC_BANNER.Length) / 2) + $XTC_BANNER) -ForegroundColor Yellow
Write-Host
Write-Host "################################################################################"
Write-Host
}
# Sets the target architecture
function charch {
param (
[string]$arch
)
if ([string]::IsNullOrWhiteSpace($arch)) {
Write-Host "Syntax: charch [architecture]"
return
}
switch -Regex ($arch) {
"aarch64|arm64" {
$Env:TARGET = "aarch64"
}
"arm|armv7" {
$Env:TARGET = "armv7"
}
"i386|i486|i586|i686|x86" {
$Env:TARGET = "i686"
}
"amd64|x64|x86_64" {
$Env:TARGET = "amd64"
}
default {
$Env:TARGET = "UNKNOWN"
}
}
Write-Host "Target Architecture: $($Env:TARGET)"
}
# Sets the build type
function chbuild {
param (
[string]$buildType
)
if ([string]::IsNullOrWhiteSpace($buildType)) {
Write-Host "Syntax: chbuild [DEBUG|RELEASE]"
return
}
switch -Regex ($buildType.ToUpper()) {
"RELEASE" {
$Env:BUILD_TYPE = "RELEASE"
}
default {
$Env:BUILD_TYPE = "DEBUG"
}
}
Write-Host "Target build type: $($Env:BUILD_TYPE)"
}
# Prints help
function help {
banner
Write-Host "XTChain defines an internal list of commands:"
Write-Host " * banner - prints XTChain banner"
Write-Host " * charch [arch] - sets the target CPU architecture [aarch64/armv7/i686/amd64]"
Write-Host " * chbuild [type] - sets build type [debug/release]"
Write-Host " * help - prints this message"
Write-Host " * version - prints XTChain and its components version"
Write-Host " * xbuild - builds an application with a Ninja build system"
}
# Displays version banner
function version {
param()
[bool]$XTCHAIN_EXTTOOLS = $false
if ((Test-Path "${Env:XTCDIR}/bin/clang") -and
((Get-Command clang).Source -eq "${Env:XTCDIR}/bin/clang") -and
($Env:XTCVER -match "min")) {
$XTCHAIN_EXTTOOLS = $true
foreach ($TOOL in @("clang", "clang++", "cmake", "lld-link", "ninja")) {
if (!(Get-Command $TOOL -ErrorAction SilentlyContinue)) {
Write-Error "You are using minimal version of XTChain and '${TOOL}' has been not found in your system!"
Write-Error "Please install all required tools."
return
}
}
}
banner
Write-Host
Write-Host "LLVM/Clang Compiler: $(clang --version | Select-String -Pattern "version (\d+\.\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command clang).Source))"
Write-Host "LLVM/LLD Linker: $(lld-link --version | Select-String -Pattern "(\d+\.\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command lld-link).Source))"
Write-Host "LLVM Resource Compiler: $(windres --version | Select-String -Pattern "version (\d+\.\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command windres).Source))"
Write-Host "Wine IDL Compiler: $(widl -V | Select-String -Pattern "version (\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command widl).Source))"
Write-Host "Wine Message Compiler: $(wmc -V | Select-String -Pattern "version (\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command wmc).Source))"
Write-Host "Wine Resource Compiler: $(wrc --version | Select-String -Pattern "version (\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command wrc).Source))"
Write-Host "XT SPEC Compiler: $(xtcspecc --help | Select-String -Pattern "Version (\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command xtcspecc).Source))"
Write-Host "CMake Build System: $(cmake --version | Select-String -Pattern "version (\d+\.\d+\.\d+)" | ForEach-Object { $_.Matches.Groups[1].Value }) ($($(Get-Command cmake).Source))"
Write-Host "Ninja Build System: $(ninja --version) ($($(Get-Command ninja).Source))"
Write-Host
$BUILD_TYPE = if ($null -eq $env:BUILD_TYPE -or $env:BUILD_TYPE -eq '') { 'DEBUG' } else { $env:BUILD_TYPE }
$TARGET = if ($null -eq $env:TARGET -or $env:TARGET -eq '') { 'amd64' } else { $env:TARGET }
charch $TARGET
chbuild $BUILD_TYPE
Write-Host
Write-Host
Write-Host "For a list of all supported commands, type 'help'"
Write-Host "-------------------------------------------------"
Write-Host
Write-Host
Write-Host
}
# Builds application (wrapper to Ninja)
function xbuild {
param(
[string[]]$args
)
if (-not (Test-Path build.arch)) {
& ninja @args
} else {
$ARCH = Get-Content build.arch
if ($ARCH -ne $Env:TARGET) {
Write-Host "Build is configured for '$ARCH' while current target set to '$($Env:TARGET)'!"
Write-Host "Cannot continue until conflict is resolved ..."
return 1
}
& ninja @args
}
}