diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e4796798..47de3138d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,6 +103,12 @@ jobs: working-directory: test/haxe run: bin\TestMain + # clang-cl's /Yu reads a clang precompiled header, which keeps each + # header's date, so the compile cache must make it again when one changes + - name: Build with the cached precompiled header after a header's date changes + shell: bash + run: bash test/compile_cache/pch_dates.sh -D HXCPP_MSVC_LLVM -D HXCPP_M64 + check-android: name: Build for Android (${{ matrix.abi }}) if: github.event_name != 'pull_request' @@ -283,6 +289,22 @@ jobs: working-directory: test/regression run: haxe --run Run -D emscripten + # Each file must compile with the standard its group, its own + # cxx_standard or HXCPP_CPP17 asks for: the toolchain once pinned C++11 + # after the build tool's -std, so all three built as C++11 + - name: Build with each file's C++ standard + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + working-directory: test/cxx_standard + run: | + for xml in *.xml; do + haxelib run hxcpp $xml -Demscripten + haxelib run hxcpp $xml clean -Demscripten + done + + - name: Build with the cached precompiled header after a header's date changes + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + run: bash test/compile_cache/pch_dates.sh -D emscripten + - name: Run the memory and stack test if: ${{ !cancelled() && steps.setup.outcome == 'success' }} run: timeout 600 sh test/emscripten/run.sh diff --git a/.github/workflows/platforms.yml b/.github/workflows/platforms.yml index e595494a7..6afa13708 100644 --- a/.github/workflows/platforms.yml +++ b/.github/workflows/platforms.yml @@ -44,6 +44,20 @@ jobs: scope: ${{ inputs.pr && 'smoke' || 'full' }} stress: '["default generational verify", "generational-verify moving big-blocks", "always-move check-pointer", "big-generational big-verify nursery dynamic-size debug-level"]' + # Haxe has no Windows arm64 build, so the x64 Haxe and Neko run emulated, + # and the C++ compiles with the ARM64-hosted compiler + WindowsArm64: + if: ${{ !inputs.pr }} + uses: ./.github/workflows/test.yml + name: Windows arm64 + with: + haxe: ${{ inputs.haxe }} + arch: Arm64 + sep: \ + ext: .dll + os: windows-11-arm + scope: smoke + MacOS64: if: ${{ !inputs.pr }} uses: ./.github/workflows/test.yml diff --git a/.github/workflows/setup/action.yml b/.github/workflows/setup/action.yml index 9a04d692a..8da7cf5b5 100644 --- a/.github/workflows/setup/action.yml +++ b/.github/workflows/setup/action.yml @@ -7,10 +7,20 @@ runs: using: composite steps: - name: install haxe + if: runner.os != 'Windows' || runner.arch != 'ARM64' uses: krdlab/setup-haxe@v2 with: haxe-version: ${{ inputs.haxe }} + # setup-haxe's releases, v2.1.1 the latest, have no Windows arm64 support. + # The commit that added it, merged on 2026-10-18, installs the x64 Haxe + # and Neko there, which Windows runs emulated; use a release once one has it + - name: install haxe (Windows arm64) + if: runner.os == 'Windows' && runner.arch == 'ARM64' + uses: krdlab/setup-haxe@2158bbdec718708920c54ab91fb19d8ddfa28f32 + with: + haxe-version: ${{ inputs.haxe }} + - name: install haxe libraries shell: pwsh run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3b15f405..80c83e237 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -204,6 +204,17 @@ jobs: if: ${{ !cancelled() && steps.setup.outcome == 'success' }} shell: bash run: bash test/compile_errors/check.sh + # Clang refused a cached precompiled header once a header's date changed + - name: build tool cached precompiled header after a header's date changes + continue-on-error: ${{ inputs.warn_only }} + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + shell: bash + run: bash test/compile_cache/pch_dates.sh -D $HXCPP_ARCH_FLAG + - name: build tool compile cache trimming keeps what builds use + continue-on-error: ${{ inputs.warn_only }} + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + shell: bash + run: bash test/compile_cache/trim.sh -D$HXCPP_ARCH_FLAG - name: build tool MSVC setup scripts with ! in the Visual Studio path continue-on-error: ${{ inputs.warn_only }} if: ${{ !cancelled() && steps.setup.outcome == 'success' && runner.os == 'Windows' }} diff --git a/Changes.md b/Changes.md index 525939799..d037ca59b 100644 --- a/Changes.md +++ b/Changes.md @@ -2,6 +2,12 @@ libhxcpp 6.1.0 (unreleased) ------------------------------------------------------------ +* Fixed Emscripten builds ignoring the C++ standard: the toolchain added --std=c++11 after the build tool's own -std, so HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 and cxx_standard did nothing there and every file, the precompiled header included, compiled as C++11. Each file gets the standard it asks for now, C++11 by default as before, so an Emscripten build compiles everything once more after updating. The GCW Zero toolchain had the same flag (HaxeFoundation/hxcpp#1232) +* Fixed Objective-C++ ignoring the C++ standard: it compiled as C++11 whatever HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 or cxx_standard asked for, and with -D objc, which makes every generated file .mm, so did all of a program's Haxe code while the runtime followed the setting. Objective-C++ follows the C++ standard now, and Objective-C the C one, a file's own cxx_standard or c_standard included; objcxx_standard, objc_standard, HXCPP_OBJCXX_STANDARD and HXCPP_OBJC_STANDARD still set them apart (HaxeFoundation/hxcpp#1250) +* Fixed builds with the compile cache failing on clang once a header's date changed but not its content, as after a fresh clone, a branch switched and back or a restored CI cache: the cached precompiled header is found by content, and clang refused it with "has been modified since the precompiled header was built" at the first file that had to compile, on macOS, iOS, Android, Emscripten and Linux with clang. A cached precompiled header keeps the dates of the headers it was made from now, and is made again when one differs, later or earlier (HaxeFoundation/hxcpp#1466) +* Fixed the compile cache removing what builds still use when it trims to HXCPP_CACHE_MB, or with "cache days": it took an entry's last use from its access and change times, which reusing it changes neither, as an object up to date in the cache is linked from there and Windows does not update access times. So objects every build reused looked as old as when they were compiled, went first, and were compiled again. Each target now lists in the cache's .used folder what its last build took from the cache, reused or not, and trimming takes that list's date as their last use; no object's date changes, so a build with nothing to do still links nothing. "cache details" shows that date (HaxeFoundation/hxcpp#1469) +* Fixed builds on a Windows ARM64 machine using the x86-hosted MSVC, which Windows runs emulated in 32 bits and which can run out of memory on a precompiled header: setup asked for it for ARM64 desktop and WinRT builds, through Visual Studio's VsDevCmd and through HXCPP_MSVC_VER's vcvars scripts alike. The ARM64-hosted compiler is used now when it is installed, else the x64-hosted one, which runs emulated with a 64-bit address space, and the x86-hosted one only when neither is. CI runs the core suites on Windows ARM64 (HaxeFoundation/hxcpp#1400) + libhxcpp 6.0.3 ------------------------------------------------------------ diff --git a/docs/build_xml/Defines.md b/docs/build_xml/Defines.md old mode 100755 new mode 100644 index d31903c28..a32ae532a --- a/docs/build_xml/Defines.md +++ b/docs/build_xml/Defines.md @@ -67,8 +67,8 @@ Defines affecting how the code is compiled. These can be on the command line wh | *HXCPP_C_STANDARD* | Set default C standard | | *HXCPP_CXX_STANDARD* | Set default C++ standard | | *HXCPP_CPP17* | Use C++17, as HXCPP_CXX_STANDARD=17 does | -| *HXCPP_OBJC_STANDARD* | Set default Objective-C standard | -| *HXCPP_OBJCXX_STANDARD* | Set default Objective-C++ standard | +| *HXCPP_OBJC_STANDARD* | Set default Objective-C standard. Without it, Objective-C follows the C standard | +| *HXCPP_OBJCXX_STANDARD* | Set default Objective-C++ standard. Without it, Objective-C++ follows the C++ standard | | *exe_link* | Generate executable file (rather than dynamic library on android) | | *static_link* | Generate static library | | *dll_link* | Generate dynamic library | diff --git a/docs/build_xml/Files.md b/docs/build_xml/Files.md old mode 100755 new mode 100644 index 8291d0718..6679466c3 --- a/docs/build_xml/Files.md +++ b/docs/build_xml/Files.md @@ -13,8 +13,8 @@ The files node defines a group of files that all share the same attributes, incl + `c_standard` = Default C standard for the file group + `cxx_standard` = Default C++ standard for the file group - + `objc_standard` = Default Objective-C standard for the file group - + `objcxx_standard` = Default Objective-C++ standard for the file group + + `objc_standard` = Default Objective-C standard for the file group. Without one, Objective-C follows the C standard + + `objcxx_standard` = Default Objective-C++ standard for the file group. Without one, Objective-C++ follows the C++ standard #### Nodes - *depend* - Declare that all files in the group depend on another file or another file group. ```xml @@ -103,8 +103,8 @@ The files node defines a group of files that all share the same attributes, incl + tags = optional override of group tags. See [Tags.md](Tags.md). + `c_standard` = C standard for the file + `cxx_standard` = C++ standard for the file - + `objc_standard` = Objective-C standard for the file - + `objcxx_standard` = Objective-C++ standard for the file + + `objc_standard` = Objective-C standard for the file. Without one, the file follows its own `c_standard` if it has one, else its group + + `objcxx_standard` = Objective-C++ standard for the file. Without one, the file follows its own `cxx_standard` if it has one, else its group + filterout = allows files to be skipped at compile-time if the named define exists. This is useful when the define is set sometime after the file list is parsed. + depend name = filename of additional dependency diff --git a/test/compile_cache/pch_dates.sh b/test/compile_cache/pch_dates.sh new file mode 100644 index 000000000..5572afafd --- /dev/null +++ b/test/compile_cache/pch_dates.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# HaxeFoundation/hxcpp#1466: clang keeps each header's date in a precompiled +# header and refuses it once a date differs, though the content is the same. +# The compile cache finds a precompiled header by content, so a fresh clone, a +# branch switched and back or a restored CI cache stopped the next compile with +# "has been modified since the precompiled header was built". +# This builds a program with the compile cache, then edits it and builds it +# again with hxcpp.h dated later, and then earlier, than the cached precompiled +# header. Each build must succeed and print what it was edited to. Only clang +# and clang-cl check the dates, but every compiler must pass. +# Uses HXCPP_COMPILE_CACHE, or a cache of its own when that is not set. +# Usage: test/compile_cache/pch_dates.sh [extra haxe args, eg -D HXCPP_M64 or -D emscripten] +cd "$(dirname "$0")" +extra=("$@") +hxcpp=$(haxelib libpath hxcpp | tr -d '\r') +header="${hxcpp//\\//}/include/hxcpp.h" +[ -f "$header" ] || { echo "::error::no hxcpp.h at $header"; exit 1; } +rm -rf bin +mkdir -p bin/src +[ -n "$HXCPP_COMPILE_CACHE" ] || export HXCPP_COMPILE_CACHE="$PWD/bin/cache" + +# Later builds in the same checkout see the header's date as it was +touch -r "$header" bin/header-date +trap 'touch -r bin/header-date "$header"' EXIT + +run() { + if [ -f bin/cpp/Main.js ]; then node bin/cpp/Main.js + elif [ -f bin/cpp/Main.exe ]; then bin/cpp/Main.exe + else bin/cpp/Main + fi +} + +# build : builds and runs a Main that prints its name +build() { + printf 'class Main {\n\tstatic function main() {\n\t\tSys.println("%s");\n\t}\n}\n' "$1" > bin/src/Main.hx + if ! haxe -cp bin/src -m Main --cpp bin/cpp "${extra[@]}" > bin/build.log 2>&1; then + echo "::error::the build $1 failed" + tail -20 bin/build.log + return 1 + fi + local out + out=$(run | tr -d '\r') + if [ "$out" != "$1" ]; then + echo "::error::the build $1 printed \"$out\"" + return 1 + fi + echo "$1: built and printed its name" +} + +failed=0 +build first || failed=1 +touch "$header" +build later || failed=1 +touch -t 200001010000 "$header" +build earlier || failed=1 +exit $failed diff --git a/test/compile_cache/trim.sh b/test/compile_cache/trim.sh new file mode 100644 index 000000000..e4f5d8887 --- /dev/null +++ b/test/compile_cache/trim.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# HaxeFoundation/hxcpp#1469: trimming the compile cache, to HXCPP_CACHE_MB or +# by age, took an entry's use from its access and change times. Reusing an +# entry changes neither: an object up to date in the cache is linked from +# there, and Windows does not update access times. So entries every build +# reused looked as old as when they were compiled, and went first. +# This builds trim/Build.xml with a cache of its own, edits main.cpp and builds +# again, which reuses the rest in place, then dates every entry back to 2000, +# as if compiled long ago and never read since. Trimming to one day must keep +# all the last build used, so that build does nothing again, and remove the +# first main.cpp's object, which nothing has used since. +# Usage: test/compile_cache/trim.sh [extra build tool args, eg -DHXCPP_M64] +cd "$(dirname "$0")" +extra=("$@") +rm -rf bin/trim +mkdir -p bin/trim +cp trim/* bin/trim/ +cd bin/trim +export HXCPP_COMPILE_CACHE="$PWD/cache" + +# build : builds with a main.cpp of its own +build() { + printf '#include \n\nint main() { return other() + libValue() - %s; }\n' "$2" > main.cpp + if ! haxelib run hxcpp Build.xml "${extra[@]}" > "$1.log" 2>&1; then + echo "::error::the build $1 failed" + tail -20 "$1.log" + exit 1 + fi +} + +build first 1 +build second 2 +# The records of what each build used keep their dates +find cache -path cache/.used -prune -o -type f -exec touch -t 200001010000 {} + +haxelib run hxcpp cache days 1 "${extra[@]}" > trim.log 2>&1 || { echo "::error::trimming failed"; cat trim.log; exit 1; } +grep "Cache:" trim.log + +failed=0 +build again 2 +if grep -q "Compiling group\|Creating\|Link:" again.log; then + echo "::error::trimming removed what the last build used, so building it again did this:" + grep "Compiling group\|Creating\|Link:" again.log + failed=1 +else + echo "trimming kept what the last build used" +fi +build old 1 +if grep -q "Compiling group" old.log; then + echo "trimming removed the first main.cpp's object" +else + echo "::error::trimming kept the first main.cpp's object, which nothing has used since" + failed=1 +fi +exit $failed diff --git a/test/compile_cache/trim/Build.xml b/test/compile_cache/trim/Build.xml new file mode 100644 index 000000000..f6f6e723e --- /dev/null +++ b/test/compile_cache/trim/Build.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/test/compile_cache/trim/lib.cpp b/test/compile_cache/trim/lib.cpp new file mode 100644 index 000000000..c8fad5088 --- /dev/null +++ b/test/compile_cache/trim/lib.cpp @@ -0,0 +1 @@ +int libValue() { return 2; } diff --git a/test/compile_cache/trim/other.cpp b/test/compile_cache/trim/other.cpp new file mode 100644 index 000000000..24c79eb25 --- /dev/null +++ b/test/compile_cache/trim/other.cpp @@ -0,0 +1,3 @@ +#include + +int other() { return 1; } diff --git a/test/compile_cache/trim/pre.h b/test/compile_cache/trim/pre.h new file mode 100644 index 000000000..f73adbdd5 --- /dev/null +++ b/test/compile_cache/trim/pre.h @@ -0,0 +1,7 @@ +#ifndef TRIM_TEST_PRE_H +#define TRIM_TEST_PRE_H + +int other(); +int libValue(); + +#endif diff --git a/test/cxx_standard/Build.xml b/test/cxx_standard/Build.xml index 0198e3145..25bf33367 100644 --- a/test/cxx_standard/Build.xml +++ b/test/cxx_standard/Build.xml @@ -5,6 +5,12 @@ + +
+ + + +
diff --git a/test/cxx_standard/Build_legacy.xml b/test/cxx_standard/Build_legacy.xml index e9c4efa99..972c17543 100644 --- a/test/cxx_standard/Build_legacy.xml +++ b/test/cxx_standard/Build_legacy.xml @@ -4,6 +4,7 @@ + diff --git a/test/cxx_standard/Build_section.xml b/test/cxx_standard/Build_section.xml index af4ab0cdb..5d9f98eb0 100644 --- a/test/cxx_standard/Build_section.xml +++ b/test/cxx_standard/Build_section.xml @@ -3,6 +3,8 @@
+ +
diff --git a/test/cxx_standard/objc17.m b/test/cxx_standard/objc17.m new file mode 100644 index 000000000..1faab122e --- /dev/null +++ b/test/cxx_standard/objc17.m @@ -0,0 +1,6 @@ +#ifndef __OBJC__ +#error "Not Objective-C" +#endif +#if __STDC_VERSION__ < 201710L +#error "Not C17" +#endif diff --git a/test/cxx_standard/objcxx14.mm b/test/cxx_standard/objcxx14.mm new file mode 100644 index 000000000..84620d7fb --- /dev/null +++ b/test/cxx_standard/objcxx14.mm @@ -0,0 +1,6 @@ +#ifndef __OBJC__ +#error "Not Objective-C++" +#endif +#if __cplusplus != 201402L +#error "Not C++14" +#endif diff --git a/test/cxx_standard/objcxx17.mm b/test/cxx_standard/objcxx17.mm new file mode 100644 index 000000000..be897f892 --- /dev/null +++ b/test/cxx_standard/objcxx17.mm @@ -0,0 +1,6 @@ +#ifndef __OBJC__ +#error "Not Objective-C++" +#endif +#if __cplusplus < 201703L +#error "Not C++17" +#endif diff --git a/test/msvc_setup/check.ps1 b/test/msvc_setup/check.ps1 index 17f81e227..d7040cdbf 100644 --- a/test/msvc_setup/check.ps1 +++ b/test/msvc_setup/check.ps1 @@ -35,22 +35,57 @@ foreach ($script in "msvc-setup", "msvc64-setup", "msvc-arm64-setup", "msvc-winr } ${env:ProgramFiles(x86)} = $realPf86 +# On an ARM64 machine msvc_host_arch lists the compilers' hosts best first, and +# the ARM64 scripts call VsDevCmd for the first with a compiler for arm64 +# installed: the native one when there is one +$arm64Hosts = "arm64", "x64", "x86" +$env:msvc_host_arch = $arm64Hosts -join " " +$vcTools = (Get-Content "$realVs\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt").Trim() +$expect = $arm64Hosts | Where-Object { Test-Path "$realVs\VC\Tools\MSVC\$vcTools\bin\Host$_\arm64\cl.exe" } | Select-Object -First 1 +if ($null -eq $expect) { + "skip the ARM64 scripts on an ARM64 machine: this Visual Studio has no compiler for arm64" +} +else { + foreach ($script in "msvc-arm64-setup", "msvc-winrt-arm64-setup") { + $out = cmd /c "$root\toolchain\$script.bat" 2>&1 | Out-String + if ($out -match "(?m)^HXCPP_VARS" -and $out -match "(?m)^VSCMD_ARG_HOST_ARCH=$expect\s*$") { + "ok $script on an ARM64 machine uses the $expect-hosted compiler" + } else { + "FAIL $script on an ARM64 machine: expected the $expect-hosted compiler" + $out -split "`r?`n" | Where-Object { $_ -match "^(Error|VSCMD_ARG_HOST_ARCH|HXCPP_VARS)" } + $failures++ + } + } +} + # HXCPP_MSVC_VER names an install by its Common7\Tools folder, and the ARM64 # script runs that install's vcvars script for the host. A stand-in install -# whose vcvars scripts only say which one ran, named as Visual Studio names them +# whose vcvars scripts only say which one ran, named as Visual Studio names them, +# with a compiler for arm64 on each host until the cases below take them away $fake = "$work\fake vs" New-Item -ItemType Directory -Force "$fake\Common7\Tools", "$fake\VC\Auxiliary\Build" | Out-Null -foreach ($name in "x86_amd64", "x86_arm64", "amd64_x86", "amd64_arm64") { +foreach ($name in "x86_amd64", "x86_arm64", "amd64_x86", "amd64_arm64", "arm64") { Set-Content -Encoding ascii "$fake\VC\Auxiliary\Build\vcvars$name.bat" "@set VCVARS_RAN=$name" } +Set-Content -Encoding ascii "$fake\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" "14.99.0" +foreach ($h in $arm64Hosts) { + New-Item -ItemType Directory -Force "$fake\VC\Tools\MSVC\14.99.0\bin\Host$h\arm64" | Out-Null + Set-Content -Encoding ascii "$fake\VC\Tools\MSVC\14.99.0\bin\Host$h\arm64\cl.exe" "" +} $env:HXCPP_MSVC = "$fake\Common7\Tools\" -foreach ($case in @(@{ host = "x64"; expect = "amd64_arm64" }, @{ host = "x86"; expect = "x86_arm64" })) { +foreach ($case in @( + @{ host = "x64"; expect = "amd64_arm64"; on = "an x64 host" }, + @{ host = "x86"; expect = "x86_arm64"; on = "an x86 host" }, + @{ host = $arm64Hosts -join " "; expect = "arm64"; on = "an ARM64 host" }, + @{ host = $arm64Hosts -join " "; without = "arm64"; expect = "amd64_arm64"; on = "an ARM64 host without the ARM64-hosted compiler" }, + @{ host = $arm64Hosts -join " "; without = "x64"; expect = "x86_arm64"; on = "an ARM64 host with only the x86-hosted compiler" })) { + if ($case.ContainsKey("without")) { Remove-Item "$fake\VC\Tools\MSVC\14.99.0\bin\Host$($case.without)\arm64\cl.exe" } $env:msvc_host_arch = $case.host $out = cmd /c "$root\toolchain\msvc-arm64-setup.bat" 2>&1 | Out-String if ($out -match "(?m)^HXCPP_VARS" -and $out -match "(?m)^VCVARS_RAN=$($case.expect)\s*$") { - "ok msvc-arm64-setup with HXCPP_MSVC on an $($case.host) host" + "ok msvc-arm64-setup with HXCPP_MSVC on $($case.on)" } else { - "FAIL msvc-arm64-setup with HXCPP_MSVC on an $($case.host) host: expected vcvars$($case.expect).bat" + "FAIL msvc-arm64-setup with HXCPP_MSVC on $($case.on): expected vcvars$($case.expect).bat" $out -split "`r?`n" | Where-Object { $_ -match "^(Error|VCVARS_RAN|HXCPP_VARS)" } $failures++ } diff --git a/toolchain/emscripten-toolchain.xml b/toolchain/emscripten-toolchain.xml index 27e3dbe6d..6c8cb9180 100644 --- a/toolchain/emscripten-toolchain.xml +++ b/toolchain/emscripten-toolchain.xml @@ -106,7 +106,6 @@ -
diff --git a/toolchain/gcw0-toolchain.xml b/toolchain/gcw0-toolchain.xml index ddbb5295c..aa9050d29 100644 --- a/toolchain/gcw0-toolchain.xml +++ b/toolchain/gcw0-toolchain.xml @@ -29,7 +29,6 @@ - diff --git a/toolchain/msvc-arm64-setup.bat b/toolchain/msvc-arm64-setup.bat index b3ba42657..d763140f2 100644 --- a/toolchain/msvc-arm64-setup.bat +++ b/toolchain/msvc-arm64-setup.bat @@ -2,21 +2,33 @@ setlocal @set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" @set InstallDir= @if exist "%vswhere%" for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.arm64 -property installationPath`) do @set "InstallDir=%%i" -@rem Visual Studio names the x64 host amd64 in its vcvars scripts -@set "vcvars_host=%msvc_host_arch%" -@if /i "%vcvars_host%"=="x64" set "vcvars_host=amd64" +@if exist "%HXCPP_MSVC%\..\..\VC\" set "InstallDir=%HXCPP_MSVC%\..\.." +@rem msvc_host_arch lists the compilers' hosts best first, and the first with a +@rem compiler for arm64 installed is used: on an ARM64 machine the native one, +@rem then the x64-hosted one, which Windows runs emulated with a 64-bit address +@rem space, and last the x86-hosted one, emulated in 32 bits, which can run out +@rem of memory on a precompiled header. With none found, the first is used +@set "vctools=" +@if exist "%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" set /p vctools=<"%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" +@set "host=" +@for %%h in (%msvc_host_arch%) do @if not defined host if exist "%InstallDir%\VC\Tools\MSVC\%vctools%\bin\Host%%h\arm64\cl.exe" set "host=%%h" +@if not defined host for /f "tokens=1" %%h in ("%msvc_host_arch%") do @set "host=%%h" +@rem Visual Studio names the x64 host amd64 in its vcvars scripts, and the ARM64 host's own script vcvarsarm64 +@set "vcvars=vcvars%host%_arm64.bat" +@if /i "%host%"=="x64" set "vcvars=vcvarsamd64_arm64.bat" +@if /i "%host%"=="arm64" set "vcvars=vcvarsarm64.bat" @if exist "%HXCPP_MSVC%\..\..\VC\" ( - @if not exist "%hxcpp_msvc%\..\..\VC\Auxiliary\Build\vcvars%vcvars_host%_arm64.bat" ( - @echo Error: the specified MSVC version does not have vcvars%vcvars_host%_arm64.bat setup script + @if not exist "%hxcpp_msvc%\..\..\VC\Auxiliary\Build\%vcvars%" ( + @echo Error: the specified MSVC version does not have %vcvars% setup script ) else ( @echo "%HXCPP_MSVC%" - @call "%HXCPP_MSVC%\..\..\VC\Auxiliary\Build\vcvars%vcvars_host%_arm64.bat" + @call "%HXCPP_MSVC%\..\..\VC\Auxiliary\Build\%vcvars%" @echo HXCPP_VARS @set ) ) else if exist "%vswhere%" ( @if exist "%InstallDir%\Common7\Tools\VsDevCmd.bat" ( - @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%msvc_host_arch% -arch=arm64 -app_platform=Desktop -no_logo + @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%host% -arch=arm64 -app_platform=Desktop -no_logo @echo HXCPP_VARS @set ) else ( diff --git a/toolchain/msvc-winrt-arm64-setup.bat b/toolchain/msvc-winrt-arm64-setup.bat index 8f4714a08..d2dcdc0de 100644 --- a/toolchain/msvc-winrt-arm64-setup.bat +++ b/toolchain/msvc-winrt-arm64-setup.bat @@ -2,8 +2,14 @@ setlocal @set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" @set InstallDir= @if exist "%vswhere%" for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.arm64 -property installationPath`) do @set "InstallDir=%%i" +@rem The first host in msvc_host_arch with a compiler for arm64 installed, as msvc-arm64-setup.bat picks it +@set "vctools=" +@if exist "%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" set /p vctools=<"%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" +@set "host=" +@for %%h in (%msvc_host_arch%) do @if not defined host if exist "%InstallDir%\VC\Tools\MSVC\%vctools%\bin\Host%%h\arm64\cl.exe" set "host=%%h" +@if not defined host for /f "tokens=1" %%h in ("%msvc_host_arch%") do @set "host=%%h" @if exist "%InstallDir%\Common7\Tools\VsDevCmd.bat" ( - @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%msvc_host_arch% -arch=arm64 -app_platform=UWP -no_logo + @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%host% -arch=arm64 -app_platform=UWP -no_logo @echo HXCPP_VARS @set ) else ( diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 2198179c2..821309af1 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -477,6 +477,9 @@ class BuildTool // more after them all: any of them can call into it, as hxcpp_std does var linkAgain = new Array(); var runtimeAgain:String = null; + // What this target takes from the compile cache, compiled, found there + // or reused in place, so trimming keeps it (CompileCache.recordUse) + var cacheUsed = new Array(); for(group in target.mFileGroups) { var useCache = CompileCache.hasCache && group.mUseCache; @@ -556,6 +559,8 @@ class BuildTool Profile.push("pch"); var obj = mCompiler.precompile(group,cached || to_be_compiled.length==0); + if (useCache) + cacheUsed.push(mCompiler.getPchDir(group) + "/"); if (obj!=null) { pchStamp = FileSystem.stat(obj).mtime.getTime(); @@ -732,6 +737,11 @@ class BuildTool var libTarget = new Target(libName, "linker", "static_link" ); linker.link(libTarget,groupObjs, mCompiler, [] ); target.mAutoLibs.push(linker.mLastOutName); + if (useCache) + { + cacheUsed.push(linker.mLastOutName); + cacheUsed.push(linker.mLastHashName); + } // Linux the libraries must be added again if the references were not resolved the firs time if (group.mAddTwice) { @@ -754,10 +764,14 @@ class BuildTool { objs = objs.concat(groupObjs); } + if (useCache) + cacheUsed = cacheUsed.concat(groupObjs); if (group.mDir!="." && group.mSetImportDir) Sys.setCwd( baseDir ); } + if (cacheUsed.length>0) + CompileCache.recordUse(mCompiler.mObjDir + " " + targetKey, cacheUsed); if (runtimeAgain!=null) linkAgain.push(runtimeAgain); for(lib in linkAgain) @@ -1111,10 +1125,11 @@ class BuildTool Log.warn('Increasing default Obj-C++ standard to Obj-C++11 instead of Obj-C++${defaultObjCxxStandard}'); defaultObjCxxStandard = 11; } - } else { - defaultObjCxxStandard = 11; } + // An Objective-C or Objective-C++ standard left null follows the file's + // C or C++ one (Compiler.addStandard), so -D objc, which makes every + // generated file .mm, compiles them with the C++ standard asked for if (inXML.has.c_standard) group.mCStandard = Std.parseInt(substitute(inXML.att.c_standard)); else if (group.mCStandard == null) @@ -1123,7 +1138,7 @@ class BuildTool if (inXML.has.objc_standard) group.mObjCStandard = Std.parseInt(substitute(inXML.att.objc_standard)); else if (group.mObjCStandard == null) - group.mObjCStandard = defaultObjCStandard != null ? defaultObjCStandard : group.mCStandard; + group.mObjCStandard = defaultObjCStandard; if (inXML.has.cxx_standard) group.mCxxStandard = Std.parseInt(substitute(inXML.att.cxx_standard)); @@ -1133,7 +1148,7 @@ class BuildTool if (inXML.has.objcxx_standard) group.mObjCxxStandard = Std.parseInt(substitute(inXML.att.objcxx_standard)); else if (group.mObjCxxStandard == null) - group.mObjCxxStandard = defaultObjCxxStandard != null ? defaultObjCxxStandard : group.mCxxStandard; + group.mObjCxxStandard = defaultObjCxxStandard; for(el in inXML.elements) { @@ -1149,10 +1164,14 @@ class BuildTool group.addFile( file ); } + // A file's own C or C++ standard is nearer than its group's + // Objective-C or Objective-C++ one, so it takes the file's file.mCStandard = el.has.c_standard ? Std.parseInt(substitute(el.att.c_standard)) : group.mCStandard; - file.mObjCStandard = el.has.objc_standard ? Std.parseInt(substitute(el.att.objc_standard)) : group.mObjCStandard; + file.mObjCStandard = el.has.objc_standard ? Std.parseInt(substitute(el.att.objc_standard)) : + el.has.c_standard ? null : group.mObjCStandard; file.mCxxStandard = el.has.cxx_standard ? Std.parseInt(substitute(el.att.cxx_standard)) : group.mCxxStandard; - file.mObjCxxStandard = el.has.objcxx_standard ? Std.parseInt(substitute(el.att.objcxx_standard)) : group.mObjCxxStandard; + file.mObjCxxStandard = el.has.objcxx_standard ? Std.parseInt(substitute(el.att.objcxx_standard)) : + el.has.cxx_standard ? null : group.mObjCxxStandard; if (el.has.tag) { diff --git a/tools/hxcpp/CompileCache.hx b/tools/hxcpp/CompileCache.hx index 9392f3e1b..86bff30d7 100644 --- a/tools/hxcpp/CompileCache.hx +++ b/tools/hxcpp/CompileCache.hx @@ -109,6 +109,88 @@ class CompileCache return true; } + // Trimming keeps what builds use, but reusing an entry leaves it as it + // was: an object up to date in the cache is linked from there, and + // Windows does not update access times. Changing an object's date would + // relink every build. So each target lists here the entries its last + // build used, and the list's date is when it used them + static inline var USE_DIR = ".used"; + + public static function recordUse(inTarget:String, inEntries:Array) + { + if (!hasCache) + return; + var prefix = compileCache + "/"; + var seen = new Map(); + var names = new Array(); + for(entry in inEntries) + { + entry = entry.split("\\").join("/"); + if (!StringTools.startsWith(entry, prefix)) + continue; + var parts = entry.substr(prefix.length).split("/"); + if (parts.length<2) + continue; + // A precompiled header's directory is used as a whole + var name = parts[1].substr(0,3)=="pch" ? parts[0] + "/" + parts[1] : parts.join("/"); + if (!seen.exists(name)) + { + seen.set(name,true); + names.push(name); + } + } + names.sort(Reflect.compare); + var content = names.join("\n"); + var dir = compileCache + "/" + USE_DIR; + var record = dir + "/" + haxe.crypto.Md5.encode(inTarget); + try + { + // The same entries recorded within the hour is near enough + if (FileSystem.exists(record) && Date.now().getTime() - FileSystem.stat(record).mtime.getTime() < 3600 * 1000.0 && + sys.io.File.getContent(record)==content) + return; + if (!FileSystem.exists(dir)) + PathManager.mkdir(dir); + sys.io.File.saveContent(record, content); + } + catch(e:Dynamic) + { + Log.v('Could not record the cache entries used in $record: $e'); + } + } + + // When each entry was last used, as far as the records tell + static function readUse(ioRecords:Array<{ filename:String, time:Float }>) + { + var used = new Map(); + var dir = compileCache + "/" + USE_DIR; + if (!FileSystem.exists(dir) || !FileSystem.isDirectory(dir)) + return used; + for(file in FileSystem.readDirectory(dir)) + { + var filename = dir + "/" + file; + try + { + var time = FileSystem.stat(filename).mtime.getTime(); + ioRecords.push( { filename:filename, time:time } ); + for(name in sys.io.File.getContent(filename).split("\n")) + if (name!="" && (!used.exists(name) || used.get(name), inProject:String, inDir:String, inFile:String, inInfo:sys.FileStat) + { + var time = inInfo.atime==null ? inInfo.mtime.getTime() : Math.max(inInfo.atime.getTime(),inInfo.mtime.getTime()); + var name = inDir.substr(0,3)=="pch" ? inProject + "/" + inDir : inProject + "/" + inDir + "/" + inFile; + return inUsed.exists(name) ? Math.max(time, inUsed.get(name)) : time; + } + public static function clear(inDays:Int,inMB:Int,inLogInfo:Bool,inProject:String) { try @@ -120,11 +202,16 @@ class CompileCache var tooOld = Date.now().getTime() - inDays * 24 * 3600 * 1000.0; var sizeKB:Float = 0; var fileInfo = []; + var records = []; + var used = readUse(records); for(project in projects) { if (inProject!=null && inProject!=project) continue; + // Not the use records, nor the time of the last trim + if (project.substr(0,1)==".") + continue; var projectHasDirs = false; var projDir = compileCache + "/" + project; if(!FileSystem.isDirectory(projDir)) @@ -152,18 +239,14 @@ class CompileCache if (inDays>0) { var info = FileSystem.stat(filename); - var atime = info.atime; - var time = atime==null ? info.mtime.getTime() : - Math.max(info.atime.getTime(),info.mtime.getTime() ); + var time = lastUse(used, project, dir, file, info); if (time>=tooOld) doDelete = false; } else if (inMB>0) { var info = FileSystem.stat(filename); - var atime = info.atime; - var time = atime==null ? info.mtime.getTime() : - Math.max(info.atime.getTime(),info.mtime.getTime() ); + var time = lastUse(used, project, dir, file, info); fileInfo.push( {filename:filename, time:time, size:info.size } ); sizeKB += info.size/1024; doDelete = false; @@ -211,6 +294,9 @@ class CompileCache } } + // A record older than every entry kept keeps nothing. Trimming one + // project leaves the records, which list others' entries too + var recordsBefore:Null = inDays>0 ? tooOld : null; if (inMB*1024(); + for(path in paths) + lines.push( (FileSystem.exists(path) ? Std.string(FileSystem.stat(path).mtime.getTime()) : "missing") + " " + path ); + return lines.join("\n"); + } + + static function readDates(inName:String):String + { + try { + if (FileSystem.exists(inName)) + return sys.io.File.getContent(inName); + } catch(e:Dynamic) { } + return null; + } + public function precompile(inGroup:FileGroup, inReuseIfPossible:Bool) { // header will be like "hxcpp" or "wx/wx" @@ -645,13 +682,19 @@ class Compiler // Like objs/hxcpp.pch or objs/wx.gch var pch_name = dir + "/" + file + mPCHExt; + var dates = inGroup.isCached() && pchChecksDates() ? getPchDates(inGroup) : null; + var datesName = dir + "/" + file + ".dates"; mPCHRebuilt = false; if (inGroup.isCached() || inReuseIfPossible) { // No obj needed for gcc var obj = mPCH=="msvc" ? PathManager.combine(dir, file + mExt) : null; if (FileSystem.exists(pch_name) && (obj==null || FileSystem.exists(obj)) ) - return obj; + { + if (dates==null || readDates(datesName)==dates) + return obj; + Log.v('Headers of $pch_name have other dates than when it was made'); + } } mPCHRebuilt = true; @@ -710,6 +753,12 @@ class Compiler //throw "Error creating pch: " + result + " - build cancelled"; } + if (dates!=null) + { + try { sys.io.File.saveContent(datesName, dates); } + catch(e:Dynamic) { Log.v('Could not write $datesName: $e'); } + } + if (mPCH == "msvc") return PathManager.combine(dir, file + mExt); return null; diff --git a/tools/hxcpp/Linker.hx b/tools/hxcpp/Linker.hx index cb87c25e4..7a4fb9e5f 100644 --- a/tools/hxcpp/Linker.hx +++ b/tools/hxcpp/Linker.hx @@ -21,6 +21,8 @@ class Linker public var mLastOutName:String; // The record of the last link this call made, or null when it linked nothing public var mLastHashFile:String; + // The record of what the last output is linked from, linked this call or not + public var mLastHashName:String; public var mAddLibPath:String; public function new(inExe:String) @@ -106,6 +108,7 @@ class Linker mLastOutName = out_name; mLastHashFile = null; + mLastHashName = hashFile; var lastLib = ""; var libs = new Array(); diff --git a/tools/hxcpp/Setup.hx b/tools/hxcpp/Setup.hx index c073cf8e3..acf39c62c 100644 --- a/tools/hxcpp/Setup.hx +++ b/tools/hxcpp/Setup.hx @@ -857,7 +857,11 @@ class Setup Sys.putEnv("HXCPP_WINXP_COMPAT","1"); xpCompat = true; } - Sys.putEnv("msvc_host_arch", ioDefines.exists("windows_arm_host") ? "x86" : "x64" ); + // The hosts of the compilers to use for arm64, best first: the ARM64 + // scripts take the first that is installed. On an ARM64 machine the + // x86-hosted compiler runs emulated in 32 bits, and can run out of + // memory on a precompiled header + Sys.putEnv("msvc_host_arch", ioDefines.exists("windows_arm_host") ? "arm64 x64 x86" : "x64" ); var vc_setup_proc = new Process("cmd.exe", ["/C", BuildTool.HXCPP + "\\toolchain\\msvc" + extra + "-setup.bat" ]); var vars_found = false;