diff --git a/.github/workflows/macos-test.yml b/.github/workflows/macos-test.yml index 64a768757..2f86c4e2a 100644 --- a/.github/workflows/macos-test.yml +++ b/.github/workflows/macos-test.yml @@ -77,7 +77,7 @@ jobs: - name: Set up the environment run: sh ./tools/metacall-environment.sh $METACALL_INSTALL_OPTIONS env: - METACALL_INSTALL_OPTIONS: base python nodejs typescript java ruby wasm rpc file cobol go backtrace #netcore5 c rust rapidjson funchook swig pack # clangformat v8rep51 coverage + METACALL_INSTALL_OPTIONS: base python nodejs typescript java ruby c wasm rpc file cobol go backtrace #netcore5 rust rapidjson funchook swig pack # clangformat v8rep51 coverage - name: Configure run: | @@ -85,7 +85,7 @@ jobs: . .env bash ../tools/metacall-configure.sh $METACALL_CONFIGURE_OPTIONS env: - METACALL_CONFIGURE_OPTIONS: ${{ matrix.options.build }} ${{ matrix.options.sanitizer }} scripts ports tests python nodejs typescript java ruby wasm rpc file cobol go benchmarks install # netcore5 c rust examples pack # v8 coverage + METACALL_CONFIGURE_OPTIONS: ${{ matrix.options.build }} ${{ matrix.options.sanitizer }} scripts ports tests python nodejs typescript java ruby c wasm rpc file cobol go benchmarks install # netcore5 rust examples pack # v8 coverage - name: Build working-directory: ./build diff --git a/.github/workflows/windows-test.yml b/.github/workflows/windows-test.yml index c7af6e0ee..f9db06953 100644 --- a/.github/workflows/windows-test.yml +++ b/.github/workflows/windows-test.yml @@ -48,7 +48,7 @@ jobs: - name: Set up the environment run: cmd.exe /c "powershell .\tools\metacall-environment.ps1 $Env:METACALL_INSTALL_OPTIONS" env: - METACALL_INSTALL_OPTIONS: python nodejs java ruby typescript wasm rpc file # netcore5 java c cobol rust rapidjson funchook swig pack # clangformat v8rep51 coverage + METACALL_INSTALL_OPTIONS: c python nodejs java ruby typescript wasm rpc file # netcore5 java cobol rust rapidjson funchook swig pack # clangformat v8rep51 coverage - name: Configure run: | @@ -57,7 +57,7 @@ jobs: cd "$METACALL_PATH\build" cmd.exe /c "powershell ..\tools\metacall-configure.ps1 $Env:METACALL_BUILD_OPTIONS" env: - METACALL_BUILD_OPTIONS: ${{ matrix.options.build }} ${{ matrix.options.sanitizer }} scripts ports tests python nodejs java ruby typescript wasm rpc file # netcore5 java c cobol rust examples install pack benchmarks # v8 coverage + METACALL_BUILD_OPTIONS: ${{ matrix.options.build }} ${{ matrix.options.sanitizer }} scripts ports tests c python nodejs java ruby typescript wasm rpc file # netcore5 java cobol rust examples install pack benchmarks # v8 coverage - name: Build working-directory: ./build diff --git a/cmake/InstallLibTCC.cmake b/cmake/InstallLibTCC.cmake old mode 100644 new mode 100755 index 096f447c9..523166170 --- a/cmake/InstallLibTCC.cmake +++ b/cmake/InstallLibTCC.cmake @@ -188,4 +188,4 @@ set(LIBTCC_FOUND TRUE) mark_as_advanced(LIBTCC_INCLUDE_DIR LIBTCC_LIBRARY) -message(STATUS "Installing LibTCC ${LIBTCC_COMMIT_SHA}") +message(STATUS "Installing LibTCC ${LIBTCC_COMMIT_SHA}") \ No newline at end of file diff --git a/cmake/Warnings.cmake b/cmake/Warnings.cmake index 5c9b44da7..aa78a1844 100644 --- a/cmake/Warnings.cmake +++ b/cmake/Warnings.cmake @@ -85,7 +85,7 @@ if(WARNINGS_ENABLED) string(REPLACE "/W1" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") string(REPLACE "/W2" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") string(REPLACE "/W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /Wall") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2 /Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CTR_NONSTDC_NO_WARNINGS=1") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CTR_SECURE_NO_WARNINGS=1") set(WARNINGS_C_AVAILABLE 1) @@ -105,7 +105,7 @@ if(WARNINGS_ENABLED) string(REPLACE "/W1" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/W2" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2 /Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _CTR_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _CTR_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _CTR_NONSTDC_NO_WARNINGS=1") diff --git a/source/loaders/c_loader/CMakeLists.txt b/source/loaders/c_loader/CMakeLists.txt index cc2c09210..509e17dce 100644 --- a/source/loaders/c_loader/CMakeLists.txt +++ b/source/loaders/c_loader/CMakeLists.txt @@ -17,12 +17,14 @@ endif() find_package(LibTCC) if(NOT LIBTCC_FOUND) + message(Status "###########checking in install libtcc###########") include(InstallLibTCC) - + message(Status "###########Done checking###########") if(NOT LIBTCC_FOUND) message(SEND_ERROR "TCC library not found") return() endif() + message(Status "###########Lib tcc found###########") endif() find_package(LibClang) diff --git a/source/loaders/c_loader/source/c_loader_impl.cpp b/source/loaders/c_loader/source/c_loader_impl.cpp index 4ad6689bf..a506a8d17 100644 --- a/source/loaders/c_loader/source/c_loader_impl.cpp +++ b/source/loaders/c_loader/source/c_loader_impl.cpp @@ -64,8 +64,8 @@ namespace fs = std::experimental::filesystem; #include /* LibClang */ -#include #include +#include typedef struct loader_impl_c_type { diff --git a/tools/metacall-environment.ps1 b/tools/metacall-environment.ps1 index dd2191520..faa2dc12a 100755 --- a/tools/metacall-environment.ps1 +++ b/tools/metacall-environment.ps1 @@ -202,6 +202,127 @@ function Set-Ruby { Write-Output "-DRuby_LIBRARY_NAME=""$RubyDir/bin/x64-vcruntime140-ruby310.dll""" >> $EnvOpts } + +function Set-C { + $ErrorActionPreference = "Stop" + Write-Output "Installing C dependencies..." + + # Ensure Chocolatey is set up + Set-Choco + + # Set directories + Set-Location $ROOT_DIR + $DepsDir = Join-Path $ROOT_DIR 'dependencies' + $vcpkgDir = Join-Path $DepsDir 'vcpkg' + + # Install vcpkg if missing + if (-not (Test-Path (Join-Path $vcpkgDir 'vcpkg.exe'))) { + Write-Output "Cloning vcpkg into $vcpkgDir..." + git clone --depth=1 https://github.com/microsoft/vcpkg.git $vcpkgDir + & (Join-Path $vcpkgDir 'bootstrap-vcpkg.bat') + & (Join-Path $vcpkgDir 'vcpkg.exe') integrate install + } else { + Write-Output "vcpkg already installed." + } + + # Install libffi using vcpkg + Write-Output "Installing libffi using vcpkg..." + & (Join-Path $vcpkgDir 'vcpkg.exe') install libffi + + + # Define LLVM version and download URL + $llvmVersion = "19.1.7" + $llvmArchiveUrl = "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvmVersion/clang+llvm-$llvmVersion-x86_64-pc-windows-msvc.tar.xz" + $archivePath = "$env:TEMP\clang+llvm-$llvmVersion-x86_64-pc-windows-msvc.tar.xz" + $extractPath = "$env:TEMP\clang+llvm-$llvmVersion" + $finalPath = Join-Path $DepsDir 'llvm' + + # Ensure dependencies directory exists + if (!(Test-Path $DepsDir)) { + New-Item -ItemType Directory -Path $DepsDir -Force | Out-Null + } + + Download LLVM archive + Write-Output "Downloading LLVM $llvmVersion archive..." + Invoke-WebRequest -Uri $llvmArchiveUrl -OutFile $archivePath + + # Extract the .xz file + Write-Output "Extracting .xz archive..." + tar -xf $archivePath -C $env:TEMP + $tarFile = $archivePath -replace '\.xz$', '' # Remove .xz extension + + # Extract the .tar file + Write-Output "Extracting .tar archive..." + tar -xf $tarFile -C $env:TEMP + + # Find the extracted folder + $extractedFolder = Get-ChildItem -Path $env:TEMP -Directory | Where-Object { $_.Name -match "clang\+llvm-$llvmVersion-x86_64-pc-windows-msvc" } | Select-Object -First 1 + + if ($extractedFolder) { + Write-Output "Moving extracted LLVM to $finalPath..." + Move-Item -Path $extractedFolder.FullName -Destination $finalPath -Force + } else { + Write-Output "Extracted LLVM folder not found!" + } + + # Clean up + Write-Output "Cleaning up downloaded files..." + Remove-Item -Path $archivePath, $tarFile -Force + + Write-Output "LLVM $llvmVersion successfully installed at $finalPath!" + + # Write environment options for CMake configuration + $Env_Opts = "$ROOT_DIR\build\CMakeConfig.txt" + $vcpkgLibDir = "$DepsDir\vcpkg\installed\x64-windows\lib" + $vcpkgIncludeDir = "$DepsDir\vcpkg\installed\x64-windows\include" + + $cmakeOptions = @( + "set(OPTION_BUILD_LOADERS_C ON CACHE BOOL `"Build C loaders`")" + + "set(LIBFFI_LIBRARY `"$vcpkgLibDir\ffi.lib`" CACHE STRING `"Path to libffi library`")" + "set(LIBFFI_INCLUDE_DIR `"$vcpkgIncludeDir`" CACHE STRING `"Path to libffi include directory`")" + + "set(LibClang_INCLUDE_DIR `"$finalPath\include`" CACHE STRING `"Path to libclang include directory`")" + "set(LIBCLANG_LIBRARY `"$finalPath\lib\libclang.lib`" CACHE STRING `"Path to libclang library`")" + + "set(CMAKE_TOOLCHAIN_FILE `"$vcpkgDir\scripts\buildsystems\vcpkg.cmake`" CACHE STRING `"Path to vcpkg toolchain file`")" + ) + + $cmakeOptions | Out-File -Append -FilePath $Env_Opts + + Write-Output "All dependencies installed and configured successfully." +} + +function Clone-GitRepository { + param ( + [string]$repositoryUrl, + [string]$destinationPath + ) + + # Check if Git is installed + if (-not (Get-Command git -ErrorAction SilentlyContinue)) { + Write-Error "Git is not installed. Please install Git and try again." + return + } + + # Check if the destination path already exists + if (Test-Path $destinationPath) { + Write-Error "Destination path already exists. Please provide a different path." + return + } + + # Clone the repository using Git + & git clone $repositoryUrl $destinationPath + + # Check if the cloning was successful + if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to clone the repository." + return + } + + Write-Output "Repository cloned successfully." +} + function Set-TypeScript { Write-Output "Install TypeScript" npm i react@latest -g @@ -279,6 +400,21 @@ function Set-Base { } } +function Set-Choco { + # Set directory for installation - Chocolatey does not lock + # down the directory if not the default + $InstallDir='C:\ProgramData\chocoportable' + $env:ChocolateyInstall="$InstallDir" + + # If your PowerShell Execution policy is restrictive, you may + # not be able to get around that. Try setting your session to + # Bypass. + Set-ExecutionPolicy Bypass -Scope Process -Force; + + # All install options - offline, proxy, etc at + # https://chocolatey.org/install + iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) +} # Configure function Configure { # Create option variables file @@ -352,6 +488,7 @@ function Configure { } if ("$var" -eq 'c') { Write-Output "c selected" + Set-C } if ("$var" -eq 'cobol') { Write-Output "cobol selected" diff --git a/tools/metacall-environment.sh b/tools/metacall-environment.sh index d2983330b..f77e8bbda 100755 --- a/tools/metacall-environment.sh +++ b/tools/metacall-environment.sh @@ -650,9 +650,8 @@ sub_java(){ # C sub_c(){ echo "configure c" - + LLVM_VERSION_STRING=14 if [ "${OPERATIVE_SYSTEM}" = "Linux" ]; then - LLVM_VERSION_STRING=14 if [ "${LINUX_DISTRO}" = "debian" ]; then UBUNTU_CODENAME=""