diff --git a/.github/workflows/cmake-test-release-linux.yml b/.github/workflows/cmake-test-release-linux.yml index a6ff4d1d6..7f528850e 100644 --- a/.github/workflows/cmake-test-release-linux.yml +++ b/.github/workflows/cmake-test-release-linux.yml @@ -13,9 +13,11 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release - CACHE_VERSION: v8 + CACHE_VERSION: v9 LLVM_VERSION: 19 LLVM_TARGZFILE: "https://www.dropbox.com/scl/fi/l9xrfupdbwqbnckr5g36p/llvm_19_1_3_release.tgz?rlkey=xubw01vl6ey3xszbph32xqfip&st=okz2ghqx&dl=1" + GC_VERSION: "8.2.8" + LIBATOMIC_OPS_VERSION: "7.8.2" jobs: build: @@ -81,32 +83,27 @@ jobs: - name: Download 3rd party source - GC continue-on-error: true shell: sh - run: curl --insecure -L https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz --output gc-8.0.4.tar.gz + run: curl --insecure -L https://www.hboehm.info/gc/gc_source/gc-${{ env.GC_VERSION }}.tar.gz --output gc-${{ env.GC_VERSION }}.tar.gz - name: Download 3rd party source - GC:Atomic_ops continue-on-error: true shell: sh - run: curl --insecure -L https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz --output libatomic_ops-7.6.10.tar.gz + run: curl --insecure -L https://www.hboehm.info/gc/gc_source/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz --output libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz - name: UnZip 3rd party source - GC continue-on-error: false shell: sh - run: tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ + run: tar -xvzf gc-${{ env.GC_VERSION }}.tar.gz -C ./3rdParty/ - name: UnZip 3rd party source - GC:Atomic_ops continue-on-error: false shell: sh - run: tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ + run: tar -xvzf libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz -C ./3rdParty/ - name: Copy Atomic_ops to GC continue-on-error: false shell: sh - run: cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/ - - - name: Copy fixes to GC - continue-on-error: false - shell: sh - run: cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/ + run: cp -a ./3rdParty/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}/ ./3rdParty/gc-${{ env.GC_VERSION }}/libatomic_ops/ - name: Install Ninja continue-on-error: false @@ -122,7 +119,7 @@ jobs: continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/ninja/release shell: sh - run: cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF + run: cmake ../../../../3rdParty/gc-${{ env.GC_VERSION }} -G "Ninja" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/3rdParty/gc/release -DBUILD_SHARED_LIBS=OFF -Denable_threads=ON -Denable_cplusplus=OFF -Denable_docs=OFF - name: Build GC continue-on-error: false @@ -130,11 +127,13 @@ jobs: shell: sh run: cmake --build . --config ${{ env.BUILD_TYPE }} -j 8 - - name: Copy GC + - name: Install GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/ninja/release shell: sh - run: mkdir -p ../../../../3rdParty/gc/release/; cp ./lib* ../../../../3rdParty/gc/release/ + # Generates the BDWgc CMake package files (lib/cmake/bdwgc/BDWgcConfig.cmake) + # that the tsc build looks up via find_package(BDWgc CONFIG). + run: cmake --install . --config ${{ env.BUILD_TYPE }} - name: List GC files continue-on-error: false diff --git a/.github/workflows/cmake-test-release-win.yml b/.github/workflows/cmake-test-release-win.yml index 05a59e49c..7348256fc 100644 --- a/.github/workflows/cmake-test-release-win.yml +++ b/.github/workflows/cmake-test-release-win.yml @@ -13,9 +13,11 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release - CACHE_VERSION: v8 + CACHE_VERSION: v9 LLVM_VERSION: 19 - LLVM_ZIPFILE: "https://www.dropbox.com/scl/fi/xdcj15hlzpod06x4wpls1/llvm_19_1_3_release.zip?rlkey=x38yiyfw3y6bv15z5j3oi84lb&st=bz3u5xkv&dl=1" + LLVM_ZIPFILE: "https://www.dropbox.com/scl/fi/map5fet7x19bm8ztsr4ma/llvm_19_1_3_release_vs2026.zip?rlkey=iwae4mz45lf7nycawa7d61g3r&st=4ee1dfug&dl=1" + GC_VERSION: "8.2.8" + LIBATOMIC_OPS_VERSION: "7.8.2" jobs: build: @@ -23,7 +25,7 @@ jobs: # well on Windows or Mac. You can convert this to a matrix build if you need # cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: windows-2022 + runs-on: windows-latest steps: # - name: check disk space @@ -75,37 +77,32 @@ jobs: - name: Download 3rd party source - GC continue-on-error: true shell: pwsh - run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz" -OutFile "gc-8.0.4.tar.gz" + run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/gc-${{ env.GC_VERSION }}.tar.gz" -OutFile "gc-${{ env.GC_VERSION }}.tar.gz" - name: Download 3rd party source - GC:Atomic_ops continue-on-error: true shell: pwsh - run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz" -OutFile "libatomic_ops-7.6.10.tar.gz" + run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz" -OutFile "libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz" - name: UnZip 3rd party source - GC continue-on-error: false - run: tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ + run: tar -xvzf gc-${{ env.GC_VERSION }}.tar.gz -C ./3rdParty/ shell: pwsh - name: UnZip 3rd party source - GC:Atomic_ops continue-on-error: false - run: tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ + run: tar -xvzf libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz -C ./3rdParty/ shell: pwsh - name: Copy Atomic_ops to GC continue-on-error: false - run: xcopy /E /H /C /I /Y ".\3rdParty\libatomic_ops-7.6.10" ".\3rdParty\gc-8.0.4\libatomic_ops" - shell: pwsh - - - name: Copy fixes to GC - continue-on-error: false - run: xcopy /E /H /C /I /Y ".\docs\fix\gc" ".\3rdParty\gc-8.0.4" + run: xcopy /E /H /C /I /Y ".\3rdParty\libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}" ".\3rdParty\gc-${{ env.GC_VERSION }}\libatomic_ops" shell: pwsh - name: Configure GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/msbuild/x64/release - run: cmake ../../../../../3rdParty/gc-8.0.4 -G "Visual Studio 17 2022" -A x64 -Wno-dev -Denable_threads=ON -Denable_cplusplus=OFF + run: cmake ../../../../../3rdParty/gc-${{ env.GC_VERSION }} -G "Visual Studio 18 2026" -A x64 -Wno-dev -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/3rdParty/gc/x64/release -DBUILD_SHARED_LIBS=OFF -Denable_threads=ON -Denable_cplusplus=OFF -Denable_docs=OFF -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded shell: pwsh - name: Build GC @@ -114,10 +111,12 @@ jobs: run: cmake --build . --config ${{ env.BUILD_TYPE }} -j 8 shell: pwsh - - name: Copy GC + - name: Install GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/msbuild/x64/release - run: xcopy /E /H /C /I /Y .\${{ env.BUILD_TYPE }}\ ..\..\..\..\..\3rdParty\gc\x64\release\ + # Generates the BDWgc CMake package files (lib/cmake/bdwgc/BDWgcConfig.cmake) + # that the tsc build looks up via find_package(BDWgc CONFIG). + run: cmake --install . --config ${{ env.BUILD_TYPE }} shell: pwsh - name: List GC files @@ -129,7 +128,7 @@ jobs: - name: Configure continue-on-error: false working-directory: ${{github.workspace}}/__build/tsc/msbuild/x64/release - run: cmake ../../../../../tsc -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev + run: cmake ../../../../../tsc -G "Visual Studio 18 2026" -A x64 -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev shell: pwsh - name: Build diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 9bd685072..4084a1ee1 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -9,16 +9,18 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release - CACHE_VERSION: v8 + CACHE_VERSION: v9 LLVM_VERSION: 19 - LLVM_ZIPFILE: "https://www.dropbox.com/scl/fi/xdcj15hlzpod06x4wpls1/llvm_19_1_3_release.zip?rlkey=x38yiyfw3y6bv15z5j3oi84lb&st=bz3u5xkv&dl=1" + LLVM_ZIPFILE: "https://www.dropbox.com/scl/fi/map5fet7x19bm8ztsr4ma/llvm_19_1_3_release_vs2026.zip?rlkey=iwae4mz45lf7nycawa7d61g3r&st=4ee1dfug&dl=1" LLVM_TARGZFILE: "https://www.dropbox.com/scl/fi/l9xrfupdbwqbnckr5g36p/llvm_19_1_3_release.tgz?rlkey=xubw01vl6ey3xszbph32xqfip&st=okz2ghqx&dl=1" LLVM_UB20_TARGZFILE: "https://www.dropbox.com/scl/fi/jfs77u2moymjo57ca4r0s/llvm_19_1_3_release_UB20.tgz?rlkey=tia0bdfa07gaeidepumb1e1fy&st=np5mcrox&dl=1" + GC_VERSION: "8.2.8" + LIBATOMIC_OPS_VERSION: "7.8.2" jobs: build_on_windows: name: Create/Upload Release Asset (Windows) - runs-on: windows-2022 + runs-on: windows-latest steps: - name: Checkout code uses: actions/checkout@v4 @@ -75,41 +77,36 @@ jobs: - name: Download 3rd party source - GC continue-on-error: true shell: pwsh - run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz" -OutFile "gc-8.0.4.tar.gz" + run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/gc-${{ env.GC_VERSION }}.tar.gz" -OutFile "gc-${{ env.GC_VERSION }}.tar.gz" - name: Download 3rd party source - GC:Atomic_ops continue-on-error: true shell: pwsh - run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz" -OutFile "libatomic_ops-7.6.10.tar.gz" + run: Invoke-WebRequest -SkipCertificateCheck -Uri "https://www.hboehm.info/gc/gc_source/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz" -OutFile "libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz" - name: UnZip 3rd party source - GC continue-on-error: false - run: tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ + run: tar -xvzf gc-${{ env.GC_VERSION }}.tar.gz -C ./3rdParty/ shell: pwsh - name: UnZip 3rd party source - GC:Atomic_ops continue-on-error: false - run: tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ + run: tar -xvzf libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz -C ./3rdParty/ shell: pwsh - - name: Create gc-8.0.4\libatomic_ops Folders - run: if (!(Test-Path -Path ".\3rdParty\gc-8.0.4\libatomic_ops")) { New-Item -ItemType Directory -Force -Path ".\3rdParty\gc-8.0.4\libatomic_ops" }; + - name: Create gc-${{ env.GC_VERSION }}\libatomic_ops Folders + run: if (!(Test-Path -Path ".\3rdParty\gc-${{ env.GC_VERSION }}\libatomic_ops")) { New-Item -ItemType Directory -Force -Path ".\3rdParty\gc-${{ env.GC_VERSION }}\libatomic_ops" }; shell: pwsh - name: Copy Atomic_ops to GC continue-on-error: false - run: xcopy /E /H /C /I /Y ".\3rdParty\libatomic_ops-7.6.10" ".\3rdParty\gc-8.0.4\libatomic_ops" - shell: pwsh - - - name: Copy fixes to GC - continue-on-error: false - run: xcopy /E /H /C /I /Y ".\docs\fix\gc" ".\3rdParty\gc-8.0.4" + run: xcopy /E /H /C /I /Y ".\3rdParty\libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}" ".\3rdParty\gc-${{ env.GC_VERSION }}\libatomic_ops" shell: pwsh - name: Configure GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/msbuild/x64/release - run: cmake ../../../../../3rdParty/gc-8.0.4 -G "Visual Studio 17 2022" -A x64 -Wno-dev -Denable_threads=ON -Denable_cplusplus=OFF + run: cmake ../../../../../3rdParty/gc-${{ env.GC_VERSION }} -G "Visual Studio 18 2026" -A x64 -Wno-dev -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/3rdParty/gc/x64/release -DBUILD_SHARED_LIBS=OFF -Denable_threads=ON -Denable_cplusplus=OFF -Denable_docs=OFF -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded shell: pwsh - name: Build GC @@ -118,16 +115,18 @@ jobs: run: cmake --build . --config ${{ env.BUILD_TYPE }} -j 8 shell: pwsh - - name: Copy GC + - name: Install GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/msbuild/x64/release - run: xcopy /E /H /C /I /Y .\${{ env.BUILD_TYPE }}\ ..\..\..\..\..\3rdParty\gc\x64\release\ + # Generates the BDWgc CMake package files (lib/cmake/bdwgc/BDWgcConfig.cmake) + # that the tsc build looks up via find_package(BDWgc CONFIG). + run: cmake --install . --config ${{ env.BUILD_TYPE }} shell: pwsh - name: Configure continue-on-error: false working-directory: ${{github.workspace}}/__build/tsc/msbuild/x64/release - run: cmake ../../../../../tsc -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DTSC_PACKAGE_VERSION:STRING="${{ steps.version.outputs.TAG_NAME }}" -Wno-dev + run: cmake ../../../../../tsc -G "Visual Studio 18 2026" -A x64 -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DTSC_PACKAGE_VERSION:STRING="${{ steps.version.outputs.TAG_NAME }}" -Wno-dev shell: pwsh - name: Build @@ -145,7 +144,7 @@ jobs: - name: Create Zip of Windows Asset working-directory: ${{github.workspace}}/__build - run: Get-ChildItem -Path .\tsc\msbuild\x64\release\bin\tsc.exe, .\tsc\msbuild\x64\release\bin\TypeScriptRuntime.dll, .\gc\msbuild\x64\release\${{ env.BUILD_TYPE }}\gcmt-lib.lib, .\tsc\msbuild\x64\release\lib\TypeScriptAsyncRuntime.lib, ..\3rdParty\llvm\x64\release\lib\LLVMSupport.lib, ..\3rdParty\llvm\x64\release\bin\wasm-ld.exe | Compress-Archive -DestinationPath ..\tsc.zip + run: Get-ChildItem -Path .\tsc\msbuild\x64\release\bin\tsc.exe, .\tsc\msbuild\x64\release\bin\TypeScriptRuntime.dll, .\gc\msbuild\x64\release\${{ env.BUILD_TYPE }}\gc.lib, .\tsc\msbuild\x64\release\lib\TypeScriptAsyncRuntime.lib, ..\3rdParty\llvm\x64\release\lib\LLVMSupport.lib, ..\3rdParty\llvm\x64\release\bin\wasm-ld.exe | Compress-Archive -DestinationPath ..\tsc.zip shell: pwsh - name: Archive Zip of Windows Asset @@ -220,32 +219,27 @@ jobs: - name: Download 3rd party source - GC continue-on-error: true shell: sh - run: curl --insecure -L https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz --output gc-8.0.4.tar.gz + run: curl --insecure -L https://www.hboehm.info/gc/gc_source/gc-${{ env.GC_VERSION }}.tar.gz --output gc-${{ env.GC_VERSION }}.tar.gz - name: Download 3rd party source - GC:Atomic_ops continue-on-error: true shell: sh - run: curl --insecure -L https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz --output libatomic_ops-7.6.10.tar.gz + run: curl --insecure -L https://www.hboehm.info/gc/gc_source/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz --output libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz - name: UnZip 3rd party source - GC continue-on-error: false shell: sh - run: tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ + run: tar -xvzf gc-${{ env.GC_VERSION }}.tar.gz -C ./3rdParty/ - name: UnZip 3rd party source - GC:Atomic_ops continue-on-error: false shell: sh - run: tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ + run: tar -xvzf libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz -C ./3rdParty/ - name: Copy Atomic_ops to GC continue-on-error: false shell: sh - run: cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/ - - - name: Copy fixes to GC - continue-on-error: false - shell: sh - run: cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/ + run: cp -a ./3rdParty/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}/ ./3rdParty/gc-${{ env.GC_VERSION }}/libatomic_ops/ - name: Install Ninja continue-on-error: false @@ -261,7 +255,7 @@ jobs: continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/ninja/release shell: sh - run: cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF + run: cmake ../../../../3rdParty/gc-${{ env.GC_VERSION }} -G "Ninja" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/3rdParty/gc/release -DBUILD_SHARED_LIBS=OFF -Denable_threads=ON -Denable_cplusplus=OFF -Denable_docs=OFF - name: Build GC continue-on-error: false @@ -269,11 +263,13 @@ jobs: shell: sh run: cmake --build . --config ${{ env.BUILD_TYPE }} -j 8 - - name: Copy GC + - name: Install GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/ninja/release shell: sh - run: mkdir -p ../../../../3rdParty/gc/release/; cp ./lib* ../../../../3rdParty/gc/release/ + # Generates the BDWgc CMake package files (lib/cmake/bdwgc/BDWgcConfig.cmake) + # that the tsc build looks up via find_package(BDWgc CONFIG). + run: cmake --install . --config ${{ env.BUILD_TYPE }} - name: Configure continue-on-error: false @@ -300,7 +296,7 @@ jobs: - name: Create Tar.GZ of Linux Asset working-directory: ${{github.workspace}}/__build shell: sh - run: tar -czvhf ../tsc.tar.gz ./tsc/ninja/release/bin/tsc ./tsc/ninja/release/lib/libTypeScriptRuntime.so ./gc/ninja/release/libgcmt-lib.a ./tsc/ninja/release/lib/libTypeScriptAsyncRuntime.a ../3rdParty/llvm/release/bin/wasm-ld ../3rdParty/llvm/release/lib/libLLVMSupport.a ../3rdParty/llvm/release/lib/libLLVMDemangle.a + run: tar -czvhf ../tsc.tar.gz ./tsc/ninja/release/bin/tsc ./tsc/ninja/release/lib/libTypeScriptRuntime.so ./gc/ninja/release/libgc.a ./tsc/ninja/release/lib/libTypeScriptAsyncRuntime.a ../3rdParty/llvm/release/bin/wasm-ld ../3rdParty/llvm/release/lib/libLLVMSupport.a ../3rdParty/llvm/release/lib/libLLVMDemangle.a - name: Archive Tar.GZ of Linux Asset uses: actions/upload-artifact@v4 @@ -374,32 +370,27 @@ jobs: - name: Download 3rd party source - GC continue-on-error: true shell: sh - run: curl --insecure -L https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz --output gc-8.0.4.tar.gz + run: curl --insecure -L https://www.hboehm.info/gc/gc_source/gc-${{ env.GC_VERSION }}.tar.gz --output gc-${{ env.GC_VERSION }}.tar.gz - name: Download 3rd party source - GC:Atomic_ops continue-on-error: true shell: sh - run: curl --insecure -L https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz --output libatomic_ops-7.6.10.tar.gz + run: curl --insecure -L https://www.hboehm.info/gc/gc_source/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz --output libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz - name: UnZip 3rd party source - GC continue-on-error: false shell: sh - run: tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ + run: tar -xvzf gc-${{ env.GC_VERSION }}.tar.gz -C ./3rdParty/ - name: UnZip 3rd party source - GC:Atomic_ops continue-on-error: false shell: sh - run: tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ + run: tar -xvzf libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}.tar.gz -C ./3rdParty/ - name: Copy Atomic_ops to GC continue-on-error: false shell: sh - run: cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/ - - - name: Copy fixes to GC - continue-on-error: false - shell: sh - run: cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/ + run: cp -a ./3rdParty/libatomic_ops-${{ env.LIBATOMIC_OPS_VERSION }}/ ./3rdParty/gc-${{ env.GC_VERSION }}/libatomic_ops/ - name: Install Ninja continue-on-error: false @@ -415,7 +406,7 @@ jobs: continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/ninja/release shell: sh - run: cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF + run: cmake ../../../../3rdParty/gc-${{ env.GC_VERSION }} -G "Ninja" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/3rdParty/gc/release -DBUILD_SHARED_LIBS=OFF -Denable_threads=ON -Denable_cplusplus=OFF -Denable_docs=OFF - name: Build GC continue-on-error: false @@ -423,11 +414,13 @@ jobs: shell: sh run: cmake --build . --config ${{ env.BUILD_TYPE }} -j 8 - - name: Copy GC + - name: Install GC continue-on-error: false working-directory: ${{github.workspace}}/__build/gc/ninja/release shell: sh - run: mkdir -p ../../../../3rdParty/gc/release/; cp ./lib* ../../../../3rdParty/gc/release/ + # Generates the BDWgc CMake package files (lib/cmake/bdwgc/BDWgcConfig.cmake) + # that the tsc build looks up via find_package(BDWgc CONFIG). + run: cmake --install . --config ${{ env.BUILD_TYPE }} - name: Configure continue-on-error: false @@ -454,7 +447,7 @@ jobs: - name: Create Tar.GZ of Linux Asset working-directory: ${{github.workspace}}/__build shell: sh - run: tar -czvhf ../tsc-ub20.tar.gz ./tsc/ninja/release/bin/tsc ./tsc/ninja/release/lib/libTypeScriptRuntime.so ./gc/ninja/release/libgcmt-lib.a ./tsc/ninja/release/lib/libTypeScriptAsyncRuntime.a ../3rdParty/llvm/release/bin/wasm-ld ../3rdParty/llvm/release/lib/libLLVMSupport.a ../3rdParty/llvm/release/lib/libLLVMDemangle.a + run: tar -czvhf ../tsc-ub20.tar.gz ./tsc/ninja/release/bin/tsc ./tsc/ninja/release/lib/libTypeScriptRuntime.so ./gc/ninja/release/libgc.a ./tsc/ninja/release/lib/libTypeScriptAsyncRuntime.a ../3rdParty/llvm/release/bin/wasm-ld ../3rdParty/llvm/release/lib/libLLVMSupport.a ../3rdParty/llvm/release/lib/libLLVMDemangle.a - name: Archive Tar.GZ of Linux Asset uses: actions/upload-artifact@v4 diff --git a/README.md b/README.md index ab0143831..452e3ed41 100644 --- a/README.md +++ b/README.md @@ -3,33 +3,54 @@ [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=BBJ4SQYLA6D2L) -# Build +A native ahead-of-time (AOT) and JIT compiler for **TypeScript**, built on **LLVM/MLIR**. +It compiles `.ts` files directly to native executables, WebAssembly, or runs them +on the fly via a built-in JIT — no Node.js or JavaScript runtime required. + +## CI Status [![Test Build (Windows)](https://github.com/ASDAlexander77/TypeScriptCompiler/actions/workflows/cmake-test-release-win.yml/badge.svg)](https://github.com/ASDAlexander77/TypeScriptCompiler/actions/workflows/cmake-test-release-win.yml) [![Test Build (Linux)](https://github.com/ASDAlexander77/TypeScriptCompiler/actions/workflows/cmake-test-release-linux.yml/badge.svg)](https://github.com/ASDAlexander77/TypeScriptCompiler/actions/workflows/cmake-test-release-linux.yml) -# What's new +## Contents + +- [What's new](#whats-new) +- [Roadmap](#roadmap) +- [Demo](#demo) +- [Try it online](#try-it) +- [Example](#example) +- [Running your code](#run-as-jit) + - [As JIT](#run-as-jit) + - [As a native executable](#compile-as-binary-executable) + - [As WebAssembly](#compiling-as-wasm) +- [Building from source](#build) +- [Community](#chat-room) +- [License](#license) + +## What's new + +- Migrated to **Visual Studio 2026** (Windows build chain) - JavaScript Built-in objects library [[Default Library repo](https://github.com/ASDAlexander77/TypeScriptCompilerDefaultLib/)] - Visual Studio Code project -```cmd +```bat tsc --new Test1 ``` - Strict null checks -```TypeScript +```typescript let sn: string | null = null; // Ok let s: string = null; // error ``` -- improved `Template Literal Types` -```TypeScript +- Improved `Template Literal Types` +```typescript type Color = "red" | "green" | "blue"; type HexColor = `#${string}`; ``` - Public, private, and protected modifiers -```TypeScript +```typescript class Point { private x: number; #y: number; @@ -41,7 +62,7 @@ p.#y // error ``` - Class from Tuple -```TypeScript +```typescript class Point { x: number; y: number; @@ -55,7 +76,7 @@ const l = new Line({ x: 0, y: 1 }, { x: 1.0, y: 2.0 }); ``` - Compile-time `if`s -```TypeScript +```typescript function isArray(value: T): value is T { return true; } @@ -76,38 +97,41 @@ const v2 = gen([]); // result: 0 - Migrated to LLVM 19.1.3 -- improved ```generating debug information``` more info here: [Wiki:How-To](https://github.com/ASDAlexander77/TypeScriptCompiler/wiki/How-To#compile-and-debug-with-visual-studio-code) -```cmd +- Improved `generating debug information` — more info here: [Wiki:How-To](https://github.com/ASDAlexander77/TypeScriptCompiler/wiki/How-To#compile-and-debug-with-visual-studio-code) +```bat tsc --di --opt_level=0 --emit=exe example.ts ``` - [more...](https://github.com/ASDAlexander77/TypeScriptCompiler/wiki/What's-new) -# Planning +## Roadmap + - [x] Migrating to LLVM 19.1.3 - [x] Shared libraries -- [ ] JavaScript Built-in classes library +- [x] JavaScript Built-in classes library + +## Demo -# Demo [(click here)](https://github.com/ASDAlexander77/TypeScriptCompiler/releases/) [![Demo](https://raw.githubusercontent.com/ASDAlexander77/ASDAlexander77.github.io/main/img/tsc_emit.gif)](https://github.com/ASDAlexander77/TypeScriptCompiler/releases/) -# Try it +## Try it + [(click here)](https://godbolt.org/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAZgQDbYB2AhgLbYgDkAjF%2BTXRMiAZVQtGIHgA4BQogFUAztgAKAD24AGfgCsp5eiyagiATwAO2JalIELRcisaoiBIdWaYAwunoBXNiYQACZyLwAZAiZsADlAgCNsUhAAZh5yC3QlYncmXwCg0Mzs3KEomPi2JJT0p2wXNyERIhZSIgLA4LDnbFc8lraiCrjE5LSMpVb2zqKe6eHo0erx9IBKJ3R/UlROLhYEqdIWVwBqVCMlJVOAEWwLIY5hU4BSAHYAIRetAEFT//OQiO/lcZAgFn8CXoBFQp1YHBApyO0WAa1en3eN2%2BP2xANOFjswli7GwEDWiIAbugCJh0V9fni8QTokQIC8QiE7g92k8iHCSYj2SFXiEPqciEgCEoAHTw7BrF6pel/AGY7G4gEHI4nPnM4QAWWw2DcJjJlOpmEVYoA9NbTmx/FNTklTgQ2BZGLzsLToqccHYKd7zpcVEp1W8sb9sRcWFdTj9UBh/MIUVzHsw%2Bdh1EQvNc0zyM3SNf8MExgaDSGSiwzGf8lP4rJWhQmkymTKdjLSfv5CCbgEKFUrTrbAWWiKQQSRSNdff6CIHaTGrtZ7Y6%2BeJ6PQkQ3kmTi%2BjIzia/89URDcaUWbTlSadWVbXT2yOQAVJDYeOJrZt4C3e7p54cMa1zYCcSCnPqQiYCwZgdnyPBaOw0oDla%2B5qlGx6nMAzDJCwOYAEr3GQRBKFeN60u8yq1iehKskKADi2HHH2HafsmzGkIR7QytKSEcoOlGqhG4aHtiNDJv0Qj2iw0RVhR%2B6MHyODckQvKIvmKkZlaw52ugADW4roOcHG4e%2BLCnBxNDJMwuwGR2TAdoc446uKljYPuSn/nyio3HC2AAO4fq2fbqbye5DiOem2bYIE5nZtKxjkwD2WZTBCAAtFqTlnPWCRLmGGEeQWwjSqexIcGFAn/IVGnFae559hV%2B62tVvLSlhMRMdgBFZFxFXaacySkGQiItYWUpwugfLoDQLlWIFX7BX%2BRWOOcxipXyJy7HG7U4fhnHEcJXAbPQ3AAKz8MEXA6OQ6DcM%2BrliHYDinMSbiBkiWw7O%2B7LpPwRDaEdGy6WkqTSqk4MQ5DkMAGyGNwAAs/BsCAbzw2DqTSJjqTw/DbzQ1oWjw%2BQl3XbdXD8EoIBaOQ/1XUd5BwLAKBZn0/hTpQ1BtMASiqMYDQiEg6B%2BZdfDkBg7oMLheS8zE9AC0LJP8OLFgMOMxGoAA%2BloWsa6kp0a8AqBi%2BgEuMKQZV7ErJsq2bADybPy8LAPhOofQ/KQ3PcPwLOoC0hCXfwgjCGIEicDwRNB4oKgaM7%2BgZEYJggOYVg2E9jjQoc8AbOgDh5JT5M3YGpB2DglOQBsSifbsBhTP7Mv84LTu8PwfnHBY3B8MdZ0Xc7ZO4K7qBs2Qpz3VYj32Hyr3zu%2Bvim8kpxaNKi8EtgeunAAUgAks%2BpwQHR3hohAo/YOPz1T4G5CnPgxDDz9PBrH9ANrBsb4sP61Bd1wiPkMjISndK0NoY8GAdDU6p0QipAAJyQKAcTXuXsnBUxpk/IGaR/4Yz1uAngeNIHYLeG8OGXBUg9zpjdBBtMdAbEZsgNA1tVYUCoBAZW9Ck42B1trPWBsjY4ApDCbAAA1Ag/lbZWBFoHBgOZpzUASM7BI0Q2hmA7vwORrBSBmFtgkXQfRaai3FryW2TB6CKNITgBI/hgDeAkPQfOoscBsGMMASQJiCAcX6IGfO10fZsz2KLFkDRnYZ2OGo3wOBnbjjdEojYNAjDc0EcI0RSi5DBw3GHCO8hlBqE0KQuOhgHFJ1cqnCehgCCZ3LjdXOQIEHoCLiXawWd6iNDyJ4JgPg/BdAMJEJYVQagGCyDkJo%2BQ2lFAyH0soTARjdPGJMBo2iBgLFmMEaZjTmgLAmWMFIkx5lDMWU4VZXT1lSArlXMOn9zpwNIWTEeD1bATxelLd6s8bbz0XsvDia8t47z3gfXe18pwinWI/Omz9yCv3fmScgwN0jShCNIdI4d4bSEgajRFWhZAnS/iQ0mCDKbUwofTahEAUAuI5kwuhZsLZ3WuWnO5b0Z5kueUvEqbzTob23rvfeD9wi9jIDSAwkcQ6SHDkkqOmTY41xmRJYIEAvALI6S0tZKwNklH6XkWVIzSgDIVT0pZsyVlDDVQ03VTBBjtC1VM3Z%2Brtk1z2ZUA598aYcWwLyrQpzMX8DJhECI/D9SnE3nhU4cS/Lz2PqfSe9y6Vz1IAvRlK93lsq%2BYfX5t8IEZFOI8%2Bh/z76Asoag8G6MoYFtSIQ7%2BisyEFxxcgoFn8QhurLdmwG5Ai45A8PDIAA%3D%3D) [![Compiler Explorer](https://asdalexander77.github.io/img/god_bolt_tsc_native.jpg)](https://godbolt.org/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAZgQDbYB2AhgLbYgDkAjF%2BTXRMiAZVQtGIHgA4BQogFUAztgAKAD24AGfgCsp5eiyagiATwAO2JalIELRcisaoiBIdWaYAwunoBXNiYQACZyLwAZAiZsADlAgCNsUhAAZh5yC3QlYncmXwCg0Mzs3KEomPi2JJT0p2wXNyERIhZSIgLA4LDnbFc8lraiCrjE5LSMpVb2zqKe6eHo0erx9IBKJ3R/UlROLhYEqdIWVwBqVCMlJVOAEWwLIY5hU4BSAHYAIRetAEFT//OQiO/lcZAgFn8CXoBFQp1YHBApyO0WAa1en3eN2%2BP2xANOFjswli7GwEDWiIAbugCJh0V9fni8QTokQIC8QiE7g92k8iHCSYj2SFXiEPqciEgCEoAHTw7BrF6pel/AGY7G4gEHI4nPnM4QAWWw2DcJjJlOpmEVYoA9NbTmx/FNTklTgQ2BZGLzsLToqccHYKd7zpcVEp1W8sb9sRcWFdTj9UBh/MIUVzHsw%2Bdh1EQvNc0zyM3SNf8MExgaDSGSiwzGf8lP4rJWhQmkymTKdjLSfv5CCbgEKFUrTrbAWWiKQQSRSNdff6CIHaTGrtZ7Y6%2BeJ6PQkQ3kmTi%2BjIzia/89URDcaUWbTlSadWVbXT2yOQAVJDYeOJrZt4C3e7p54cMa1zYCcSCnPqQiYCwZgdnyPBaOw0oDla%2B5qlGx6nMAzDJCwOYAEr3GQRBKFeN60u8yq1iehKskKADi2HHH2HafsmzGkIR7QytKSEcoOlGqhG4aHtiNDJv0Qj2iw0RVhR%2B6MHyODckQvKIvmKkZlaw52ugADW4roOcHG4e%2BLCnBxNDJMwuwGR2TAdoc446uKljYPuSn/nyio3HC2AAO4fq2fbqbye5DiOem2bYIE5nZtKxjkwD2WZTBCAAtFqTlnPWCRLmGGEeQWwjSqexIcGFAn/IVGnFae559hV%2B62tVvLSlhMRMdgBFZFxFXaacySkGQiItYWUpwugfLoDQLlWIFX7BX%2BRWOOcxipXyJy7HG7U4fhnHEcJXAbPQ3AAKz8MEXA6OQ6DcM%2BrliHYDinMSbiBkiWw7O%2B7LpPwRDaEdGy6WkqTSqk4MQ5DkMAGyGNwAAs/BsCAbzw2DqTSJjqTw/DbzQ1oWjw%2BQl3XbdXD8EoIBaOQ/1XUd5BwLAKBZn0/hTpQ1BtMASiqMYDQiEg6B%2BZdfDkBg7oMLheS8zE9AC0LJP8OLFgMOMxGoAA%2BloWsa6kp0a8AqBi%2BgEuMKQZV7ErJsq2bADybPy8LAPhOofQ/KQ3PcPwLOoC0hCXfwgjCGIEicDwRNB4oKgaM7%2BgZEYJggOYVg2E9jjQoc8AbOgDh5JT5M3YGpB2DglOQBsSifbsBhTP7Mv84LTu8PwfnHBY3B8MdZ0Xc7ZO4K7qBs2Qpz3VYj32Hyr3zu%2Bvim8kpxaNKi8EtgeunAAUgAks%2BpwQHR3hohAo/YOPz1T4G5CnPgxDDz9PBrH9ANrBsb4sP61Bd1wiPkMjISndK0NoY8GAdDU6p0QipAAJyQKAcTXuXsnBUxpk/IGaR/4Yz1uAngeNIHYLeG8OGXBUg9zpjdBBtMdAbEZsgNA1tVYUCoBAZW9Ck42B1trPWBsjY4ApDCbAAA1Ag/lbZWBFoHBgOZpzUASM7BI0Q2hmA7vwORrBSBmFtgkXQfRaai3FryW2TB6CKNITgBI/hgDeAkPQfOoscBsGMMASQJiCAcX6IGfO10fZsz2KLFkDRnYZ2OGo3wOBnbjjdEojYNAjDc0EcI0RSi5DBw3GHCO8hlBqE0KQuOhgHFJ1cqnCehgCCZ3LjdXOQIEHoCLiXawWd6iNDyJ4JgPg/BdAMJEJYVQagGCyDkJo%2BQ2lFAyH0soTARjdPGJMBo2iBgLFmMEaZjTmgLAmWMFIkx5lDMWU4VZXT1lSArlXMOn9zpwNIWTEeD1bATxelLd6s8bbz0XsvDia8t47z3gfXe18pwinWI/Omz9yCv3fmScgwN0jShCNIdI4d4bSEgajRFWhZAnS/iQ0mCDKbUwofTahEAUAuI5kwuhZsLZ3WuWnO5b0Z5kueUvEqbzTob23rvfeD9wi9jIDSAwkcQ6SHDkkqOmTY41xmRJYIEAvALI6S0tZKwNklH6XkWVIzSgDIVT0pZsyVlDDVQ03VTBBjtC1VM3Z%2Brtk1z2ZUA598aYcWwLyrQpzMX8DJhECI/D9SnE3nhU4cS/Lz2PqfSe9y6Vz1IAvRlK93lsq%2BYfX5t8IEZFOI8%2Bh/z76Asoag8G6MoYFtSIQ7%2BisyEFxxcgoFn8QhurLdmwG5Ai45A8PDIAA%3D%3D) -Chat Room ---------- +## Chat Room Want to chat with other members of the TypeScriptCompiler community? -[![Join the chat at https://gitter.im/ASDAlexander77/TypeScriptCompiler](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ASDAlexander77/TypeScriptCompiler?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +- [GitHub Discussions](https://github.com/ASDAlexander77/TypeScriptCompiler/discussions) (preferred) +- [![Join the chat at https://gitter.im/ASDAlexander77/TypeScriptCompiler](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ASDAlexander77/TypeScriptCompiler?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) (legacy) -# Example +## Example -```TypeScript +```typescript abstract class Department { constructor(public name: string) {} @@ -142,12 +166,14 @@ function main() { ``` Run -```cmd + +```bat tsc --emit=jit --opt --shared-libs=TypeScriptRuntime.dll example.ts ``` Result -``` + +```text Department name: Accounting and Auditing The Accounting Department meets each Monday at 10am. ``` @@ -155,33 +181,51 @@ The Accounting Department meets each Monday at 10am. ## Run as JIT - with Garbage collection -```cmd + +```bat tsc --emit=jit --opt --shared-libs=TypeScriptRuntime.dll hello.ts ``` - without Garbage collection -```cmd + +```bat tsc --emit=jit --nogc hello.ts ``` File ``hello.ts`` -```TypeScript +```typescript function main() { print("Hello World!"); } ``` + Result -``` + +```text Hello World! ``` ## Compile as Binary Executable +> Make sure you have [built `tsc` from source](#build) first. + +The compile scripts below set a few environment variables so the linker can find the +runtime libraries, then invoke `tsc` with `--emit=exe`. **Edit the paths to match your +checkout** — the `C:\dev\...` / `~/dev/...` values are only examples. + +| Variable | Points to | +| --- | --- | +| `GC_LIB_PATH` | Boehm GC library (the garbage collector) | +| `LLVM_LIB_PATH` | LLVM/MLIR libraries | +| `TSC_LIB_PATH` | TSC runtime library | +| `TSCEXEPATH` | Folder containing the `tsc` executable | + ### On Windows File ``tsc-compile.bat`` -```cmd + +```bat set FILENAME=%1 set GC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\gc\msbuild\x64\release\Release set LLVM_LIB_PATH=C:\dev\TypeScriptCompiler\__build\llvm\msbuild\x64\release\Release\lib @@ -189,24 +233,29 @@ set TSC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-release\l set TSCEXEPATH=C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-release\bin %TSCEXEPATH%\tsc.exe --opt --emit=exe %FILENAME%.ts ``` -Compile -```cmd + +Compile + +```bat tsc-compile.bat hello ``` Run -``` + +```text hello.exe ``` Result -``` + +```text Hello World! ``` ### On Linux (Ubuntu 20.04 and 22.04) File ``tsc-compile.sh`` + ```bash FILENAME=$1 export TSC_LIB_PATH=~/dev/TypeScriptCompiler/__build/tsc/linux-ninja-gcc-release/lib @@ -215,37 +264,49 @@ export GC_LIB_PATH=~/dev/TypeScriptCompiler/3rdParty/gc/release TSCEXEPATH=~/dev/TypeScriptCompiler/__build/tsc/linux-ninja-gcc-release/bin $TSCEXEPATH/tsc --emit=exe $FILENAME.ts --relocation-model=pic ``` -Compile + +Compile + ```bash sh -f tsc-compile.sh hello ``` Run -``` + +```text ./hello ``` Result -``` + +```text Hello World! ``` -### Compiling as WASM +## Compiling as WASM + ### On Windows + File ``tsc-compile-wasm.bat`` -```cmd + +```bat set FILENAME=%1 set GC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\gc\msbuild\x64\release\Release set LLVM_LIB_PATH=C:\dev\TypeScriptCompiler\__build\llvm\msbuild\x64\release\Release\lib set TSC_LIB_PATH=C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-release\lib C:\dev\TypeScriptCompiler\__build\tsc\windows-msbuild-release\bin\tsc.exe --emit=exe --nogc -mtriple=wasm32-unknown-unknown %FILENAME%.ts ``` -Compile -```cmd +Compile + +```bat tsc-compile-wasm.bat hello ``` Run ``run.html`` + +
+Click to expand the full run.html WebAssembly loader + ```html @@ -384,38 +445,42 @@ Run ``run.html`` ``` +
+ ## Build ### On Windows #### Requirements: -- ``Visual Studio 2022`` -- 512GB of free space on disk +- ``Visual Studio 2026`` +- ~50 GB of free disk space (LLVM/MLIR build dominates this) +> The hardcoded `C:\dev\...` paths in the scripts below are examples — adjust them to your checkout location. First, precompile dependencies -```cmd +```bat cd TypeScriptCompiler -prepare_3rdParty.bat +prepare_3rdParty.bat ``` To build ``TSC`` binaries: -```cmd +```bat cd TypeScriptCompiler\tsc config_tsc_release.bat build_tsc_release.bat ``` ### On Linux (Ubuntu 20.04 and 22.04) + #### Requirements: - `gcc` or `clang` - `cmake` - `ninja-build` -- 512GB of free space on disk +- ~50 GB of free disk space (LLVM/MLIR build dominates this) - sudo apt-get install ``libtinfo-dev`` First, precompile dependencies @@ -434,3 +499,13 @@ chmod +x *.sh ./config_tsc_release.sh ./build_tsc_release.sh ``` + +## License + +This project is licensed under the **MIT License** — see the [LICENSE](LICENSE) file for details. + +## Contributing + +Issues and pull requests are welcome. See the +[Wiki](https://github.com/ASDAlexander77/TypeScriptCompiler/wiki) for documentation, +build notes, and how-to guides. diff --git a/docs/fix/gc/CMakeLists.txt b/docs/fix/gc/CMakeLists.txt deleted file mode 100644 index 9eb9dd2a8..000000000 --- a/docs/fix/gc/CMakeLists.txt +++ /dev/null @@ -1,263 +0,0 @@ -# -# Copyright (c) 1994 by Xerox Corporation. All rights reserved. -# Copyright (c) 1996 by Silicon Graphics. All rights reserved. -# Copyright (c) 1998 by Fergus Henderson. All rights reserved. -# Copyright (c) 2000-2010 by Hewlett-Packard Company. All rights reserved. -## -# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED -# OR IMPLIED. ANY USE IS AT YOUR OWN RISK. -## -# Permission is hereby granted to use or copy this program -# for any purpose, provided the above notices are retained on all copies. -# Permission to modify the code and to distribute modified code is granted, -# provided the above notices are retained, and a notice that the code was -# modified is included with the above copyright notice. -## - -# -# get cmake and run: -# cmake -G "Visual Studio 8 2005" -# in the same dir as this file -# this will generate gc.sln -# - -SET(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required - -PROJECT(gc) - -INCLUDE(CTest) - -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - -ADD_DEFINITIONS("-D_CRT_SECURE_NO_DEPRECATE - -DALL_INTERIOR_POINTERS -DNO_EXECUTE_PERMISSION") - -IF(APPLE) - IF("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") - SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;x86_64" CACHE STRING "Build architectures for Mac OS X" FORCE) - ENDIF() -ENDIF(APPLE) - -#LIBATOMIC #TODO -#ADD_LIBRARY(atomic_ops STATIC ) -#SET_TARGET_PROPERTIES(atomic_ops PROPERTIES COMPILE_FLAGS -DNO_DEBUGGING) - - -#LIBGC - -INCLUDE_DIRECTORIES(include) -INCLUDE_DIRECTORIES(libatomic_ops/src) - -SET(SRC alloc.c reclaim.c allchblk.c misc.c mach_dep.c os_dep.c - mark_rts.c headers.c mark.c obj_map.c blacklst.c finalize.c - new_hblk.c dbg_mlc.c malloc.c dyn_load.c typd_mlc.c ptr_chck.c - mallocx.c) -SET(LIBS) -OPTION(enable_threads "TODO" NO) -IF(enable_threads) - FIND_PACKAGE(Threads REQUIRED) - MESSAGE("Thread Model: ${CMAKE_THREAD_LIBS_INIT}" ) - INCLUDE_DIRECTORIES(${Threads_INCLUDE_DIR}) - SET(LIBS ${LIBS} ${Threads_LIBRARIES}) -ENDIF(enable_threads) - -OPTION(enable_handle_fork "Attempt to ensure a usable collector after fork()" ON) - -OPTION(enable_thread_local_alloc "Turn on thread-local allocation optimization" ON) - -OPTION(enable_parallel_mark "Parallelize marking and free list construction" ON) - -#IF(Threads_FOUND) -# ADD_DEFINITIONS("") -#ELSE -# MESSAGE("Parallel mark requires enable_threads ON" ) -#ENDIF(Threads_FOUND) - -OPTION(enable_cplusplus "install C++ support" ON) -IF(enable_cplusplus) - SET(SRC ${SRC} gc_cpp.cc) -ENDIF(enable_cplusplus) - -SET(_HOST ${CMAKE_HOST_SYSTEM_PROCESSOR}--${CMAKE_SYSTEM}) #FIXME missing the vendor field. -STRING(TOLOWER ${_HOST} HOST) -MESSAGE("HOST = ${HOST}") - -# Thread Detection. Relying on cmake for lib and includes. -#TODO check cmake detection -IF(CMAKE_USE_PTHREADS_INIT) - SET(SRC ${SRC} pthread_start.c pthread_support.c pthread_stop_world.c) - # Common defines for most POSIX platforms. - IF( HOST MATCHES .*-.*-aix.*|.*-.*-android.*|.*-.*-cygwin.*|.*-.*-darwin.*|.*-.*-.*freebsd.*|.*-.*-haiku.*|.*-.*-gnu.*|.*-.*-hpux11.*|.*-.*-irix.*|.*-.*-.*linux.*|.*-.*-nacl.*|.*-.*-netbsd.*|.*-.*-openbsd.*|.*-.*-osf.*|.*-.*-solaris.*) - ADD_DEFINITIONS("-DGC_THREADS -D_REENTRANT") - IF(enable_parallel_mark) - ADD_DEFINITIONS("-DPARALLEL_MARK") - ENDIF(enable_parallel_mark) - IF(enable_thread_local_alloc) - ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") - SET(SRC ${SRC} thread_local_alloc.c) - ENDIF(enable_thread_local_alloc) - MESSAGE("Explicit GC_INIT() calls may be required.") - ENDIF() - IF ( HOST MATCHES .*-.*-hpux11.*) - MESSAGE("Only HP/UX 11 POSIX threads are supported.") - ADD_DEFINITIONS("-D_POSIX_C_SOURCE=199506L") #TODO test -DVAR=value. Alternative is COMPILE_DEFINITIONS property - ENDIF() - IF ( HOST MATCHES .*-.*-hpux10.*) - MESSAGE("HP/UX 10 POSIX threads are not supported.") - ENDIF() - IF ( HOST MATCHES .*-.*-netbsd.*) - MESSAGE("Only on NetBSD 2.0 or later.") - ADD_DEFINITIONS("-D_PTHREADS") - ENDIF() - IF( HOST MATCHES .*-.*-android.*) - # Android NDK does not provide pthread_atfork. - ELSEIF( HOST MATCHES .*-.*-aix.*|.*-.*-cygwin.*|.*-.*-freebsd.*|.*-.*-haiku.*|.*-.*-hpux11.*|.*-.*-irix.*|.*-.*-kfreebsd.*-gnu|.*-.*-.*linux.*|.*-.*-netbsd.*|.*-.*-openbsd.*|.*-.*-osf.*|.*-.*-solaris.*) - IF(enable_handle_fork) - ADD_DEFINITIONS("-DHANDLE_FORK") - ENDIF(enable_handle_fork) - ENDIF() - IF ( HOST MATCHES .*-.*-cygwin.*) - SET(SRC ${SRC} win32_threads.c) - ENDIF() - IF ( HOST MATCHES .*-.*-darwin.*) - IF(enable_handle_fork) - # The incremental mode conflicts with fork handling. - IF(enable_parallel_mark) - ADD_DEFINITIONS("-DHANDLE_FORK") - ENDIF(enable_parallel_mark) - ENDIF(enable_handle_fork) - SET(SRC ${SRC} darwin_stop_world.c) - #TODO - #darwin_threads=true - ENDIF() -ENDIF(CMAKE_USE_PTHREADS_INIT) - -IF(CMAKE_USE_WIN32_THREADS_INIT) - ADD_DEFINITIONS("-DGC_THREADS") - IF(enable_parallel_mark) - ADD_DEFINITIONS("-DPARALLEL_MARK") - IF(enable_thread_local_alloc) - ADD_DEFINITIONS("-DTHREAD_LOCAL_ALLOC") - SET(SRC ${SRC} thread_local_alloc.c) - ENDIF(enable_thread_local_alloc) - ENDIF() - ADD_DEFINITIONS("-DEMPTY_GETENV_RESULTS") #TODO test - SET(SRC ${SRC} win32_threads.c) -ENDIF(CMAKE_USE_WIN32_THREADS_INIT) - -OPTION(enable_gcj_support "Support for gcj" ON) -IF(enable_gcj_support) - ADD_DEFINITIONS("-DGC_GCJ_SUPPORT") - IF(enable_threads) - ADD_DEFINITIONS("-DGC_ENABLE_SUSPEND_THREAD") - ENDIF(enable_threads) - SET(SRC ${SRC} gcj_mlc.c) -ENDIF(enable_gcj_support) - -OPTION(enable_disclaim "Support alternative finalization interface" ON) -IF(enable_disclaim) - ADD_DEFINITIONS("-DENABLE_DISCLAIM") - SET(SRC ${SRC} fnlz_mlc.c) -ENDIF(enable_disclaim) - -OPTION(enable_java_finalization "Support for java finalization" ON) -IF(enable_java_finalization) - ADD_DEFINITIONS("-DJAVA_FINALIZATION") -ENDIF(enable_java_finalization) - -OPTION(enable_atomic_uncollectable "Support for atomic uncollectible allocation" ON) -IF(enable_atomic_uncollectable) - ADD_DEFINITIONS("-DGC_ATOMIC_UNCOLLECTABLE") -ENDIF(enable_atomic_uncollectable) - -OPTION(enable_gc_debug "Support for pointer back-tracing" NO) -IF(enable_gc_debug) - ADD_DEFINITIONS("-DDBG_HDRS_ALL -DKEEP_BACK_PTRS") - IF (HOST MATCHES ia64-.*-linux.*|i586-.*-linux.*|i686-.*-linux.*|x86-.*-linux.*|x86_64-.*-linux.*) - ADD_DEFINITIONS("-DMAKE_BACK_GRAPH") - ADD_DEFINITIONS("-DSAVE_CALL_COUNT=8") - SET(SRC ${SRC} backgraph.c) - ENDIF() - IF (HOST MATCHES i.86-.*-dgux.*) - ADD_DEFINITIONS("-DMAKE_BACK_GRAPH") - SET(SRC ${SRC} backgraph.c) - ENDIF() -ENDIF(enable_gc_debug) - -OPTION(enable_redirect_malloc "Redirect malloc and friends to GC routines" NO) -IF(enable_redirect_malloc) - IF(enable_gc_debug) - ADD_DEFINITIONS("-DREDIRECT_MALLOC=GC_debug_malloc_replacement") - ADD_DEFINITIONS("-DREDIRECT_REALLOC=GC_debug_realloc_replacement") - ADD_DEFINITIONS("-DREDIRECT_FREE=GC_debug_free") - ELSE(enable_gc_debug) - ADD_DEFINITIONS("-DREDIRECT_MALLOC=GC_malloc") - ENDIF(enable_gc_debug) - ADD_DEFINITIONS("-DGC_USE_DLOPEN_WRAP") -ENDIF(enable_redirect_malloc) - -OPTION(enable_mmap "Use mmap instead of sbrk to expand the heap" NO) - -OPTION(enable_munmap "Return page to the OS if empty for N collections" ON) -IF(enable_munmap) - ADD_DEFINITIONS("-DUSE_MMAP -DUSE_MUNMAP") -ELSEIF(enable_mmap) - ADD_DEFINITIONS("-DUSE_MMAP") -ENDIF() - -OPTION(enable_dynamic_loading "Enable tracing of dynamic library data roots" ON) -IF(NOT enable_dynamic_loading) - ADD_DEFINITIONS("-DIGNORE_DYNAMIC_LOADING") -ENDIF() - -OPTION(enable_register_main_static_data "Perform the initial guess of data root sets" ON) -IF(NOT enable_register_main_static_data) - ADD_DEFINITIONS("-DGC_DONT_REGISTER_MAIN_STATIC_DATA") -ENDIF() - -OPTION(enable_large_config "Optimize for large heap or root set" NO) -IF(enable_large_config) - ADD_DEFINITIONS("-DLARGE_CONFIG") -ENDIF(enable_large_config) - -OPTION(enable_gc_assertions "Enable collector-internal assertion checking" NO) -IF(enable_gc_assertions) - ADD_DEFINITIONS("-DGC_ASSERTIONS") -ENDIF(enable_gc_assertions) - -OPTION(enable_threads_discovery "Enable threads discovery in GC" ON) -IF(NOT enable_threads_discovery) - ADD_DEFINITIONS("-DGC_NO_THREADS_DISCOVERY") -ENDIF() - -OPTION(enable_checksums "Report erroneously cleared dirty bits" NO) -IF(enable_checksums) - IF(enable_munmap OR enable_threads) - MESSAGE("CHECKSUMS not compatible with USE_MUNMAP or threads") - ENDIF() - ADD_DEFINITIONS("-DCHECKSUMS") - SET(SRC ${SRC} checksums.c) -ENDIF(enable_checksums) - -ADD_LIBRARY( gc-lib STATIC ${SRC}) -SET_TARGET_PROPERTIES(gc-lib PROPERTIES - COMPILE_DEFINITIONS GC_NOT_DLL) -#TODO TARGET_LINK_LIBRARIES(... ... ${LIBS}) - -ADD_LIBRARY( gcmt-lib STATIC ${SRC}) -SET_TARGET_PROPERTIES(gcmt-lib PROPERTIES - COMPILE_DEFINITIONS GC_NOT_DLL) - -ADD_LIBRARY( gcmt-dll SHARED ${SRC}) - -IF(WIN32) - ADD_EXECUTABLE(cord cord/cordbscs.c cord/cordxtra.c - cord/tests/de.c cord/tests/de_win.c) - SET_TARGET_PROPERTIES(cord PROPERTIES WIN32_EXECUTABLE TRUE) - SET_TARGET_PROPERTIES(cord PROPERTIES - COMPILE_DEFINITIONS GC_NOT_DLL) - TARGET_LINK_LIBRARIES(cord gc-lib) - TARGET_LINK_LIBRARIES(cord gdi32) -ENDIF(WIN32) - -ADD_SUBDIRECTORY(tests) diff --git a/docs/fix/gc/tests/CMakeLists.txt b/docs/fix/gc/tests/CMakeLists.txt deleted file mode 100644 index 5e4363128..000000000 --- a/docs/fix/gc/tests/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# -# Copyright (c) 1994 by Xerox Corporation. All rights reserved. -# Copyright (c) 1996 by Silicon Graphics. All rights reserved. -# Copyright (c) 1998 by Fergus Henderson. All rights reserved. -# Copyright (c) 2000-2010 by Hewlett-Packard Company. All rights reserved. -## -# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED -# OR IMPLIED. ANY USE IS AT YOUR OWN RISK. -## -# Permission is hereby granted to use or copy this program -# for any purpose, provided the above notices are retained on all copies. -# Permission to modify the code and to distribute modified code is granted, -# provided the above notices are retained, and a notice that the code was -# modified is included with the above copyright notice. -## - -ADD_DEFINITIONS(-DGC_NOT_DLL) - -# Compile some tests as C++ to test extern "C" in header files. -SET_SOURCE_FILES_PROPERTIES( - leak_test.c - test.c - PROPERTIES LANGUAGE CXX) - -ADD_EXECUTABLE(gctest WIN32 test.c) -TARGET_LINK_LIBRARIES(gctest gc-lib "${CMAKE_THREAD_LIBS_INIT}") -ADD_TEST(NAME gctest COMMAND gctest) - -ADD_EXECUTABLE(hugetest huge_test.c) -TARGET_LINK_LIBRARIES(hugetest gc-lib "${CMAKE_THREAD_LIBS_INIT}") -ADD_TEST(NAME hugetest COMMAND hugetest) - -ADD_EXECUTABLE(leaktest leak_test.c) -TARGET_LINK_LIBRARIES(leaktest gc-lib "${CMAKE_THREAD_LIBS_INIT}") -ADD_TEST(NAME leaktest COMMAND leaktest) - -ADD_EXECUTABLE(middletest middle.c) -TARGET_LINK_LIBRARIES(middletest gc-lib "${CMAKE_THREAD_LIBS_INIT}") -ADD_TEST(NAME middletest COMMAND middletest) - -ADD_EXECUTABLE(realloc_test realloc_test.c) -TARGET_LINK_LIBRARIES(realloc_test gc-lib "${CMAKE_THREAD_LIBS_INIT}") -ADD_TEST(NAME realloc_test COMMAND realloc_test) - -ADD_EXECUTABLE(smashtest smash_test.c) -TARGET_LINK_LIBRARIES(smashtest gc-lib "${CMAKE_THREAD_LIBS_INIT}") -ADD_TEST(NAME smashtest COMMAND smashtest) diff --git a/prepare_3rdParty.bat b/prepare_3rdParty.bat index c9bd0447c..cf8ecf28d 100644 --- a/prepare_3rdParty.bat +++ b/prepare_3rdParty.bat @@ -5,6 +5,9 @@ if not "%1"=="" ( set BUILD=%1 ) +set GC_VER=8.2.8 +set LIBATOMIC_OPS_VER=7.8.2 + set p=%cd% IF EXIST ".\3rdParty\llvm\x64\%BUILD%\bin" ( @@ -13,7 +16,6 @@ IF EXIST ".\3rdParty\llvm\x64\%BUILD%\bin" ( cd %p% echo "Downloading LLVM" git submodule update --init --recursive - rem copy /Y .\docs\fix\AddCompilerRT.cmake .\3rdParty\llvm-project\compiler-rt\cmake\Modules\ echo "Configuring LLVM (%BUILD%)" cd %p% @call scripts\config_llvm_%BUILD%_%TOOL%.bat @@ -22,25 +24,20 @@ IF EXIST ".\3rdParty\llvm\x64\%BUILD%\bin" ( @call scripts\build_llvm_%BUILD%_%TOOL%.bat ) -IF EXIST ".\3rdParty\gc\x64\%BUILD%\gc-lib.lib" ( +IF EXIST ".\3rdParty\gc\x64\%BUILD%\lib\gc.lib" ( echo "No need to build GC (%BUILD%)" ) ELSE ( cd %p% echo "Downloading BDWGC" - curl -o gc-8.0.4.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz + curl -o gc-%GC_VER%.tar.gz https://www.hboehm.info/gc/gc_source/gc-%GC_VER%.tar.gz echo "Opening TAR.GZ BDWGC" - tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ + tar -xvzf gc-%GC_VER%.tar.gz -C ./3rdParty/ echo "Downloading Libatomic_ops" - curl -o libatomic_ops-7.6.10.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz + curl -o libatomic_ops-%LIBATOMIC_OPS_VER%.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-%LIBATOMIC_OPS_VER%.tar.gz echo "Opening TAR.GZ Libatomic_ops" - tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ - echo "Copy to gc-/libatomic_ops" - xcopy /E /H /C /I /Y .\3rdParty\libatomic_ops-7.6.10\ .\3rdParty\gc-8.0.4\libatomic_ops\ - echo "Copy fixes" - xcopy /E /H /C /I /Y .\docs\fix\gc\ .\3rdParty\gc-8.0.4\ + tar -xvzf libatomic_ops-%LIBATOMIC_OPS_VER%.tar.gz -C ./3rdParty/ + echo "Copy to gc-%GC_VER%/libatomic_ops" + xcopy /E /H /C /I /Y .\3rdParty\libatomic_ops-%LIBATOMIC_OPS_VER%\ .\3rdParty\gc-%GC_VER%\libatomic_ops\ cd %p% @call scripts\build_gc_%BUILD%_%TOOL%.bat - cd %p% - if "%BUILD%"=="debug" ( xcopy /E /H /C /I /Y .\__build\gc\msbuild\x64\%BUILD%\Debug\ .\3rdParty\gc\x64\debug\ ) - if "%BUILD%"=="release" ( xcopy /E /H /C /I /Y .\__build\gc\msbuild\x64\%BUILD%\Release\ .\3rdParty\gc\x64\release\ ) ) \ No newline at end of file diff --git a/prepare_3rdParty_debug.sh b/prepare_3rdParty_debug.sh index 0bb8c8664..2d3772165 100755 --- a/prepare_3rdParty_debug.sh +++ b/prepare_3rdParty_debug.sh @@ -6,12 +6,11 @@ echo "Configuring LLVM (Debug)" echo "Building LLVM (Debug)" ./scripts/build_llvm_debug.sh echo "Building GC (Debug)" -curl -o gc-8.0.4.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz -curl -o libatomic_ops-7.6.10.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz -tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ -tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ -cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/ -cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/ +curl -o gc-8.2.8.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.2.8.tar.gz +curl -o libatomic_ops-7.8.2.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.8.2.tar.gz +tar -xvzf gc-8.2.8.tar.gz -C ./3rdParty/ +tar -xvzf libatomic_ops-7.8.2.tar.gz -C ./3rdParty/ +cp -a ./3rdParty/libatomic_ops-7.8.2/ ./3rdParty/gc-8.2.8/libatomic_ops/ ./scripts/build_gc_debug.sh diff --git a/prepare_3rdParty_release.sh b/prepare_3rdParty_release.sh index 6b380e21a..5e480f083 100755 --- a/prepare_3rdParty_release.sh +++ b/prepare_3rdParty_release.sh @@ -6,12 +6,11 @@ echo "Configuring LLVM (Release)" echo "Building LLVM (Release)" ./scripts/build_llvm_release.sh echo "Building GC (Release)" -curl -o gc-8.0.4.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.0.4.tar.gz -curl -o libatomic_ops-7.6.10.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.6.10.tar.gz -tar -xvzf gc-8.0.4.tar.gz -C ./3rdParty/ -tar -xvzf libatomic_ops-7.6.10.tar.gz -C ./3rdParty/ -cp -a ./3rdParty/libatomic_ops-7.6.10/ ./3rdParty/gc-8.0.4/libatomic_ops/ -cp -ar ./docs/fix/gc/* ./3rdParty/gc-8.0.4/ +curl -o gc-8.2.8.tar.gz https://www.hboehm.info/gc/gc_source/gc-8.2.8.tar.gz +curl -o libatomic_ops-7.8.2.tar.gz https://www.hboehm.info/gc/gc_source/libatomic_ops-7.8.2.tar.gz +tar -xvzf gc-8.2.8.tar.gz -C ./3rdParty/ +tar -xvzf libatomic_ops-7.8.2.tar.gz -C ./3rdParty/ +cp -a ./3rdParty/libatomic_ops-7.8.2/ ./3rdParty/gc-8.2.8/libatomic_ops/ ./scripts/build_gc_release.sh diff --git a/scripts/build_gc_debug.sh b/scripts/build_gc_debug.sh index badd60ea9..190633be4 100755 --- a/scripts/build_gc_debug.sh +++ b/scripts/build_gc_debug.sh @@ -2,6 +2,6 @@ mkdir -p __build/gc/ninja/debug mkdir -p 3rdParty/gc/debug cd __build/gc/ninja/debug -cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/debug -Denable_threads=ON -Denable_cplusplus=OFF +cmake ../../../../3rdParty/gc-8.2.8 -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/debug -Denable_threads=ON -Denable_cplusplus=OFF cmake --build . --config Debug -j 16 -cp ./lib* ../../../../3rdParty/gc/debug/ +cmake --install . --config Debug diff --git a/scripts/build_gc_debug_ninja.bat b/scripts/build_gc_debug_ninja.bat index f62e39e29..f97fc87b2 100644 --- a/scripts/build_gc_debug_ninja.bat +++ b/scripts/build_gc_debug_ninja.bat @@ -1,6 +1,7 @@ pushd mkdir __build\gc\ninja\debug cd __build\gc\ninja\debug -cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/debug -Denable_threads=ON -Denable_cplusplus=OFF +cmake ../../../../3rdParty/gc-8.2.8 -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/debug -Denable_threads=ON -Denable_cplusplus=OFF cmake --build . --config Debug -j 8 +cmake --install . --config Debug popd \ No newline at end of file diff --git a/scripts/build_gc_debug_vs.bat b/scripts/build_gc_debug_vs.bat index a40805df8..494c6bfbc 100644 --- a/scripts/build_gc_debug_vs.bat +++ b/scripts/build_gc_debug_vs.bat @@ -1,7 +1,7 @@ pushd mkdir __build\gc\msbuild\x64\debug cd __build\gc\msbuild\x64\debug -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ../../../../../3rdParty/gc-8.0.4 -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DCMAKE_BUILD_TYPE=Debug -Wno-dev -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/gc/x64/debug -Denable_threads=ON -Denable_cplusplus=OFF -cmake --build . --config Debug -j 8 +cmake ../../../../../3rdParty/gc-8.2.8 -G "Visual Studio 18 2026" -A x64 %EXTRA_PARAM% -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -Wno-dev -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/gc/x64/debug -Denable_threads=ON -Denable_cplusplus=OFF -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug +cmake --build . --config Debug -j 20 +cmake --install . --config Debug popd \ No newline at end of file diff --git a/scripts/build_gc_release.sh b/scripts/build_gc_release.sh index 3430c2b38..450fe04c6 100755 --- a/scripts/build_gc_release.sh +++ b/scripts/build_gc_release.sh @@ -2,6 +2,6 @@ mkdir -p __build/gc/ninja/release mkdir -p 3rdParty/gc/release cd __build/gc/ninja/release -cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF +cmake ../../../../3rdParty/gc-8.2.8 -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF cmake --build . --config Release -j 16 -cp ./lib* ../../../../3rdParty/gc/release/ \ No newline at end of file +cmake --install . --config Release diff --git a/scripts/build_gc_release_ninja.bat b/scripts/build_gc_release_ninja.bat index b441b36c7..5dabb840d 100644 --- a/scripts/build_gc_release_ninja.bat +++ b/scripts/build_gc_release_ninja.bat @@ -1,7 +1,7 @@ pushd mkdir __build\gc\ninja\release cd __build\gc\ninja\release -cmake ../../../../3rdParty/gc-8.0.4 -G "Ninja" -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF +cmake ../../../../3rdParty/gc-8.2.8 -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -Wno-dev -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=../../../../3rdParty/gc/release -Denable_threads=ON -Denable_cplusplus=OFF cmake --build . --config Release -j 8 cmake --install . --config Release popd \ No newline at end of file diff --git a/scripts/build_gc_release_vs.bat b/scripts/build_gc_release_vs.bat index 1cebaa89c..ba57a2fb4 100644 --- a/scripts/build_gc_release_vs.bat +++ b/scripts/build_gc_release_vs.bat @@ -1,8 +1,7 @@ pushd mkdir __build\gc\msbuild\x64\release cd __build\gc\msbuild\x64\release -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ../../../../../3rdParty/gc-8.0.4 -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/gc/x64/release -Denable_threads=ON -Denable_cplusplus=OFF +cmake ../../../../../3rdParty/gc-8.2.8 -G "Visual Studio 18 2026" -A x64 %EXTRA_PARAM% -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -Wno-dev -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/gc/x64/release -Denable_threads=ON -Denable_cplusplus=OFF -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded cmake --build . --config Release -j 8 cmake --install . --config Release popd \ No newline at end of file diff --git a/scripts/build_llvm_debug_vs.bat b/scripts/build_llvm_debug_vs.bat index aca3dd719..b5d70113e 100644 --- a/scripts/build_llvm_debug_vs.bat +++ b/scripts/build_llvm_debug_vs.bat @@ -1,5 +1,5 @@ pushd cd __build\llvm\msbuild\x64\debug -cmake --build . --config Debug --target install +cmake --build . --config Debug --target install -j 20 cmake --install . --config Debug popd \ No newline at end of file diff --git a/scripts/build_llvm_release_vs.bat b/scripts/build_llvm_release_vs.bat index 24d135850..805069f94 100644 --- a/scripts/build_llvm_release_vs.bat +++ b/scripts/build_llvm_release_vs.bat @@ -1,5 +1,5 @@ pushd cd __build\llvm\msbuild\x64\release -cmake --build . --config Release --target install -j 8 +cmake --build . --config Release --target install -j 20 cmake --install . --config Release popd \ No newline at end of file diff --git a/scripts/config_llvm_debug_vs.bat b/scripts/config_llvm_debug_vs.bat index 1822cff2c..1496236d6 100644 --- a/scripts/config_llvm_debug_vs.bat +++ b/scripts/config_llvm_debug_vs.bat @@ -1,7 +1,10 @@ pushd +rem capture repo root (cwd at script start) so the install prefix is absolute. +rem a relative CMAKE_INSTALL_PREFIX is resolved to an empty path by 'cmake --install' +rem and installs LLVM to the drive root (e.g. I:\bin, I:\lib) instead of 3rdParty. +set "LLVM_INSTALL_ROOT=%CD%" mkdir __build\llvm\msbuild\x64\debug cd __build\llvm\msbuild\x64\debug -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON -Wno-dev +cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 18 2026" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug -Thost=x64 -DCMAKE_INSTALL_PREFIX="%LLVM_INSTALL_ROOT%\3rdParty\llvm\x64\debug" -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON -Wno-dev popd diff --git a/scripts/config_llvm_debug_vs_clangcl.bat b/scripts/config_llvm_debug_vs_clangcl.bat index 307f1e5a4..3ae3d8c22 100644 --- a/scripts/config_llvm_debug_vs_clangcl.bat +++ b/scripts/config_llvm_debug_vs_clangcl.bat @@ -1,7 +1,6 @@ pushd mkdir __build\llvm\msbuild\x64\debug cd __build\llvm\msbuild\x64\debug -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="ClangCL" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON +cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 18 2026" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="ClangCL" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON popd diff --git a/scripts/config_llvm_debug_vs_intel.bat b/scripts/config_llvm_debug_vs_intel.bat index ce8266d71..4c838aa51 100644 --- a/scripts/config_llvm_debug_vs_intel.bat +++ b/scripts/config_llvm_debug_vs_intel.bat @@ -1,7 +1,6 @@ pushd mkdir __build\llvm\msbuild\x64\debug cd __build\llvm\msbuild\x64\debug -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="Intel C++ Compiler 2024" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON +cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 18 2026" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -T="Intel C++ Compiler 2024" -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON popd diff --git a/scripts/config_llvm_release_vs.bat b/scripts/config_llvm_release_vs.bat index 9bf1bf728..9e8820fe7 100644 --- a/scripts/config_llvm_release_vs.bat +++ b/scripts/config_llvm_release_vs.bat @@ -1,6 +1,9 @@ pushd +rem capture repo root (cwd at script start) so the install prefix is absolute. +rem a relative CMAKE_INSTALL_PREFIX is resolved to an empty path by 'cmake --install' +rem and installs LLVM to the drive root (e.g. I:\bin, I:\lib) instead of 3rdParty. +set "LLVM_INSTALL_ROOT=%CD%" mkdir __build\llvm\msbuild\x64\release cd __build\llvm\msbuild\x64\release -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/x64/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON +cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 18 2026" -A x64 %EXTRA_PARAM% -DLLVM_TARGETS_TO_BUILD="host;ARM;AArch64" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -Thost=x64 -DCMAKE_INSTALL_PREFIX="%LLVM_INSTALL_ROOT%\3rdParty\llvm\x64\release" -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON popd diff --git a/scripts/config_llvm_wasm_debug.bat b/scripts/config_llvm_wasm_debug.bat index 9fb1547b2..85b28b955 100644 --- a/scripts/config_llvm_wasm_debug.bat +++ b/scripts/config_llvm_wasm_debug.bat @@ -1,7 +1,6 @@ pushd mkdir __build\llvm\msbuild\wasm\debug cd __build\llvm\msbuild\wasm\debug -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -emcmake cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON +emcmake cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 18 2026" -A x64 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Debug -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/debug -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON popd diff --git a/scripts/config_llvm_wasm_release.bat b/scripts/config_llvm_wasm_release.bat index 761e72a74..493529394 100644 --- a/scripts/config_llvm_wasm_release.bat +++ b/scripts/config_llvm_wasm_release.bat @@ -1,7 +1,6 @@ pushd mkdir __build\llvm\msbuild\wasm\release cd __build\llvm\msbuild\wasm\release -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -emcmake cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 17 2022" -A x64 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON +emcmake cmake ..\..\..\..\..\3rdParty\llvm-project\llvm -G "Visual Studio 18 2026" -A x64 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" -DCMAKE_BUILD_TYPE=Release -Thost=x64 -DCMAKE_INSTALL_PREFIX=../../../../../3rdParty/llvm/wasm/release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PLUGINS=ON -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_REQUIRES_RTTI=ON -DLLVM_ENABLE_PIC=ON popd diff --git a/tsc/CMakeLists.txt b/tsc/CMakeLists.txt index de0e16d7c..f2f9fbebf 100644 --- a/tsc/CMakeLists.txt +++ b/tsc/CMakeLists.txt @@ -45,7 +45,7 @@ set(CMAKE_BUILD_TYPE "Debug") endif() if ("${MLIR_DIR}" STREQUAL "" OR "${MLIR_DIR}" STREQUAL "MLIR_DIR-NOTFOUND") - if (MSVC) + if (MSVC OR WIN32) #file(REAL_PATH "${CMAKE_SOURCE_DIR}/../3rdParty/llvm/${CMAKE_BUILD_TYPE}/lib/cmake/mlir" MLIR_DIR) get_filename_component(MLIR_DIR "${CMAKE_SOURCE_DIR}/../3rdParty/llvm/x64/${CMAKE_BUILD_TYPE}/lib/cmake/mlir" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") else() @@ -57,7 +57,7 @@ endif() message(STATUS "MLIR_DIR is ${MLIR_DIR}") if ("${Clang_DIR}" STREQUAL "" OR "${Clang_DIR}" STREQUAL "Clang_DIR-NOTFOUND") - if (MSVC) + if (MSVC OR WIN32) #file(REAL_PATH "${CMAKE_SOURCE_DIR}/../3rdParty/llvm/${CMAKE_BUILD_TYPE}/lib/cmake/clang" Clang_DIR) get_filename_component(Clang_DIR "${CMAKE_SOURCE_DIR}/../3rdParty/llvm/x64/${CMAKE_BUILD_TYPE}/lib/cmake/clang" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") else() @@ -68,11 +68,21 @@ if ("${Clang_DIR}" STREQUAL "" OR "${Clang_DIR}" STREQUAL "Clang_DIR-NOTFOUND") endif() message(STATUS "Clang_DIR is ${Clang_DIR}") +if ("${BDWgc_DIR}" STREQUAL "" OR "${BDWgc_DIR}" STREQUAL "BDWgc_DIR-NOTFOUND") + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE) + if (MSVC OR WIN32) + get_filename_component(BDWgc_DIR "${CMAKE_SOURCE_DIR}/../3rdParty/gc/x64/${CMAKE_BUILD_TYPE_LOWERCASE}/lib/cmake/bdwgc" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + else() + get_filename_component(BDWgc_DIR "${CMAKE_SOURCE_DIR}/../3rdParty/gc/${CMAKE_BUILD_TYPE_LOWERCASE}/lib/cmake/bdwgc" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif() +endif() +message(STATUS "BDWgc_DIR is ${BDWgc_DIR}") + if ("${PYTHON_EXECUTABLE}" STREQUAL "" OR "${PYTHON_EXECUTABLE}" STREQUAL "PYTHON_EXECUTABLE-NOTFOUND") set(PYTHON_EXECUTABLE "python.exe") endif() -message(STATUS "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE was ${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE} and set to x64") +message(STATUS "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE was [${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}], set to x64") set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64") find_package(MLIR REQUIRED CONFIG) @@ -85,6 +95,13 @@ if (NOT Clang_FOUND) message(FATAL_ERROR "Failed to find Clang") endif() +# bdwgc ships a CMake package (BDWgc::gc / BDWgc::cord imported targets) that +# carries the include dir and the per-config static lib location. +find_package(BDWgc REQUIRED CONFIG) +if (NOT BDWgc_FOUND) + message(FATAL_ERROR "Failed to find BDWgc (garbage collector)") +endif() + message(STATUS "Using MLIRConfig.cmake in: ${MLIR_CMAKE_DIR}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_CMAKE_DIR}") message(STATUS "Using ClangConfig.cmake in: ${CLANG_CMAKE_DIR}") @@ -101,6 +118,23 @@ set(LLVM_ENABLE_PIC "ON") # clang fix set(CMAKE_BUILD_WITH_INSTALL_RPATH "ON") +if(MSVC) + # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214. + # Use the static CRT (/MT, /MTd) to match the prebuilt static LLVM/MLIR libs. + # Use a generator expression so it is correct for multi-config generators + # (e.g. Visual Studio), where CMAKE_BUILD_TYPE is not meaningful at configure time. + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + + # HandleLLVMOptions (included below) otherwise forces the dynamic CRT default and + # would override CMAKE_MSVC_RUNTIME_LIBRARY. These tell it to select the static CRT + # for every configuration so all targets (including unittests/gtest) match. + set(LLVM_USE_CRT_DEBUG MTd) + set(LLVM_USE_CRT_RELEASE MT) + set(LLVM_USE_CRT_RELWITHDEBINFO MT) + set(LLVM_USE_CRT_MINSIZEREL MT) + + message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY is ${CMAKE_MSVC_RUNTIME_LIBRARY}") +endif() list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") diff --git a/tsc/CMakePresets.json b/tsc/CMakePresets.json index c47310284..9a53fafbf 100644 --- a/tsc/CMakePresets.json +++ b/tsc/CMakePresets.json @@ -21,9 +21,6 @@ "name": "windows-msbuild", "hidden": true, "inherits": "default", - "generator": "Visual Studio 17 2022", - "displayName": "Visual Studio Professional 2022 - x86_amd64", - "description": "Using compilers for Visual Studio 17 2022 (x86_x64 architecture)", "toolset": "host=x64", "architecture": "x64", "cacheVariables": { @@ -44,23 +41,133 @@ } }, { - "name": "windows-msbuild-debug", + "name": "windows-msbuild-2022", + "hidden": true, + "inherits": "windows-msbuild", + "generator": "Visual Studio 17 2022", + "displayName": "Visual Studio Professional 2022 - x86_amd64", + "description": "Using compilers for Visual Studio 17 2022 (x86_x64 architecture)" + }, + { + "name": "windows-msbuild-2022-debug", "displayName": "Visual Studio Professional 2022 - x86_amd64 - Debug", "description": "Using compilers for Visual Studio 17 2022 (x86_x64 architecture)", - "inherits": "windows-msbuild", + "inherits": "windows-msbuild-2022", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } }, { - "name": "windows-msbuild-release", + "name": "windows-msbuild-2022-release", "displayName": "Visual Studio Professional 2022 - x86_amd64 - Release", "description": "Using compilers for Visual Studio 17 2022 (x86_x64 architecture)", + "inherits": "windows-msbuild-2022", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "windows-msbuild-2026", + "hidden": true, "inherits": "windows-msbuild", + "generator": "Visual Studio 18 2026", + "displayName": "Visual Studio Professional 2026 - x86_amd64", + "description": "Using compilers for Visual Studio 18 2026 (x86_x64 architecture)" + }, + { + "name": "windows-msbuild-2026-debug", + "displayName": "Visual Studio Professional 2026 - x86_amd64 - Debug", + "description": "Using compilers for Visual Studio 18 2026 (x86_x64 architecture)", + "inherits": "windows-msbuild-2026", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "windows-msbuild-2026-release", + "displayName": "Visual Studio Professional 2026 - x86_amd64 - Release", + "description": "Using compilers for Visual Studio 18 2026 (x86_x64 architecture)", + "inherits": "windows-msbuild-2026", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } }, + { + "name": "windows-ninja", + "hidden": true, + "inherits": "default", + "generator": "Ninja Multi-Config", + "displayName": "Ninja Multi-Config", + "description": "Clang++ (current) x86_64-pc-windows-msvc", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "1" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "windows-ninja-debug", + "hidden": true, + "inherits": "windows-ninja", + "displayName": "Ninja Multi-Config - Debug", + "description": "Ninja Multi-Config - Debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "windows-ninja-release", + "hidden": true, + "inherits": "windows-ninja", + "displayName": "Ninja Multi-Config - Release", + "description": "Ninja Multi-Config - Release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "windows-ninja-clangcl-debug", + "inherits": "windows-ninja-debug", + "displayName": "ClangCL (current) Debug", + "description": "Using compilers: C = clang-cl, CXX = clang-cl", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + } + }, + { + "name": "windows-ninja-clangcl-release", + "inherits": "windows-ninja-release", + "displayName": "ClangCL (current) Release", + "description": "Using compilers: C = clang-cl, CXX = clang-cl", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + } + }, + { + "name": "windows-ninja-clang-debug", + "inherits": "windows-ninja-debug", + "displayName": "Clang (current) Debug", + "description": "Using compilers: C = clang, CXX = clang++", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "windows-ninja-clang-release", + "inherits": "windows-ninja-release", + "displayName": "Clang (current) Release", + "description": "Using compilers: C = clang, CXX = clang++", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, { "name": "linux-ninja", "hidden": true, @@ -138,15 +245,27 @@ ], "buildPresets": [ { - "name": "build-windows-msbuild-debug", + "name": "build-windows-msbuild-2022-debug", "displayName": "Visual Studio Professional 2022 - x86_amd64 - Debug", - "configurePreset": "windows-msbuild-debug", + "configurePreset": "windows-msbuild-2022-debug", "configuration": "Debug" }, { - "name": "build-windows-msbuild-release", + "name": "build-windows-msbuild-2022-release", "displayName": "Visual Studio Professional 2022 - x86_amd64 - Release", - "configurePreset": "windows-msbuild-release", + "configurePreset": "windows-msbuild-2022-release", + "configuration": "Release" + }, + { + "name": "build-windows-msbuild-2026-debug", + "displayName": "Visual Studio Professional 2026 - x86_amd64 - Debug", + "configurePreset": "windows-msbuild-2026-debug", + "configuration": "Debug" + }, + { + "name": "build-windows-msbuild-2026-release", + "displayName": "Visual Studio Professional 2026 - x86_amd64 - Release", + "configurePreset": "windows-msbuild-2026-release", "configuration": "Release" }, { @@ -200,14 +319,26 @@ } }, { - "name": "test-windows-msbuild-debug", - "configurePreset": "windows-msbuild-debug", + "name": "test-windows-msbuild-2022-debug", + "configurePreset": "windows-msbuild-2022-debug", + "configuration": "Debug", + "inherits": "test-default" + }, + { + "name": "test-windows-msbuild-2022-release", + "configurePreset": "windows-msbuild-2022-release", + "configuration": "Release", + "inherits": "test-default" + }, + { + "name": "test-windows-msbuild-2026-debug", + "configurePreset": "windows-msbuild-2026-debug", "configuration": "Debug", "inherits": "test-default" }, { - "name": "test-windows-msbuild-release", - "configurePreset": "windows-msbuild-release", + "name": "test-windows-msbuild-2026-release", + "configurePreset": "windows-msbuild-2026-release", "configuration": "Release", "inherits": "test-default" }, diff --git a/tsc/build_tsc_debug-test.bat b/tsc/build_tsc_debug-test.bat index c0c085685..462b1735f 100644 --- a/tsc/build_tsc_debug-test.bat +++ b/tsc/build_tsc_debug-test.bat @@ -1,5 +1,5 @@ pushd -cd ../__build/tsc/windows-msbuild-debug +cd ../__build/tsc/msbuild/x64/debug set CTEST_OUTPUT_ON_FAILURE=TRUE set CTEST_PARALLEL_LEVEL=16 cmake --build . --target RUN_TESTS --config Debug --parallel diff --git a/tsc/build_tsc_debug-test.sh b/tsc/build_tsc_debug-test.sh new file mode 100755 index 000000000..1a51b3208 --- /dev/null +++ b/tsc/build_tsc_debug-test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd ../__build/tsc/ninja/debug +ctest -j18 -C Debug -T test --output-on-failure -T test --output-on-failure \ No newline at end of file diff --git a/tsc/build_tsc_debug.sh b/tsc/build_tsc_debug.sh old mode 100644 new mode 100755 diff --git a/tsc/build_tsc_defaultlib_debug.bat b/tsc/build_tsc_defaultlib_debug.bat index 528beff83..594d982d3 100644 --- a/tsc/build_tsc_defaultlib_debug.bat +++ b/tsc/build_tsc_defaultlib_debug.bat @@ -2,8 +2,8 @@ pushd cd ../../TypeScriptCompilerDefaultLib/ call build.bat -xcopy dll\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-debug/bin/defaultlib/dll/" /i /y -xcopy lib\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-debug/bin/defaultlib/lib/" /i /y -xcopy src\*.d.ts "../TypeScriptCompiler/__build/tsc/windows-msbuild-debug/bin/defaultlib/" /i /y +xcopy dll\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-2026-debug/bin/defaultlib/dll/" /i /y +xcopy lib\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-2026-debug/bin/defaultlib/lib/" /i /y +xcopy src\*.d.ts "../TypeScriptCompiler/__build/tsc/windows-msbuild-2026-debug/bin/defaultlib/" /i /y popd diff --git a/tsc/build_tsc_defaultlib_release.bat b/tsc/build_tsc_defaultlib_release.bat new file mode 100644 index 000000000..7e93297fb --- /dev/null +++ b/tsc/build_tsc_defaultlib_release.bat @@ -0,0 +1,9 @@ +pushd +cd ../../TypeScriptCompilerDefaultLib/ +call build.bat + +xcopy dll\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-2026-release/bin/defaultlib/dll/" /i /y +xcopy lib\*.* "../TypeScriptCompiler/__build/tsc/windows-msbuild-2026-release/bin/defaultlib/lib/" /i /y +xcopy src\*.d.ts "../TypeScriptCompiler/__build/tsc/windows-msbuild-2026-release/bin/defaultlib/" /i /y + +popd diff --git a/tsc/build_tsc_release-test.sh b/tsc/build_tsc_release-test.sh old mode 100644 new mode 100755 diff --git a/tsc/build_tsc_release.sh b/tsc/build_tsc_release.sh old mode 100644 new mode 100755 diff --git a/tsc/config_tsc_debug.bat b/tsc/config_tsc_debug.bat index 099ad0214..59e754fc6 100644 --- a/tsc/config_tsc_debug.bat +++ b/tsc/config_tsc_debug.bat @@ -1,6 +1,5 @@ pushd mkdir "../__build/tsc/msbuild/x64/debug" cd "../__build/tsc/msbuild/x64/debug" -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ../../../../../tsc -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Debug -DTSC_PACKAGE_VERSION:STRING=1.2.3 -DTYPESCRIPT_INCLUDE_TESTS=any -Wno-dev %EXTRA_PARAM% +cmake ../../../../../tsc -G "Visual Studio 18 2026" -A x64 -DCMAKE_BUILD_TYPE=Debug -DTSC_PACKAGE_VERSION:STRING=1.2.3 -DTYPESCRIPT_INCLUDE_TESTS=any -Wno-dev %EXTRA_PARAM% popd diff --git a/tsc/config_tsc_debug.sh b/tsc/config_tsc_debug.sh old mode 100644 new mode 100755 diff --git a/tsc/config_tsc_release.bat b/tsc/config_tsc_release.bat index 774034e7d..936b422b3 100644 --- a/tsc/config_tsc_release.bat +++ b/tsc/config_tsc_release.bat @@ -1,6 +1,5 @@ pushd mkdir "../__build/tsc/msbuild/x64/release" cd "../__build/tsc/msbuild/x64/release" -if exist "C:/Program Files/Microsoft Visual Studio/2022/Professional" set EXTRA_PARAM=-DCMAKE_GENERATOR_INSTANCE="C:/Program Files/Microsoft Visual Studio/2022/Professional" -cmake ../../../../../tsc -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev %EXTRA_PARAM% +cmake ../../../../../tsc -G "Visual Studio 18 2026" -A x64 -DCMAKE_BUILD_TYPE=Release -Wno-dev %EXTRA_PARAM% popd diff --git a/tsc/config_tsc_release.sh b/tsc/config_tsc_release.sh old mode 100644 new mode 100755 diff --git a/tsc/include/TypeScript/Config.h b/tsc/include/TypeScript/Config.h index 111341730..978c62c21 100644 --- a/tsc/include/TypeScript/Config.h +++ b/tsc/include/TypeScript/Config.h @@ -5,6 +5,12 @@ #pragma warning(disable : 4062) #pragma warning(disable : 4834) #pragma warning(disable : 4996) + +// CRT debug +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC +#endif // _DEBUG + #endif //#define GC_ENABLE 1 diff --git a/tsc/include/TypeScript/LowerToLLVM/LLVMCodeHelper.h b/tsc/include/TypeScript/LowerToLLVM/LLVMCodeHelper.h index cf02798db..ca1f03c36 100644 --- a/tsc/include/TypeScript/LowerToLLVM/LLVMCodeHelper.h +++ b/tsc/include/TypeScript/LowerToLLVM/LLVMCodeHelper.h @@ -240,6 +240,14 @@ class LLVMCodeHelper : public LLVMCodeHelperBase // TODO: finish it auto newFuncOp = rewriter.create( location, name, mlir::FunctionType::get(rewriter.getContext(), llvm::ArrayRef(), llvm::ArrayRef())); + // the per-symbol "__cctor" is only ever called from this module's own global ctors / __mlir_gctors. + // keep it internal so it is not exported - otherwise an executable and a shared lib that both + // define e.g. "A.Origin__cctor" interpose each other (ELF gives the executable's copy priority), + // and the shared lib's __mlir_gctors ends up calling the executable's cctor, leaving the shared + // lib's globals uninitialized (null deref at runtime in -shared/-gctors-as-method builds). + newFuncOp.setPrivate(); + newFuncOp->setAttr("llvm.linkage", + LLVM::LinkageAttr::get(rewriter.getContext(), LLVM::Linkage::Internal)); if (!initRegion.empty()) { OpBuilder::InsertionGuard insertGuard(rewriter); diff --git a/tsc/include/TypeScript/MLIRLogic/MLIRCodeLogic.h b/tsc/include/TypeScript/MLIRLogic/MLIRCodeLogic.h index d7ff1aa50..8410ba1d1 100644 --- a/tsc/include/TypeScript/MLIRLogic/MLIRCodeLogic.h +++ b/tsc/include/TypeScript/MLIRLogic/MLIRCodeLogic.h @@ -367,17 +367,17 @@ class MLIRCustomMethods { static std::map m { {"print", true}, {"convertf", true}, {"assert", true}, {"parseInt", true}, {"parseFloat", true}, {"isNaN", true}, {"sizeof", true}, {GENERATOR_SWITCHSTATE, true}, - {"LoadLibraryPermanently", true}, { "SearchForAddressOfSymbol", true }, { "LoadReference", true }, { "ReferenceOf", true }, + {"LoadLibraryPermanently", true}, { "SearchForAddressOfSymbol", true }, { "LoadReference", true }, { "ReferenceOf", true }, { "Deref", true }, { "Ref", true }, {"atomicrmw", true}, {"cmpxchg", true}, {"fence", true}, {"inline_asm", true}, {"call_intrinsic", true}, {"linker_options", true} }; - return m[functionName.str()]; - } + return m[functionName.str()]; + } static bool isInternalFunctionNameNoBuiltin (StringRef functionName) { - static std::map m { - {"print", true}, {"convertf", true}, {"assert", true}, {"sizeof", true}, {GENERATOR_SWITCHSTATE, true}, - {"LoadLibraryPermanently", true}, { "SearchForAddressOfSymbol", true }, { "LoadReference", true }, { "ReferenceOf", true }, + static std::map m { + {"print", true}, {"convertf", true}, {"assert", true}, {"sizeof", true}, {GENERATOR_SWITCHSTATE, true}, + {"LoadLibraryPermanently", true}, { "SearchForAddressOfSymbol", true }, { "LoadReference", true }, { "ReferenceOf", true }, { "Deref", true }, { "Ref", true }, {"atomicrmw", true}, {"cmpxchg", true}, {"fence", true}, {"inline_asm", true}, {"call_intrinsic", true}, {"linker_options", true} }; return m[functionName.str()]; @@ -454,11 +454,11 @@ class MLIRCustomMethods { return mlirGenSearchForAddressOfSymbol(location, operands, castFn, genContext); } - else if (functionName == "LoadReference") + else if (functionName == "LoadReference" || functionName == "Deref") { return mlirGenLoadReference(location, operands, castFn, genContext); } - else if (functionName == "ReferenceOf") + else if (functionName == "ReferenceOf" || functionName == "Ref") { return mlirGenReferenceOf(location, operands); } diff --git a/tsc/include/TypeScript/VSCodeTemplate/Files.h b/tsc/include/TypeScript/VSCodeTemplate/Files.h index 3c710a2dc..f35df0930 100644 --- a/tsc/include/TypeScript/VSCodeTemplate/Files.h +++ b/tsc/include/TypeScript/VSCodeTemplate/Files.h @@ -57,10 +57,15 @@ declare type float = any; declare type double = any; declare type Opaque = any; -type Reference = any +type Ref = any +type Reference = Ref // deprecated alias of Ref -declare function ReferenceOf(r: T): Reference; -declare function LoadReference(r: Reference): T; +declare function Ref(r: T): Ref; +declare function Deref(r: Ref): T; + +// deprecated aliases of Ref / Deref +declare function ReferenceOf(r: T): Ref; +declare function LoadReference(r: Ref): T; declare function sizeof(v?: T): index; )raw"; diff --git a/tsc/include/TypeScript/gcwrapper.h b/tsc/include/TypeScript/gcwrapper.h index 2c73a93ac..3759a48b3 100644 --- a/tsc/include/TypeScript/gcwrapper.h +++ b/tsc/include/TypeScript/gcwrapper.h @@ -1,6 +1,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + void _mlir__GC_init(); void *_mlir__GC_malloc(size_t size); @@ -20,3 +24,7 @@ void _mlir__GC_win32_free_heap(); void *_mlir__GC_malloc_explicitly_typed(size_t size, int64_t descr); int64_t _mlir__GC_make_descriptor(const int64_t *descr, size_t size); + +#ifdef __cplusplus +} +#endif diff --git a/tsc/lib/TypeScript/LowerToLLVM.cpp b/tsc/lib/TypeScript/LowerToLLVM.cpp index 3bda408fe..d163efa93 100644 --- a/tsc/lib/TypeScript/LowerToLLVM.cpp +++ b/tsc/lib/TypeScript/LowerToLLVM.cpp @@ -6167,6 +6167,7 @@ static LogicalResult preserveTypesForDebugInfo(mlir::ModuleOp &module, LLVMTypeC mlir::Type dataType; auto argIndex = 0; auto isGlobal = false; + auto isGlobalDefined = true; mlir::StringAttr linkageNameAttr; if (auto variableOp = dyn_cast(op)) { @@ -6183,6 +6184,22 @@ static LogicalResult preserveTypesForDebugInfo(mlir::ModuleOp &module, LLVMTypeC dataType = globalOp.getType(); linkageNameAttr = globalOp.getSymNameAttr(); isGlobal = true; + // an external declaration (no initializer value and empty initializer region) is not + // defined here - marking it as defined makes the debug info emit a dangling address + // relocation to a symbol that never gets emitted (e.g. static members of a class + // expression used only as a default-parameter type). + auto &initRegion = globalOp.getInitializerRegion(); + isGlobalDefined = globalOp.getValueAttr() != nullptr || + (!initRegion.empty() && !initRegion.front().empty()); + + // skip debug info for external declarations - attaching a global-variable + // expression to a declaration global makes LLVM emit a DW_OP_addr relocation to + // a symbol that never gets defined (link error). This happens for static members + // of a class expression used only as a default-parameter type. + if (!isGlobalDefined) + { + continue; + } } // TODO: finish the DI logic @@ -6203,8 +6220,8 @@ static LogicalResult preserveTypesForDebugInfo(mlir::ModuleOp &module, LLVMTypeC { // recreate globalVar later to set correct LinkageAttr and isDefined auto varInfo = LLVM::DIGlobalVariableAttr::get( - location.getContext(), scope, name, linkageNameAttr, - file, line, diType, false, true, alignInBits); + location.getContext(), scope, name, linkageNameAttr, + file, line, diType, false, isGlobalDefined, alignInBits); op->setLoc(mlir::FusedLoc::get(location.getContext(), {location}, varInfo)); } else diff --git a/tsc/lib/TypeScript/MLIRGen.cpp b/tsc/lib/TypeScript/MLIRGen.cpp index 34fe5759c..7f5caeb52 100644 --- a/tsc/lib/TypeScript/MLIRGen.cpp +++ b/tsc/lib/TypeScript/MLIRGen.cpp @@ -1075,9 +1075,17 @@ class MLIRGenImpl builder.setInsertionPointToStart(parentModule.getBody()); mclh.seekLastOp(parentModule.getBody()); - // priority is lowest to load as first dependencies + // The shared-lib load + symbol resolution call into LLVM's + // sys::DynamicLibrary, which uses std::vector. In debug builds STL + // iterators take a global lock that the CRT only initializes via its + // own '_Init_locks'/'initlocks' dynamic initializer (in .CRT$XCU). + // FIRST_GLOBAL_CONSTRUCTOR_PRIORITY (100) places this ctor BEFORE that + // CRT init -> entering an uninitialized CRITICAL_SECTION -> crash. + // Use the same band as the per-symbol __cctors (LAST) so it runs after + // 'initlocks'; it is emitted before them, so it still loads the library + // before any LLVMSearchForAddressOfSymbol runs. builder.create( - location, mlir::FlatSymbolRefAttr::get(builder.getContext(), fullInitGlobalFuncName), builder.getIndexAttr(FIRST_GLOBAL_CONSTRUCTOR_PRIORITY)); + location, mlir::FlatSymbolRefAttr::get(builder.getContext(), fullInitGlobalFuncName), builder.getIndexAttr(LAST_GLOBAL_CONSTRUCTOR_PRIORITY)); } for (auto declSymbol : symbols) @@ -22593,19 +22601,30 @@ genContext); for (auto [index, typeParam] : enumerate(typeParams)) { auto isDefault = false; - auto type = index < argsCount - ? getType(typeArgs[index], genContext) - : (isDefault = true, typeParam->hasDefault() - ? getType(typeParam->getDefault(), genContext) - : typeParam->hasConstraint() - ? getType(typeParam->getConstraint(), genContext) - : mlir::Type()); + mlir::Type type; + if (index < argsCount) + { + type = getType(typeArgs[index], genContext); + } + else + { + isDefault = true; + if (typeParam->hasDefault()) + { + type = getType(typeParam->getDefault(), genContext); + } + else if (typeParam->hasConstraint()) + { + type = getType(typeParam->getConstraint(), genContext); + } + } + if (!type) { if (isDefault && !typeParam->hasDefault() && argsCount == 0) { // seems creating instance without TypeParams, can be used instance with the same name - // scuh as Point and Point + // such as Point and Point return {mlir::failure(), IsGeneric::NoDefaults}; } @@ -23025,6 +23044,7 @@ genContext); {"TypeOf", true }, {"Opaque", true }, // to support void* {"Reference", true }, // to support dll import + {"Ref", true }, // alias of Reference {"Readonly", true }, {"Partial", true }, {"Required", true }, @@ -23112,6 +23132,7 @@ genContext); {"TypeOf", true }, {"Opaque", true }, // to support void* {"Reference", true }, // to support dll import + {"Ref", true }, // alias of Reference {"ThisType", true }, //{"Array", true } }; @@ -23274,7 +23295,7 @@ genContext); type = mth.wideStorageType(type); return type; }) - .Case("Reference", [&] (auto typeArguments, auto genContext) { + .Cases("Reference", "Ref", [&] (auto typeArguments, auto genContext) { auto type = getFirstTypeFromTypeArguments(typeArguments, genContext); if (!type) { @@ -23423,7 +23444,7 @@ genContext); type = mth.wideStorageType(type); return type; }) - .Case("Reference", [&] (auto typeArguments, auto genContext) { + .Cases("Reference", "Ref", [&] (auto typeArguments, auto genContext) { auto type = getFirstTypeFromTypeArguments(typeArguments, genContext); return mlir_ts::RefType::get(type); }) diff --git a/tsc/lib/TypeScriptRuntime/CMakeLists.txt b/tsc/lib/TypeScriptRuntime/CMakeLists.txt index 8b1ce8dd1..858ccbeee 100644 --- a/tsc/lib/TypeScriptRuntime/CMakeLists.txt +++ b/tsc/lib/TypeScriptRuntime/CMakeLists.txt @@ -1,15 +1,8 @@ -include_directories("${PROJECT_SOURCE_DIR}/../3rdParty/gc-8.0.4/include/") - -string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE) +# Include dir + lib location come from the BDWgc::gc imported target (find_package +# in the top-level CMakeLists), so no hardcoded include_directories/link_directories. if(MSVC) - message(STATUS "Using GC Lib: ${PROJECT_SOURCE_DIR}/../3rdParty/gc/x64/${CMAKE_BUILD_TYPE_LOWERCASE}/") - - link_directories("${PROJECT_SOURCE_DIR}/../3rdParty/gc/x64/${CMAKE_BUILD_TYPE_LOWERCASE}/") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR") else() - message(STATUS "Using GC Lib: ${PROJECT_SOURCE_DIR}/../3rdParty/gc/${CMAKE_BUILD_TYPE_LOWERCASE}/") - - link_directories("${PROJECT_SOURCE_DIR}/../3rdParty/gc/${CMAKE_BUILD_TYPE_LOWERCASE}/") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti") endif() @@ -25,5 +18,13 @@ add_mlir_library(TypeScriptRuntime EXCLUDE_FROM_LIBMLIR LINK_LIBS PRIVATE - gcmt-lib + BDWgc::gc ) + +if(MSVC) + # Export the runtime symbols under the names JIT-compiled code expects so the + # MLIR ExecutionEngine resolves them via the JITDylib path (no init callback, + # no cross-heap free of the symbol StringMap). See TypeScriptRuntime.def. + target_link_options(TypeScriptRuntime PRIVATE + "/DEF:${CMAKE_CURRENT_SOURCE_DIR}/TypeScriptRuntime.def") +endif() diff --git a/tsc/lib/TypeScriptRuntime/TypeScriptRuntime.def b/tsc/lib/TypeScriptRuntime/TypeScriptRuntime.def new file mode 100644 index 000000000..c5affeea3 --- /dev/null +++ b/tsc/lib/TypeScriptRuntime/TypeScriptRuntime.def @@ -0,0 +1,56 @@ +; Exports for TypeScriptRuntime.dll under the names JIT-compiled code expects. +; The MLIR ExecutionEngine resolves these directly from the DLL export table +; (JITDylib path) instead of through the '__mlir_execution_engine_init' hook, +; which avoids a cross-heap free of the symbol StringMap under the static CRT. +; +; Syntax 'EXPORTNAME=internal_symbol' re-exports an internal symbol under the +; name the generated code calls. + +EXPORTS + ; --- GC runtime (gc.cpp, extern "C" via gcwrapper.h) --- + GC_init=_mlir__GC_init + GC_malloc=_mlir__GC_malloc + GC_malloc_atomic=_mlir__GC_malloc_atomic + GC_memalign=_mlir__GC_memalign + GC_realloc=_mlir__GC_realloc + GC_free=_mlir__GC_free + GC_get_heap_size=_mlir__GC_get_heap_size + GC_malloc_explicitly_typed=_mlir__GC_malloc_explicitly_typed + GC_make_descriptor=_mlir__GC_make_descriptor + + ; --- memory runtime (MemRuntime.cpp, extern "C") --- + _mlir_alloc=Alloc + _mlir_aligned_alloc=AlignedAlloc + _mlir_free=Free + _mlir_aligned_free=AlignedFree + aligned_alloc=AlignedAlloc + aligned_free=AlignedFree + + ; --- dynamic-library runtime (DynamicRuntime.cpp, extern "C") --- + LLVMLoadLibraryPermanently=LoadLibraryPermanently + LLVMSearchForAddressOfSymbol=SearchForAddressOfSymbol + + ; --- async runtime (AsyncRuntime.cpp, extern "C", names already match) --- + mlirAsyncRuntimeAddRef + mlirAsyncRuntimeDropRef + mlirAsyncRuntimeExecute + mlirAsyncRuntimeGetValueStorage + mlirAsyncRuntimeCreateToken + mlirAsyncRuntimeCreateValue + mlirAsyncRuntimeEmplaceToken + mlirAsyncRuntimeEmplaceValue + mlirAsyncRuntimeSetTokenError + mlirAsyncRuntimeSetValueError + mlirAsyncRuntimeIsTokenError + mlirAsyncRuntimeIsValueError + mlirAsyncRuntimeIsGroupError + mlirAsyncRuntimeAwaitToken + mlirAsyncRuntimeAwaitValue + mlirAsyncRuntimeAwaitTokenAndExecute + mlirAsyncRuntimeAwaitValueAndExecute + mlirAsyncRuntimeCreateGroup + mlirAsyncRuntimeAddTokenToGroup + mlirAsyncRuntimeAwaitAllInGroup + mlirAsyncRuntimeAwaitAllInGroupAndExecute + mlirAsyncRuntimGetNumWorkerThreads + mlirAsyncRuntimePrintCurrentThreadId diff --git a/tsc/lib/TypeScriptRuntime/gc.cpp b/tsc/lib/TypeScriptRuntime/gc.cpp index d2b29248c..4bb539f6a 100644 --- a/tsc/lib/TypeScriptRuntime/gc.cpp +++ b/tsc/lib/TypeScriptRuntime/gc.cpp @@ -17,7 +17,11 @@ #endif #include "gc.h" -#include "gc_typed.h" +#include "gc/gc_typed.h" + +// give the wrappers C linkage so they are exported under clean, unmangled +// names (see TypeScriptRuntime.def, used by the JIT to resolve runtime symbols) +#include "TypeScript/gcwrapper.h" void _mlir__GC_init() { diff --git a/tsc/lib/TypeScriptRuntime/mlir_init.cpp b/tsc/lib/TypeScriptRuntime/mlir_init.cpp index 3d6b1e266..cf7b52fc4 100644 --- a/tsc/lib/TypeScriptRuntime/mlir_init.cpp +++ b/tsc/lib/TypeScriptRuntime/mlir_init.cpp @@ -1,45 +1,13 @@ -#include "llvm/ADT/StringMap.h" - #include -#ifdef _WIN32 -#pragma comment(linker, "/EXPORT:??_7type_info@@6B@") -#endif - -void init_gcruntime(llvm::StringMap &exportSymbols); -void destroy_gcruntime(); - -void init_memruntime(llvm::StringMap &exportSymbols); -//void destroy_memruntime(); +// The runtime symbols required by JIT-compiled code are exported under their +// JIT names via TypeScriptRuntime.def. We deliberately do NOT export the MLIR +// '__mlir_execution_engine_init/destroy' callbacks: when those are absent, the +// MLIR ExecutionEngine loads this library as a plain JITDylib and resolves +// symbols directly from its export table. That avoids the cross-heap free that +// happens when the DLL populates a StringMap owned (and later freed) by the EXE +// while both link the static CRT (separate heaps). -void init_asyncruntime(llvm::StringMap &exportSymbols); -void destroy_asyncruntime(); - -void init_dynamicruntime(llvm::StringMap &exportSymbols); -void destroy_dynamicruntime(); - -// Export symbols for the MLIR runner integration. All other symbols are hidden. #ifdef _WIN32 -#define API __declspec(dllexport) -#else -#define API __attribute__((visibility("default"))) +#pragma comment(linker, "/EXPORT:??_7type_info@@6B@") #endif - -extern "C" API void __mlir_execution_engine_init(llvm::StringMap &exportSymbols); - -// to support shared_libs -void __mlir_execution_engine_init(llvm::StringMap &exportSymbols) -{ - init_gcruntime(exportSymbols); - init_memruntime(exportSymbols); - init_asyncruntime(exportSymbols); - init_dynamicruntime(exportSymbols); -} - -extern "C" API void __mlir_execution_engine_destroy() -{ - destroy_gcruntime(); - //destory_memruntime(); - destroy_asyncruntime(); - destroy_dynamicruntime(); -} \ No newline at end of file diff --git a/tsc/test/.vscode/c_cpp_properties.json b/tsc/test/.vscode/c_cpp_properties.json index 5c736af74..3f18d42bb 100644 --- a/tsc/test/.vscode/c_cpp_properties.json +++ b/tsc/test/.vscode/c_cpp_properties.json @@ -6,7 +6,7 @@ "${workspaceFolder}/**", "${workspaceFolder}/../include", "${workspaceFolder}/../../3rdParty/llvm/x64/debug/include", - "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/include", + "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/include", "${workspaceFolder}/../tsc-new-parser" ], "defines": [ diff --git a/tsc/test/.vscode/launch.json b/tsc/test/.vscode/launch.json index 2d7431677..ea3c25a2d 100644 --- a/tsc/test/.vscode/launch.json +++ b/tsc/test/.vscode/launch.json @@ -8,10 +8,10 @@ "name": "(Windows) test-runner.exe - Launch (JIT - Shared)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/test-runner.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/test-runner.exe", "args": ["-shared", "-jit", "${workspaceFolder}/../../tsc/test/tester/tests/use_shared.ts", "${workspaceFolder}/../../tsc/test/tester/tests/shared.ts"], "stopAtEntry": false, - "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/", + "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/", "environment": [], "externalConsole": true, "visualizerFile": "${workspaceFolder}/../tsc.natvis" @@ -20,10 +20,10 @@ "name": "(Windows) test-runner.exe - Launch (Compile - Shared)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/test-runner.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/test-runner.exe", "args": ["-shared", "${workspaceFolder}/../../tsc/test/tester/tests/emit_class.ts", "${workspaceFolder}/../../tsc/test/tester/tests/decl_class.ts"], "stopAtEntry": false, - "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/", + "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/", "environment": [], "externalConsole": true, "visualizerFile": "${workspaceFolder}/../tsc.natvis" @@ -32,10 +32,10 @@ "name": "(Windows) test-runner.exe - Launch (Compile - Shared - Gctors-as-method)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/test-runner.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/test-runner.exe", "args": ["-shared", "-gctors-as-method", "${workspaceFolder}/../../tsc/test/tester/tests/import_object_literal_with_interface.ts ", "${workspaceFolder}/../../tsc/test/tester/tests/export_object_literal_with_interface.ts"], "stopAtEntry": false, - "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/", + "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/", "environment": [], "externalConsole": true, "visualizerFile": "${workspaceFolder}/../tsc.natvis" @@ -44,10 +44,10 @@ "name": "(Windows) test-runner.exe - Launch (Compile-Time)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/test-runner.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/test-runner.exe", "args": ["-shared", "-compile-time", "${workspaceFolder}/../../tsc/test/tester/tests/emit_compiletime_class.ts", "${workspaceFolder}/../../tsc/test/tester/tests/decl_class.ts"], "stopAtEntry": false, - "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/tester/Debug/", + "cwd": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/tester/Debug/", "environment": [], "externalConsole": true, "visualizerFile": "${workspaceFolder}/../tsc.natvis" @@ -56,7 +56,7 @@ "name": "(Windows) printer-tester.exe - Launch", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/test/print-tester/Debug/printer-tester.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/test/print-tester/Debug/printer-tester.exe", "args": ["c:\\temp\\dll.ts", "declare"], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/tsc/test/tester/CMakeLists.txt b/tsc/test/tester/CMakeLists.txt index 839ab6ab6..ad4e93ee6 100644 --- a/tsc/test/tester/CMakeLists.txt +++ b/tsc/test/tester/CMakeLists.txt @@ -76,18 +76,20 @@ endif() add_executable(test-runner test-runner.cpp) target_link_libraries(test-runner PRIVATE ${LIBS}) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE) +# GC lib dir derived from the BDWgc package (BDWgc_DIR=/lib/cmake/bdwgc) +get_filename_component(TEST_GC_LIBDIR "${BDWgc_DIR}/../.." ABSOLUTE) if (WIN32) target_compile_definitions(test-runner PUBLIC "TEST_LIBPATH=\"${VC_LIB_DIR}\"") target_compile_definitions(test-runner PUBLIC "TEST_SDKPATH=\"${WINDOWS_KITS_DIR_LIB}\"") target_compile_definitions(test-runner PUBLIC "TEST_UCRTPATH=\"${WINDOWS_KITS_DIR_UCRT_LIB}\"") target_compile_definitions(test-runner PUBLIC "CMAKE_C_STANDARD_LIBRARIES=\"${CMAKE_C_STANDARD_LIBRARIES}\"") - target_compile_definitions(test-runner PUBLIC "TEST_GCPATH=\"${PROJECT_SOURCE_DIR}/../3rdParty/gc/x64/${CMAKE_BUILD_TYPE_LOWERCASE}\"") + target_compile_definitions(test-runner PUBLIC "TEST_GCPATH=\"${TEST_GC_LIBDIR}\"") target_compile_definitions(test-runner PUBLIC "TEST_TSC_EXEPATH=\"${CMAKE_BINARY_DIR}/bin\"") target_compile_definitions(test-runner PUBLIC "TEST_TSC_LIBPATH=\"${CMAKE_BINARY_DIR}/lib\"") target_compile_definitions(test-runner PUBLIC "TEST_LLVM_EXEPATH=\"${PROJECT_SOURCE_DIR}/../3rdParty/llvm/x64/${CMAKE_BUILD_TYPE_LOWERCASE}/bin\"") target_compile_definitions(test-runner PUBLIC "TEST_LLVM_LIBPATH=\"${PROJECT_SOURCE_DIR}/../3rdParty/llvm/x64/${CMAKE_BUILD_TYPE_LOWERCASE}/lib\"") else() - target_compile_definitions(test-runner PUBLIC "TEST_GCPATH=\"${PROJECT_SOURCE_DIR}/../3rdParty/gc/${CMAKE_BUILD_TYPE_LOWERCASE}\"") + target_compile_definitions(test-runner PUBLIC "TEST_GCPATH=\"${TEST_GC_LIBDIR}\"") target_compile_definitions(test-runner PUBLIC "TEST_TSC_EXEPATH=\"${CMAKE_BINARY_DIR}/bin\"") target_compile_definitions(test-runner PUBLIC "TEST_TSC_LIBPATH=\"${CMAKE_BINARY_DIR}/lib\"") target_compile_definitions(test-runner PUBLIC "TEST_LLVM_EXEPATH=\"${PROJECT_SOURCE_DIR}/../3rdParty/llvm/${CMAKE_BUILD_TYPE_LOWERCASE}/bin\"") @@ -95,7 +97,17 @@ else() target_compile_definitions(test-runner PUBLIC "TEST_COMPILER=\"${CMAKE_CXX_COMPILER}\"") endif() -######## enable testing ############ +# test-runner caches the per-mode link scripts (compile/jit[d].bat|.sh) via an +# exists() guard and reuses them across runs, so they retain stale lib paths +# (e.g. GC_LIB_PATH) after a path-affecting reconfigure. Remove them on every +# (re)configure so they regenerate with the current TEST_* definitions above. +file(REMOVE + "${CMAKE_CURRENT_BINARY_DIR}/compile.bat" "${CMAKE_CURRENT_BINARY_DIR}/jit.bat" + "${CMAKE_CURRENT_BINARY_DIR}/compiled.bat" "${CMAKE_CURRENT_BINARY_DIR}/jitd.bat" + "${CMAKE_CURRENT_BINARY_DIR}/compile.sh" "${CMAKE_CURRENT_BINARY_DIR}/jit.sh" + "${CMAKE_CURRENT_BINARY_DIR}/compiled.sh" "${CMAKE_CURRENT_BINARY_DIR}/jitd.sh") + +######## enable testing ############ # open __build\tsc # ctest.exe -j4 -C Release -T test --output-on-failure add_test(NAME test-compile-00-print COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00print.ts") diff --git a/tsc/test/tester/helper.h b/tsc/test/tester/helper.h index 75f1876be..e171ba7a5 100644 --- a/tsc/test/tester/helper.h +++ b/tsc/test/tester/helper.h @@ -145,7 +145,7 @@ std::string exec(std::string cmd) { if (retry <= 1) { - std::cerr << "Error: return code is not 0, code: " << code << " cmd: " << cmd << " output: " << result << std::endl; + std::cerr << "Error: return code is not 0, code: " << code << " cmd: " << cmd << " path: " << fs::current_path() << " output: " << result << std::endl; } else { diff --git a/tsc/test/tester/test-runner.cpp b/tsc/test/tester/test-runner.cpp index b6de8490f..7e4739ec5 100644 --- a/tsc/test/tester/test-runner.cpp +++ b/tsc/test/tester/test-runner.cpp @@ -1,15 +1,20 @@ #include "helper.h" +#ifndef WIN32 +#include // for getpid +#endif + #if WIN32 -#define GC_LIB "gcmt-lib.lib " +#define GC_LIB "gc.lib " #else -#define GC_LIB "-lgcmt-lib " +#define GC_LIB "-lgc " #endif #ifdef WIN32 #define TYPESCRIPT_LIB "TypeScriptAsyncRuntime.lib " #define LLVM_LIBS "LLVMSupport.lib " //#define LIBS "msvcrt" _D_ ".lib ucrt" _D_ ".lib " -#define LIBS "msvcrt" _D_ ".lib ucrt" _D_ ".lib ntdll.lib " +// static CRT (/MT[d]) to match LLVM/TypeScript runtime libs and gc.lib; mixing static+dynamic CRT crashes at startup +#define LIBS "libcmt" _D_ ".lib libvcruntime" _D_ ".lib libucrt" _D_ ".lib ntdll.lib " #else // for Ubuntu 20.04 add -ldl and optionally -rdynamic #define LIBS "-frtti -fexceptions -lstdc++ -lrt -ldl -lpthread -lm -ltinfo" @@ -66,7 +71,7 @@ #endif #if WIN32 -#define RUN_CMD "" +#define RUN_CMD ".\\" #define BAT_NAME ".bat" #else #define RUN_CMD "/bin/sh -f ./" @@ -158,7 +163,7 @@ void createCompileBatchFile() << " /libpath:%LIBPATH% /libpath:%SDKPATH% /libpath:%UCRTPATH%" << std::endl; batFile << "del %FILENAME%.obj" << std::endl; - batFile << "call %FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl; + batFile << "call " RUN_CMD "%FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl; batFile << "del %FILENAME%.exe" << std::endl; batFile << "if exist %FILENAME%.lib (del %FILENAME%.lib)" << std::endl; batFile << "if exist %FILENAME%.dll (del %FILENAME%.dll)" << std::endl; @@ -272,7 +277,15 @@ std::string getTempOutputFileNameNoExt(std::string file) std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); std::string fileNameNoExt = fs::path(file).stem().string(); - auto fileNameNoExtWithMs = fileNameNoExt + "-" + std::to_string(ms.count()) + "-" + std::to_string(rand()); + // include the process id: rand() is never seeded, so every test-runner process yields the same first value and + // uniqueness would otherwise rely solely on the millisecond timestamp - same-stem tests (e.g. compile + jit + // variants) launched within the same millisecond under parallel ctest would collide on temp file names. +#ifdef WIN32 + auto pid = static_cast(GetCurrentProcessId()); +#else + auto pid = static_cast(getpid()); +#endif + auto fileNameNoExtWithMs = fileNameNoExt + "-" + std::to_string(ms.count()) + "-" + std::to_string(pid) + "-" + std::to_string(rand()); std::cout << "Test file: " << fileNameNoExtWithMs << " path: " << file << std::endl; @@ -355,7 +368,7 @@ void createMultiCompileBatchFile(std::string tempOutputFileNameNoExt, std::vecto << std::endl; batFile << "del " << objs.str() << std::endl; - batFile << "call %FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl; + batFile << "call " RUN_CMD "%FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl; batFile << "del %FILENAME%.exe" << std::endl; batFile << "if exist %FILENAME%.lib (del %FILENAME%.lib)" << std::endl; batFile << "if exist %FILENAME%.dll (del %FILENAME%.dll)" << std::endl; @@ -374,7 +387,8 @@ void createMultiCompileBatchFile(std::string tempOutputFileNameNoExt, std::vecto auto isFirst = true; for (auto &file : files) { - auto fileNameWithoutExt = fs::path(file).stem().string(); + // prefix with the unique temp name so parallel tests reusing the same source files don't stomp each other's object files + auto fileNameWithoutExt = tempOutputFileNameNoExt + "_" + fs::path(file).stem().string(); objs << fileNameWithoutExt << ".o "; batFile << "$TSCEXEPATH/tsc --emit=obj " << tsc_opt << " " << (isFirst ? "" : tsc_opt_ext) << " " << file << " -relocation-model=pic -o=" << fileNameWithoutExt << ".o" << std::endl; isFirst = false; @@ -480,7 +494,7 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector batFile << "del " << exec_objs.str() << std::endl; - batFile << "call %FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl; + batFile << "call " RUN_CMD "%FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl; batFile << "echo off" << std::endl; batFile << "del " << shared_libs.str() << std::endl; @@ -510,7 +524,8 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector std::stringstream sharedBat; for (auto &file : files) { - auto fileNameWithoutExt = fs::path(file).stem().string(); + // prefix with the unique temp name so parallel tests reusing the same source files don't stomp each other's object/shared-lib files + auto fileNameWithoutExt = tempOutputFileNameNoExt + "_" + fs::path(file).stem().string(); if (first) { exec_objs << fileNameWithoutExt << ".o "; @@ -520,48 +535,58 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector shared_objs << fileNameWithoutExt << ".o "; if (shared_filenameNoExt.empty()) { - shared_filenameNoExt = fileNameWithoutExt; + // the shared lib must keep its real (unprefixed) stem so that `import './'` + // resolves to lib.so instead of falling back to recompiling the source + shared_filenameNoExt = fs::path(file).stem().string(); } } - (first ? execBat : sharedBat) << "$TSCEXEPATH/tsc --emit=obj " << tsc_opt << " " << (first ? "" : tsc_opt) << " " << file << " -relocation-model=pic -o=" << fileNameWithoutExt << ".o" << std::endl; + (first ? execBat : sharedBat) << "$TSCEXEPATH/tsc --emit=obj " << tsc_opt << " " << (first ? "" : tsc_opt_ext) << " " << file << " -relocation-model=pic -o=" << fileNameWithoutExt << ".o" << std::endl; first = false; } + // run everything inside a unique per-test working directory: the shared lib must keep its + // real name (lib.so) for `import './'` to resolve, but that name is not unique + // across tests reusing the same source file - isolating the cwd avoids parallel collisions. + // Output (.txt/.err) is written to the parent dir where the runner reads it from. + batFile << "WORKDIR=" << tempOutputFileNameNoExt << "_wd" << std::endl; + batFile << "rm -rf $WORKDIR && mkdir -p $WORKDIR && cd $WORKDIR" << std::endl; + batFile << sharedBat.str(); - batFile << TEST_COMPILER << " " << linker_opt << " -o lib" << shared_filenameNoExt << ".so " << shared_objs.str() + batFile << TEST_COMPILER << " " << linker_opt << " -o lib" << shared_filenameNoExt << ".so " << shared_objs.str() << "-L$LLVM_LIBPATH -L$GC_LIB_PATH -L$TSC_LIB_PATH " << TYPESCRIPT_LIB << GC_LIB << LLVM_LIBS << LIBS << std::endl; batFile << "rm -f " << shared_objs.str() << std::endl; if (jitRun) { - batFile << "$TSCEXEPATH/tsc --emit=jit " << tsc_opt << " --shared-libs=../../lib/libTypeScriptRuntime.so " << *files.begin() << " 1> $FILENAME.txt 2> $FILENAME.err" + // one extra "../" because we run from the per-test working directory + batFile << "$TSCEXEPATH/tsc --emit=jit " << tsc_opt << " --shared-libs=../../../lib/libTypeScriptRuntime.so --shared-libs=./lib" << shared_filenameNoExt << ".so " << *files.begin() << " 1> ../$FILENAME.txt 2> ../$FILENAME.err" << std::endl; - batFile << "rm -f lib$FILENAME.so" << std::endl; } else { batFile << execBat.str(); - batFile << TEST_COMPILER << " -o $FILENAME " << exec_objs.str() << " "; + batFile << TEST_COMPILER << " -o $FILENAME " << exec_objs.str() << " "; batFile << "-L$LLVM_LIBPATH -L$GC_LIB_PATH -L$TSC_LIB_PATH "; - if (sharedLibCompileTime) + if (sharedLib) { + // dynamics and compile-time shared modes both link the produced shared lib; // we need "-Wl,-rpath=" to embed path for compiled shared lib path batFile << "-L`pwd` -Wl,-rpath=`pwd` -l" << shared_filenameNoExt << " "; - } + } batFile << TYPESCRIPT_LIB << GC_LIB << LLVM_LIBS << LIBS << std::endl; batFile << "rm -f " << exec_objs.str() << std::endl; - batFile << "./$FILENAME 1> $FILENAME.txt 2> $FILENAME.err" << std::endl; - - batFile << "rm -f $FILENAME" << std::endl; - batFile << "rm -f lib$FILENAME.so" << std::endl; + batFile << "./$FILENAME 1> ../$FILENAME.txt 2> ../$FILENAME.err" << std::endl; } + // leave and remove the per-test working directory (with the shared lib, exe, etc.) + batFile << "cd .. && rm -rf $WORKDIR" << std::endl; + batFile.close(); #endif } diff --git a/tsc/test/tester/tests/00reference_ref_deref.ts b/tsc/test/tester/tests/00reference_ref_deref.ts new file mode 100644 index 000000000..4da7f3646 --- /dev/null +++ b/tsc/test/tester/tests/00reference_ref_deref.ts @@ -0,0 +1,11 @@ +// @strict-null false + +let a = [1, 2, 3]; + +const pa: Ref> = Ref(a[0]); + +assert(Deref(pa[0]) == 1); +assert(Deref(pa[1]) == 2); +assert(Deref(pa[2]) == 3); + +print("done."); diff --git a/tsc/tsc-new-parser/parser.cpp b/tsc/tsc-new-parser/parser.cpp index 47984db2a..ac654f7f3 100644 --- a/tsc/tsc-new-parser/parser.cpp +++ b/tsc/tsc-new-parser/parser.cpp @@ -7731,13 +7731,13 @@ struct Parser // parse leading decorators if (allowDecorators && token() == SyntaxKind::AtToken) { - while (decorator = tryParseDecorator()) { + while ((decorator = tryParseDecorator())) { list = append(list, decorator); } } // parse leading modifiers - while (modifier = tryParseModifier(hasSeenStaticModifier, permitConstAsModifier, stopOnStartOfClassStaticBlock)) { + while ((modifier = tryParseModifier(hasSeenStaticModifier, permitConstAsModifier, stopOnStartOfClassStaticBlock))) { if (modifier == SyntaxKind::StaticKeyword) hasSeenStaticModifier = true; list = append(list, modifier); hasLeadingModifier = true; @@ -7745,7 +7745,7 @@ struct Parser // parse trailing decorators, but only if we parsed any leading modifiers if (hasLeadingModifier && allowDecorators && token() == SyntaxKind::AtToken) { - while (decorator = tryParseDecorator()) { + while ((decorator = tryParseDecorator())) { list = append(list, decorator); hasTrailingDecorator = true; } @@ -7753,7 +7753,7 @@ struct Parser // parse trailing modifiers, but only if we parsed any trailing decorators if (hasTrailingDecorator) { - while (modifier = tryParseModifier(hasSeenStaticModifier, permitConstAsModifier, stopOnStartOfClassStaticBlock)) { + while ((modifier = tryParseModifier(hasSeenStaticModifier, permitConstAsModifier, stopOnStartOfClassStaticBlock))) { if (modifier == SyntaxKind::StaticKeyword) hasSeenStaticModifier = true; list = append(list, modifier); } diff --git a/tsc/tsc/.vscode/launch.json b/tsc/tsc/.vscode/launch.json index 3115a0ce5..4979b5b30 100644 --- a/tsc/tsc/.vscode/launch.json +++ b/tsc/tsc/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(Windows) tsc.exe - DUMP", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=ast", "C:/temp/1.ts" @@ -23,7 +23,7 @@ "name": "(Windows) tsc.exe - MLIR", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=mlir", "-debug-only=mlir", @@ -49,7 +49,7 @@ ], "externalConsole": true, "MIMode": "gdb", - "miDebuggerPath": "/usr/bin/gdb", + "miDebuggerPath": "/usr/bin/gdb", "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], @@ -59,7 +59,7 @@ "name": "(Windows) tsc.exe - MLIR-AFFINE", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=mlir-affine", "--opt", @@ -95,7 +95,7 @@ "name": "(Windows) tsc.exe - MLIR-LLVM", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=mlir-llvm", "-debug-only=affine,llvm", @@ -127,7 +127,7 @@ "name": "(Windows) tsc.exe - LLVM", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=llvm", "-mlir-disable-threading", @@ -163,7 +163,7 @@ "name": "(Windows) tsc.exe - BC", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=bc", "-opt", @@ -175,7 +175,7 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - OBJ", "type": "cppvsdbg", @@ -193,12 +193,12 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - ASM", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=asm", "-opt", @@ -212,12 +212,12 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - EXE", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=exe", "-di", @@ -229,19 +229,70 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "DEFAULT_LIB_PATH", "value": "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/__build/release" }, - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/lib" }, + { + "name": "DEFAULT_LIB_PATH", + "value": "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/__build/release" + }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/lib" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, + { + "name": "(Windows) (ClangCL) tsc.exe - EXE", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../__build/tsc/windows-ninja-clangcl-debug/bin/tsc.exe", + "args": [ + "-emit=exe", + "-di", + "-lldb", + "-mlir-disable-threading", + "-debug-only=mlir", + "-mtriple=x86_64-pc-windows-msvc", + "I:/Playground/1.ts", + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "DEFAULT_LIB_PATH", + "value": "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/__build/release" + }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/lib" + }, + ], + "console": "externalTerminal", + "visualizerFile": "${workspaceFolder}/../tsc.natvis", + "MIMode": "gdb", + "MIDebuggerPath": "lldb.exe", + }, { "name": "(Windows) tsc.exe - EXE(DI) - NO DEFAULT", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=exe", "--di", @@ -256,18 +307,27 @@ "stopAtEntry": false, "cwd": "I:/Playground", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/lib" }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/lib" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - EXE(OPT) - NO DEFAULT", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=exe", "--opt", @@ -282,13 +342,22 @@ "stopAtEntry": false, "cwd": "I:/Playground", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/release/Release" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/release/Release/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-release/lib" }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/release/Release" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/release/Release/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-release/lib" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - EXE(OPT) (Release EXE) - NO DEFAULT", "type": "cppvsdbg", @@ -307,18 +376,27 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/release/Release" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/release/Release/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-release/lib" }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/release/Release" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/release/Release/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-release/lib" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - LLVM - NO DEFAULT", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=llvm", "-di", @@ -332,23 +410,32 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/lib" }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/lib" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - DLL", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=dll", "-opt", "-debug-only=tsc,llvm,pass", - "-mlir-disable-threading", + "-mlir-disable-threading", "--gctors-as-method", "-o=I:/Playground/export_vars.dll", "I:/Playground/export_vars.ts" @@ -356,18 +443,27 @@ "stopAtEntry": false, "cwd": "I:/Playground", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/lib" }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/msbuild/x64/debug/Debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/msbuild/x64/debug/Debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/lib" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - WASM", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=exe", "-opt", @@ -381,16 +477,16 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - WASM - emscripten", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=exe", "-mlir-disable-threading", - "-debug-only=pass", + "-debug-only=pass", "--nogc", "-o=c:/temp/1.wasm", "-mtriple=wasm32-pc-emscripten", @@ -402,12 +498,12 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - JIT", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=jit", "I:/Playground/1.ts", @@ -415,20 +511,19 @@ "-mlir-disable-threading", "-di", "--default-lib-path=I:/TypeScriptCompilerDefaultLib/__build/debug", - "--shared-libs=${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/TypeScriptRuntime.dll", - "--shared-libs=I:/Playground/export_enum.dll" + "--shared-libs=${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/TypeScriptRuntime.dll" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - JIT (no default)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=jit", "I:/Playground/1.ts", @@ -436,19 +531,19 @@ "-mlir-disable-threading", "-di", "--no-default-lib", - "--shared-libs=${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/TypeScriptRuntime.dll" + "--shared-libs=${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/TypeScriptRuntime.dll" ], "stopAtEntry": false, "cwd": "I:/Playground", "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - JIT-OBJ", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=jit", "-nogc", @@ -476,11 +571,10 @@ ], "stopAtEntry": false, "cwd": "${workspaceFolder}", - "environment": [ - ], + "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Linux) tsc - Compile (EXE - PIC)", "type": "cppdbg", @@ -496,13 +590,22 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/ninja/debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" } + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/ninja/debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" + } ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Linux) tsc - Compile (EXE)", "type": "cppdbg", @@ -517,14 +620,26 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/ninja/debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" }, - { "name": "DEFAULT_LIB_PATH", "value": "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/__build/release" }, + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/ninja/debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" + }, + { + "name": "DEFAULT_LIB_PATH", + "value": "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/__build/release" + }, ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Linux) tsc - Compile (DLL - PIC)", "type": "cppdbg", @@ -540,13 +655,22 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/ninja/debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" } + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/ninja/debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" + } ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Linux) tsc - Compile (Default Lib - linux file)", "type": "cppdbg", @@ -561,22 +685,31 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ - { "name": "GC_LIB_PATH", "value": "${workspaceFolder}/../../__build/gc/ninja/debug" }, - { "name": "LLVM_LIB_PATH", "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" }, - { "name": "TSC_LIB_PATH", "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" } + { + "name": "GC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/gc/ninja/debug" + }, + { + "name": "LLVM_LIB_PATH", + "value": "${workspaceFolder}/../../__build/llvm/ninja/debug/lib" + }, + { + "name": "TSC_LIB_PATH", + "value": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/lib" + } ], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - DefaultLib Compile (DLL)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=dll", "-debug-only=mlir,llvm", - "-mlir-disable-threading", + "-mlir-disable-threading", "--no-default-lib", "-o=c:/temp/lib.dll", "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/src/lib.ts" @@ -586,16 +719,16 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - DefaultLib Compile (MLIR)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=mlir", "-debug-only=mlir,llvm", - "-mlir-disable-threading", + "-mlir-disable-threading", "--no-default-lib", "-o=c:/temp/lib.mlir", "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/src/lib.ts" @@ -605,18 +738,18 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - DefaultLib Compile (DI) (OBJ)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=obj", "-debug-only=mlir,llvm", "-mlir-disable-threading", "--no-default-lib", - "--di", + "--di", "-o=c:/temp/lib.obj", "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/src/lib.ts" ], @@ -625,19 +758,19 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows) tsc.exe - DefaultLib Compile (opt) (OBJ)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "-emit=obj", "-debug-only=mlir,llvm", - "-mlir-disable-threading", + "-mlir-disable-threading", "--opt", - "--opt_level=3", - "--export=none", + "--opt_level=3", + "--export=none", "--no-default-lib", "--verbose", "-o=c:/temp/lib.win32.obj", @@ -648,7 +781,7 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Linux) tsc - DefaultLib Compile (OBJ)", "type": "cppdbg", @@ -656,11 +789,11 @@ "program": "${workspaceFolder}/../../__build/tsc/linux-ninja-gcc-debug/bin/tsc", "args": [ "-emit=obj", - "--export=none", + "--export=none", "--no-default-lib", "--di", "--opt_level=0", - "-mlir-disable-threading", + "-mlir-disable-threading", "-o=/home/alex/dev/playground/lib.obj", "${workspaceFolder}/../../../TypeScriptCompilerDefaultLib/src/lib.ts" ], @@ -669,7 +802,7 @@ "environment": [], "console": "externalTerminal", "visualizerFile": "${workspaceFolder}/../tsc.natvis" - }, + }, { "name": "(Windows-cppvsdbg) (cmake_winapp) TypeScriptApp.exe", "type": "cppvsdbg", @@ -682,13 +815,13 @@ "logging": { "moduleLoad": true, "trace": true - }, + }, }, { "name": "(Windows) tsc.exe - new VSCode project", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "--new", "Test1" @@ -703,7 +836,7 @@ "name": "(Windows) tsc.exe - Install Default lib", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-debug/bin/tsc.exe", + "program": "${workspaceFolder}/../../__build/tsc/windows-msbuild-2026-debug/bin/tsc.exe", "args": [ "--install-default-lib" ], @@ -725,6 +858,6 @@ "cwd": "${workspaceFolder}", "environment": [], "visualizerFile": "${workspaceFolder}/../tsc.natvis" - } + } ] } \ No newline at end of file diff --git a/tsc/tsc/exe.cpp b/tsc/tsc/exe.cpp index c17c46068..135d62125 100644 --- a/tsc/tsc/exe.cpp +++ b/tsc/tsc/exe.cpp @@ -115,9 +115,9 @@ bool checkFileExistsAtPath(std::string path, std::string fileName) void checkGCLibPath(std::string path) { #ifdef WIN32 - const auto libName = "gcmt-lib.lib"; + const auto libName = "gc.lib"; #else - const auto libName = "libgcmt-lib.a"; + const auto libName = "libgc.a"; #endif checkFileExistsAtPath(path, libName); } @@ -465,7 +465,7 @@ int buildExe(int argc, char **argv, std::string objFileName, std::string additio // tsc libs if (!disableGC) { - args.push_back("-lgcmt-lib"); + args.push_back("-lgc"); } if (isTscLibNeeded) diff --git a/tsc/tsc/jit.cpp b/tsc/tsc/jit.cpp index 4653f14c6..c7759facd 100644 --- a/tsc/tsc/jit.cpp +++ b/tsc/tsc/jit.cpp @@ -3,6 +3,13 @@ #include "mlir/ExecutionEngine/ExecutionEngine.h" #include "mlir/IR/BuiltinOps.h" +#include "llvm/Support/DynamicLibrary.h" + +#include +#ifdef _WIN32 +#include +#endif + #include "llvm/TargetParser/Host.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/TargetSelect.h" @@ -86,13 +93,17 @@ int loadLibrary(mlir::SmallString<256> &libPath, llvm::StringMap &export int runJit(int argc, char **argv, mlir::ModuleOp module, CompileOptions &compileOptions) { + // to avoid false positive memory leak reports in release builds // Print a stack trace if we signal out. llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); + llvm::PrettyStackTraceProgram X(argc, argv); llvm::setBugReportMsg("PLEASE submit a bug report to https://github.com/ASDAlexander77/TypeScriptCompiler/issues and include the crash backtrace."); llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + // No leaks until here + registerMLIRDialects(module); // Initialize LLVM targets. @@ -165,8 +176,40 @@ int runJit(int argc, char **argv, mlir::ModuleOp module, CompileOptions &compile engineOptions.jitCodeGenOptLevel = (llvm::CodeGenOptLevel) optLevel.getValue(); } +#ifdef _WIN32 + // tsc.exe links the CRT statically (/MT[d]), so its libc symbols are not in + // any DLL export table. The JIT's process-symbol resolver would otherwise bind + // libc calls (puts/printf/malloc/...) to a *different* CRT instance loaded as a + // DLL (ucrtbase.dll), giving JIT'd code a separate stdout buffer and heap from + // tsc.exe. That mismatch loses output and corrupts state on teardown. + // + // Add our own CRT entry points to the process symbol table *before* creating + // the engine: the JIT's GetForCurrentProcess generator consults this table + // (SearchForAddressOfSymbol checks explicitly-added symbols first) only for + // unresolved symbols, so it overrides ucrtbase without an ORC JITDylib + // "duplicate definition" conflict, and it is in place before create() eagerly + // materializes any global constructors that reference these symbols. + { + auto addSym = [](const char *name, void *addr) { + llvm::sys::DynamicLibrary::AddSymbol(name, addr); + }; + addSym("puts", (void*)&puts); + addSym("printf", (void*)&printf); + addSym("malloc", (void*)&malloc); + addSym("free", (void*)&free); + addSym("realloc", (void*)&realloc); + addSym("calloc", (void*)&calloc); + addSym("memset", (void*)&memset); + addSym("memcpy", (void*)&memcpy); + } +#endif + auto maybeEngine = mlir::ExecutionEngine::create(module, engineOptions); - assert(maybeEngine && "failed to construct an execution engine"); + if (!maybeEngine) + { + llvm::WithColor::error(llvm::errs(), "tsc") << "failed to construct an execution engine, error: " << maybeEngine.takeError() << "\n"; + return -1; + } auto &engine = maybeEngine.get(); if (dumpObjectFile) @@ -211,5 +254,14 @@ int runJit(int argc, char **argv, mlir::ModuleOp module, CompileOptions &compile return -1; } + // The JIT program has finished. On Windows/COFF the MLIR/ORC LLJIT platform + // registers process-level atexit glue that faults during teardown, so the + // normal CRT exit path crashes after a successful run. Flush stdio and exit + // the process directly, bypassing the CRT atexit handlers. + fflush(stdout); + fflush(stderr); +#ifdef _WIN32 + ExitProcess(0); +#endif return 0; } diff --git a/tsc/tsc/tsc.cpp b/tsc/tsc/tsc.cpp index 45cd34cc8..b65672955 100644 --- a/tsc/tsc/tsc.cpp +++ b/tsc/tsc/tsc.cpp @@ -114,7 +114,7 @@ cl::opt exportAction("export", cl::desc("Export Symbols. (Useful t cl::opt embedExportDeclarationsAction("embed-declarations", cl::desc("Embed declarations as member __decls_lib_XXXX. (Needed in 'import' statement)"), cl::init(true), cl::cat(TypeScriptCompilerCategory)); cl::opt defaultlibpath("default-lib-path", cl::desc("JS library path. Should point to folder/directory with subfolder '" DEFAULT_LIB_DIR "' or DEFAULT_LIB_PATH environmental variable"), cl::value_desc("defaultlibpath"), cl::cat(TypeScriptCompilerBuildCategory)); -cl::opt gclibpath("gc-lib-path", cl::desc("GC library path. Should point to file 'gcmt-lib.lib' or GC_LIB_PATH environmental variable"), cl::value_desc("gclibpath"), cl::cat(TypeScriptCompilerBuildCategory)); +cl::opt gclibpath("gc-lib-path", cl::desc("GC library path. Should point to file 'gc.lib' or GC_LIB_PATH environmental variable"), cl::value_desc("gclibpath"), cl::cat(TypeScriptCompilerBuildCategory)); cl::opt llvmlibpath("llvm-lib-path", cl::desc("LLVM library path. Should point to file 'LLVMSupport.lib' and 'LLVMDemangle' in linux or LLVM_LIB_PATH environmental variable"), cl::value_desc("llvmlibpath"), cl::cat(TypeScriptCompilerBuildCategory)); cl::opt tsclibpath("tsc-lib-path", cl::desc("TypeScript Compiler Runtime library path. Should point to file 'TypeScriptAsyncRuntime.lib' or TSC_LIB_PATH environmental variable"), cl::value_desc("tsclibpath"), cl::cat(TypeScriptCompilerBuildCategory)); cl::opt emsdksysrootpath("emsdk-sysroot-path", cl::desc("TypeScript Compiler Runtime library path. Should point to dir '<...>/emsdk/upstream/emscripten/cache/sysroot' or EMSDK_SYSROOT_PATH environmental variable. (used when '-mtriple=wasm32-pc-emscripten')"), cl::value_desc("emsdksysrootpath"), cl::cat(TypeScriptCompilerBuildCategory)); @@ -227,6 +227,16 @@ bool prepareDefaultLib(CompileOptions &compileOptions) int main(int argc, char **argv) { +#if _MSC_VER && _DEBUG + // Get current flag + int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); + tmpFlag |= _CRTDBG_LEAK_CHECK_DF; + // Set flag to the new value. + _CrtSetDbgFlag( tmpFlag ); + //_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); + _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); +#endif + // version printer cl::SetVersionPrinter(TscPrintVersion);