Skip to content

Commit 611ecf5

Browse files
committedFeb 9, 2025
add Set-C function from PR metacall#458
1 parent ce9b9e6 commit 611ecf5

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
 

‎tools/metacall-environment.ps1

+82
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,73 @@ function Set-Ruby {
202202
Write-Output "-DRuby_LIBRARY_NAME=""$RubyDir/bin/x64-vcruntime140-ruby310.dll""" >> $EnvOpts
203203
}
204204

205+
function Set-C {
206+
Write-Output "Install C depenendencies"
207+
208+
Set-Location $ROOT_DIR
209+
210+
$DepsDir = "$ROOT_DIR\dependencies"
211+
$repositoryUrl = "https://github.com/newlawrence/Libffi.git"
212+
$destinationPath = "$DepsDir\libffi"
213+
Clone-GitRepository -repositoryUrl $repositoryUrl -destinationPath $destinationPath
214+
215+
216+
mkdir "$destinationPath\build"
217+
Set-Location "$destinationPath\build"
218+
219+
cmake .. -G"Visual Studio 16 2019"
220+
221+
cmake --build . --target ffi
222+
223+
Set-Choco
224+
225+
# choco install llvm -y
226+
choco install llvm -y
227+
228+
229+
$Env_Opts = "$ROOT_DIR\build\CMakeConfig.txt"
230+
231+
$LLVM_Dir1 = "$env:ProgramW6432/LLVM".Replace('\', '/')
232+
# find a way to pass multiple locations to cmake
233+
# $LLVM_Dir2 = "$env:ProgramFiles/LLVM".Replace('\', '/')
234+
$LibFFI_Dir = $destinationPath.Replace('\','/')
235+
236+
Write-Output "-DLIBFFI_LIBRARY=""$LibFFI_Dir/build/lib/libffi.lib""" >> $Env_Opts
237+
Write-Output "-DLIBFFI_INCLUDE_DIR=""$LibFFI_Dir/build/include/""" >> $Env_Opts
238+
Write-Output "-DLibClang_INCLUDE_DIR=""$LLVM_Dir1/include/clang""" >> $Env_Opts
239+
240+
}
241+
242+
function Clone-GitRepository {
243+
param (
244+
[string]$repositoryUrl,
245+
[string]$destinationPath
246+
)
247+
248+
# Check if Git is installed
249+
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
250+
Write-Error "Git is not installed. Please install Git and try again."
251+
return
252+
}
253+
254+
# Check if the destination path already exists
255+
if (Test-Path $destinationPath) {
256+
Write-Error "Destination path already exists. Please provide a different path."
257+
return
258+
}
259+
260+
# Clone the repository using Git
261+
& git clone $repositoryUrl $destinationPath
262+
263+
# Check if the cloning was successful
264+
if ($LASTEXITCODE -ne 0) {
265+
Write-Error "Failed to clone the repository."
266+
return
267+
}
268+
269+
Write-Output "Repository cloned successfully."
270+
}
271+
205272
function Set-TypeScript {
206273
Write-Output "Install TypeScript"
207274
npm i react@latest -g
@@ -279,6 +346,21 @@ function Set-Base {
279346
}
280347
}
281348

349+
function Set-Choco {
350+
# Set directory for installation - Chocolatey does not lock
351+
# down the directory if not the default
352+
$InstallDir='C:\ProgramData\chocoportable'
353+
$env:ChocolateyInstall="$InstallDir"
354+
355+
# If your PowerShell Execution policy is restrictive, you may
356+
# not be able to get around that. Try setting your session to
357+
# Bypass.
358+
Set-ExecutionPolicy Bypass -Scope Process -Force;
359+
360+
# All install options - offline, proxy, etc at
361+
# https://chocolatey.org/install
362+
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
363+
}
282364
# Configure
283365
function Configure {
284366
# Create option variables file

0 commit comments

Comments
 (0)
Please sign in to comment.