2023-06-29 19:46:52 +08:00
|
|
|
# //////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
# // A multi-platform support c++11 library with focus on asynchronous socket I/O for any
|
|
|
|
# // client application.
|
|
|
|
# //////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012-2023 HALX99
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
#
|
|
|
|
#
|
2023-06-30 16:53:20 +08:00
|
|
|
# The build1k.ps1, will be core script of project https://github.com/axmolengine/build1k
|
2023-06-29 19:46:52 +08:00
|
|
|
# options
|
2023-09-01 16:31:14 +08:00
|
|
|
# -p: build target platform: win32,winuwp,linux,android,osx,ios,tvos,watchos,wasm
|
2023-06-29 19:46:52 +08:00
|
|
|
# for android: will search ndk in sdk_root which is specified by env:ANDROID_HOME first,
|
|
|
|
# if not found, by default will install ndk-r16b or can be specified by option: -cc 'ndk-r23c'
|
|
|
|
# -a: build arch: x86,x64,armv7,arm64
|
2023-06-30 16:53:20 +08:00
|
|
|
# -d: the build workspace, i.e project root which contains root CMakeLists.txt, empty use script run working directory aka cwd
|
|
|
|
# -cc: The C/C++ compiler toolchain: clang, msvc, gcc, mingw-gcc or empty use default installed on current OS
|
2023-06-29 19:46:52 +08:00
|
|
|
# msvc: msvc-120, msvc-141
|
|
|
|
# ndk: ndk-r16b, ndk-r16b+
|
2023-08-30 08:34:33 +08:00
|
|
|
# -xt: cross build tool, default: cmake, for android can be gradlew, can be path of cross build tool program
|
2023-06-30 16:53:20 +08:00
|
|
|
# -xc: cross build tool configure options: i.e. -xc '-Dbuild','-DCMAKE_BUILD_TYPE=Release'
|
|
|
|
# -xb: cross build tool build options: i.e. -xb '--config','Release'
|
|
|
|
# -prefix: the install location for missing tools in system, default is "$HOME/build1k"
|
2023-08-30 08:34:33 +08:00
|
|
|
# -sdk: specific windows sdk version, i.e. -sdk '10.0.19041.0', leave empty, cmake will auto choose latest avaiable
|
|
|
|
# -setupOnly: this param present, only execute step: setup
|
|
|
|
# -configOnly: if this param present, will skip build step
|
2023-06-29 19:46:52 +08:00
|
|
|
# support matrix
|
2023-06-30 16:53:20 +08:00
|
|
|
# | OS | Build targets | C/C++ compiler toolchain | Cross Build tool |
|
|
|
|
# +----------+----------------------+---------------------------+------------------|
|
|
|
|
# | Windows | win32,winuwp | msvc,clang,mingw-gcc | cmake |
|
|
|
|
# | Linux | linux,android | ndk | cmake,gradle |
|
|
|
|
# | macOS | osx,ios,tvos,watchos | xcode | cmake |
|
2023-06-29 19:46:52 +08:00
|
|
|
#
|
2023-08-30 08:34:33 +08:00
|
|
|
param(
|
|
|
|
[switch]$configOnly,
|
|
|
|
[switch]$setupOnly
|
|
|
|
)
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
$myRoot = $PSScriptRoot
|
|
|
|
|
|
|
|
# ----------------- utils functions -----------------
|
|
|
|
|
|
|
|
$HOST_WIN = 0 # targets: win,uwp,android
|
|
|
|
$HOST_LINUX = 1 # targets: linux,android
|
|
|
|
$HOST_MAC = 2 # targets: android,ios,osx(macos),tvos,watchos
|
|
|
|
|
|
|
|
# 0: windows, 1: linux, 2: macos
|
|
|
|
$IsWin = $IsWindows -or ("$env:OS" -eq 'Windows_NT')
|
|
|
|
if ($IsWin) {
|
|
|
|
$HOST_OS = $HOST_WIN
|
|
|
|
$envPathSep = ';'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$envPathSep = ':'
|
|
|
|
if ($IsLinux) {
|
|
|
|
$HOST_OS = $HOST_LINUX
|
|
|
|
}
|
|
|
|
elseif ($IsMacOS) {
|
|
|
|
$HOST_OS = $HOST_MAC
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw "Unsupported host OS to run build1k.ps1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$exeSuffix = if ($HOST_OS -eq 0) { '.exe' } else { '' }
|
|
|
|
|
|
|
|
class build1k {
|
|
|
|
[void] println($msg) {
|
|
|
|
Write-Host "build1k: $msg"
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] print($msg) {
|
|
|
|
Write-Host "build1k: $msg" -NoNewline
|
|
|
|
}
|
|
|
|
|
|
|
|
[System.Boolean] isfile([string]$path) {
|
|
|
|
return Test-Path $path -PathType Leaf
|
|
|
|
}
|
|
|
|
|
|
|
|
[System.Boolean] isdir([string]$path) {
|
|
|
|
return Test-Path $path -PathType Container
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] mkdirs([string]$path) {
|
2023-09-01 01:06:58 +08:00
|
|
|
if (!(Test-Path $path -PathType Container)) {
|
|
|
|
New-Item $path -ItemType Directory 1>$null
|
|
|
|
}
|
2023-07-15 00:21:23 +08:00
|
|
|
}
|
|
|
|
|
2023-09-03 11:47:36 +08:00
|
|
|
[void] rmdirs([string]$path) {
|
2023-08-25 16:57:54 +08:00
|
|
|
if ($this.isdir($path)) {
|
|
|
|
$this.println("Deleting $path ...")
|
|
|
|
Remove-Item $path -Recurse -Force
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] del([string]$path) {
|
|
|
|
if ($this.isfile($path)) {
|
|
|
|
$this.println("Deleting $path ...")
|
|
|
|
Remove-Item $path -Force
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-03 11:47:36 +08:00
|
|
|
[void] mv([string]$path, [string]$dest) {
|
2023-08-25 16:57:54 +08:00
|
|
|
if ($this.isdir($path) -and !$this.isdir($dest)) {
|
|
|
|
Move-Item $path $dest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
[void] pause($msg) {
|
|
|
|
if ($Global:IsWin) {
|
|
|
|
$myProcess = [System.Diagnostics.Process]::GetCurrentProcess()
|
|
|
|
$parentProcess = $myProcess.Parent
|
|
|
|
if (!$parentProcess) {
|
|
|
|
$myPID = $myProcess.Id
|
|
|
|
$instance = Get-WmiObject Win32_Process -Filter "ProcessId = $myPID"
|
|
|
|
$parentProcess = Get-Process -Id $instance.ParentProcessID
|
|
|
|
}
|
|
|
|
$parentProcessName = $parentProcess.ProcessName
|
|
|
|
if ($parentProcessName -like "explorer") {
|
|
|
|
$this.print("$msg, press any key to continue . . .")
|
|
|
|
cmd /c pause 1>$null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this.println($msg)
|
|
|
|
}
|
|
|
|
}
|
2023-09-06 12:36:24 +08:00
|
|
|
|
|
|
|
[string] hash($content) {
|
|
|
|
$stringAsStream = [System.IO.MemoryStream]::new()
|
|
|
|
$writer = [System.IO.StreamWriter]::new($stringAsStream)
|
|
|
|
$writer.write($content)
|
|
|
|
$writer.Flush()
|
|
|
|
$stringAsStream.Position = 0
|
|
|
|
return (Get-FileHash -InputStream $stringAsStream -Algorithm MD5).Hash
|
|
|
|
}
|
2023-07-15 00:21:23 +08:00
|
|
|
}
|
|
|
|
$b1k = [build1k]::new()
|
|
|
|
|
|
|
|
# ---------------------- manifest --------------------
|
2023-07-02 00:53:41 +08:00
|
|
|
# mode:
|
|
|
|
# x.y.z+ : >=
|
|
|
|
# x.y.z : ==
|
|
|
|
# * : any
|
|
|
|
# x.y.z~x2.y2.z2 : range
|
|
|
|
$manifest = @{
|
2023-07-15 00:21:23 +08:00
|
|
|
# C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Redist\MSVC\14.36.32532\vc_redist.x64.exe
|
|
|
|
msvc = '14.36.32532';
|
2023-08-25 16:57:54 +08:00
|
|
|
ndk = 'r23c';
|
2023-07-02 00:53:41 +08:00
|
|
|
xcode = '13.0.0~14.2.0'; # range
|
2023-09-03 11:47:36 +08:00
|
|
|
# _EMIT_STL_ERROR(STL1000, "Unexpected compiler version, expected Clang 16.0.0 or newer.");
|
|
|
|
clang = '16.0.0+'; # clang-cl msvc14.37 require 16.0.0+
|
2023-07-02 00:53:41 +08:00
|
|
|
gcc = '9.0.0+';
|
2023-08-25 16:57:54 +08:00
|
|
|
cmake = '3.22.1+';
|
2023-07-02 00:53:41 +08:00
|
|
|
ninja = '1.11.1+';
|
|
|
|
jdk = '11.0.19+';
|
2023-09-14 19:04:08 +08:00
|
|
|
emsdk = '3.1.45';
|
2023-07-02 00:53:41 +08:00
|
|
|
cmdlinetools = '7.0+'; # android cmdlinetools
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$channels = @{}
|
2023-07-07 19:32:57 +08:00
|
|
|
|
2023-07-02 00:53:41 +08:00
|
|
|
# refer to: https://developer.android.com/studio#command-line-tools-only
|
|
|
|
$cmdlinetools_rev = '9477386'
|
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
$options = @{
|
2023-09-03 11:47:36 +08:00
|
|
|
p = $null;
|
|
|
|
a = 'x64';
|
|
|
|
d = $null;
|
|
|
|
cc = $null;
|
|
|
|
xt = 'cmake';
|
|
|
|
prefix = $null;
|
|
|
|
xc = @();
|
|
|
|
xb = @();
|
|
|
|
sdk = $null;
|
|
|
|
dll = $false
|
2023-07-06 12:18:33 +08:00
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
|
|
|
$optName = $null
|
|
|
|
foreach ($arg in $args) {
|
|
|
|
if (!$optName) {
|
|
|
|
if ($arg.StartsWith('-')) {
|
|
|
|
$optName = $arg.SubString(1)
|
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-06-29 19:46:52 +08:00
|
|
|
if ($options.Contains($optName)) {
|
|
|
|
$options[$optName] = $arg
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Warning: ignore unrecognized option: $optName")
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
$optName = $null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-01 16:31:14 +08:00
|
|
|
$is_wasm = $options.p -eq 'wasm'
|
|
|
|
if ($is_wasm) {
|
|
|
|
$options.a = 'any' # forcing arch to 'any', only for identifying
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$manifest_file = Join-Path $myRoot 'manifest.ps1'
|
|
|
|
if ($b1k.isfile($manifest_file)) {
|
|
|
|
. $manifest_file
|
|
|
|
}
|
|
|
|
|
|
|
|
# translate xtool args
|
|
|
|
if ($options.xc.GetType() -eq [string]) {
|
|
|
|
$options.xc = $options.xc.Split(' ')
|
|
|
|
}
|
|
|
|
if ($options.xb.GetType() -eq [string]) {
|
|
|
|
$options.xb = $options.xb.Split(' ')
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
$pwsh_ver = $PSVersionTable.PSVersion.ToString()
|
2023-09-13 03:37:49 +08:00
|
|
|
# $osVer = [System.Environment]::OSVersion.Version.ToString()
|
|
|
|
if ([System.Version]$pwsh_ver -lt [System.Version]"7.0.0.0") {
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("PowerShell $pwsh_ver")
|
2023-07-06 12:18:33 +08:00
|
|
|
|
2023-08-30 08:34:33 +08:00
|
|
|
if (!$setupOnly) {
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("$(Out-String -InputObject $options)")
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$CONFIG_DEFAULT_OPTIONS = @()
|
|
|
|
$HOST_OS_NAME = $('windows', 'linux', 'macos').Get($HOST_OS)
|
|
|
|
|
|
|
|
# determine build target os
|
|
|
|
$BUILD_TARGET = $options.p
|
|
|
|
if (!$BUILD_TARGET) {
|
2023-07-01 08:52:14 +08:00
|
|
|
# choose host target if not specified by command line automatically
|
2023-06-29 19:46:52 +08:00
|
|
|
$BUILD_TARGET = $('win32', 'linux', 'osx').Get($HOST_OS)
|
|
|
|
}
|
|
|
|
|
|
|
|
# determine toolchain
|
|
|
|
$TOOLCHAIN = $options.cc
|
|
|
|
$toolchains = @{
|
2023-06-30 16:53:20 +08:00
|
|
|
'win32' = 'msvc';
|
|
|
|
'winuwp' = 'msvc';
|
|
|
|
'linux' = 'gcc';
|
2023-06-29 19:46:52 +08:00
|
|
|
'android' = 'ndk';
|
2023-06-30 16:53:20 +08:00
|
|
|
'osx' = 'xcode';
|
|
|
|
'ios' = 'xcode';
|
|
|
|
'tvos' = 'xcode';
|
2023-06-29 19:46:52 +08:00
|
|
|
'watchos' = 'xcode';
|
2023-09-01 16:31:14 +08:00
|
|
|
'wasm' = 'emcc'; # wasm llvm-emcc
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
if (!$TOOLCHAIN) {
|
|
|
|
$TOOLCHAIN = $toolchains[$BUILD_TARGET]
|
|
|
|
}
|
|
|
|
$TOOLCHAIN_INFO = $TOOLCHAIN.Split('-')
|
|
|
|
$TOOLCHAIN_VER = $null
|
|
|
|
if ($TOOLCHAIN_INFO.Count -ge 2) {
|
|
|
|
$toolVer = $TOOLCHAIN_INFO[$TOOLCHAIN_INFO.Count - 1]
|
|
|
|
if ($toolVer -match "\d+") {
|
|
|
|
$TOOLCHAIN_NAME = $TOOLCHAIN_INFO[0..($TOOLCHAIN_INFO.Count - 2)] -join '-'
|
|
|
|
$TOOLCHAIN_VER = $toolVer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$TOOLCHAIN_VER) {
|
|
|
|
$TOOLCHAIN_NAME = $TOOLCHAIN
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
$prefix = if ($options.prefix) { $options.prefix } else { Join-Path $HOME 'build1k' }
|
2023-07-15 00:21:23 +08:00
|
|
|
if (!$b1k.isdir($prefix)) {
|
|
|
|
$b1k.mkdirs($prefix)
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("proj_dir=$((Get-Location).Path), prefix=$prefix")
|
2023-07-02 00:53:41 +08:00
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $params = @('--version'), $silent = $false) {
|
2023-07-02 00:53:41 +08:00
|
|
|
if ($path) {
|
|
|
|
$storedPATH = $env:PATH
|
2023-07-06 12:18:33 +08:00
|
|
|
if ($mode -eq 'ONLY') {
|
|
|
|
$env:PATH = $path
|
|
|
|
}
|
|
|
|
elseif ($mode -eq 'BOTH') {
|
|
|
|
$env:PATH = "$path$envPathSep$env:PATH"
|
|
|
|
}
|
2023-07-02 00:53:41 +08:00
|
|
|
}
|
2023-07-09 23:27:24 +08:00
|
|
|
else {
|
|
|
|
$storedPATH = $null
|
|
|
|
}
|
2023-07-02 00:53:41 +08:00
|
|
|
if (!$cmd) { $cmd = $name }
|
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
$params = [array]$params
|
|
|
|
|
2023-07-02 00:53:41 +08:00
|
|
|
# try get match expr and preferred ver
|
|
|
|
$checkVerCond = $null
|
|
|
|
$requiredMin = ''
|
|
|
|
$preferredVer = ''
|
2023-08-25 16:57:54 +08:00
|
|
|
$requiredVer = $manifest[$name]
|
|
|
|
if ($requiredVer) {
|
2023-07-02 00:53:41 +08:00
|
|
|
$preferredVer = $null
|
|
|
|
if ($requiredVer.EndsWith('+')) {
|
|
|
|
$preferredVer = $requiredVer.TrimEnd('+')
|
|
|
|
$checkVerCond = '$foundVer -ge $preferredVer'
|
|
|
|
}
|
|
|
|
elseif ($requiredVer -eq '*') {
|
|
|
|
$checkVerCond = '$True'
|
2023-07-02 01:01:46 +08:00
|
|
|
$preferredVer = 'latest'
|
2023-07-02 00:53:41 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$verArr = $requiredVer.Split('~')
|
|
|
|
$isRange = $verArr.Count -gt 1
|
|
|
|
$preferredVer = $verArr[$isRange]
|
|
|
|
if ($isRange -gt 1) {
|
|
|
|
$requiredMin = $verArr[0]
|
|
|
|
$checkVerCond = '$foundVer -ge $requiredMin -and $foundVer -le $preferredVer'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$checkVerCond = '$foundVer -eq $preferredVer'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$checkVerCond) {
|
|
|
|
throw "Invalid tool $name=$requiredVer in manifest"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# find command
|
2023-07-02 10:04:00 +08:00
|
|
|
$cmd_info = (Get-Command $cmd -ErrorAction SilentlyContinue)
|
2023-07-09 23:27:24 +08:00
|
|
|
|
|
|
|
# needs restore immidiately since further cmd invoke maybe require system bins
|
|
|
|
if ($path) {
|
|
|
|
$env:PATH = "$path$envPathSep$storedPATH"
|
|
|
|
}
|
|
|
|
|
2023-07-02 00:53:41 +08:00
|
|
|
$found_rets = $null # prog_path,prog_version
|
2023-07-02 10:04:00 +08:00
|
|
|
if ($cmd_info) {
|
|
|
|
$prog_path = $cmd_info.Source
|
2023-07-15 00:21:23 +08:00
|
|
|
$verStr = $(. $cmd @params 2>$null) | Select-Object -First 1
|
2023-07-02 10:48:59 +08:00
|
|
|
if (!$verStr -or ($verStr.IndexOf('--version') -ne -1)) {
|
|
|
|
$verInfo = $cmd_info.Version
|
2023-09-13 16:00:33 +08:00
|
|
|
$verStr = "$($verInfo.Major).$($verInfo.Minor).$($verInfo.Build)"
|
2023-07-02 10:04:00 +08:00
|
|
|
}
|
2023-07-02 10:48:59 +08:00
|
|
|
|
2023-07-02 00:53:41 +08:00
|
|
|
# full pattern: '(\d+\.)+(\*|\d+)(\-[a-z]+[0-9]*)?' can match x.y.z-rc3, but not require for us
|
|
|
|
$matchInfo = [Regex]::Match($verStr, '(\d+\.)+(-)?(\*|\d+)')
|
|
|
|
$foundVer = $matchInfo.Value
|
|
|
|
[void]$requiredMin
|
|
|
|
if ($checkVerCond) {
|
|
|
|
$matched = Invoke-Expression $checkVerCond
|
|
|
|
if ($matched) {
|
2023-08-25 16:57:54 +08:00
|
|
|
if (!$silent) { $b1k.println("Using ${name}: $prog_path, version: $foundVer") }
|
2023-07-02 00:53:41 +08:00
|
|
|
$found_rets = $prog_path, $foundVer
|
|
|
|
}
|
|
|
|
else {
|
2023-08-25 16:57:54 +08:00
|
|
|
# if (!$silent) { $b1k.println("The installed ${name}: $prog_path, version: $foundVer not match required: $requiredVer") }
|
2023-07-02 00:53:41 +08:00
|
|
|
$found_rets = $null, $preferredVer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-08-25 16:57:54 +08:00
|
|
|
if (!$silent) { $b1k.println("Using ${name}: $prog_path, version: $foundVer") }
|
2023-07-02 00:53:41 +08:00
|
|
|
$found_rets = $prog_path, $foundVer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($preferredVer) {
|
2023-08-25 16:57:54 +08:00
|
|
|
# if (!$silent) { $b1k.println("Not found $name, needs install: $preferredVer") }
|
2023-07-02 00:53:41 +08:00
|
|
|
$found_rets = $null, $preferredVer
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw "Not found $name, and it's not in manifest"
|
|
|
|
}
|
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-07-10 14:24:08 +08:00
|
|
|
if ($storedPATH) {
|
2023-07-02 00:53:41 +08:00
|
|
|
$env:PATH = $storedPATH
|
|
|
|
}
|
2023-07-09 23:27:24 +08:00
|
|
|
|
2023-07-02 00:53:41 +08:00
|
|
|
return $found_rets
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function exec_prog($prog, $params) {
|
|
|
|
# & $prog_name $params
|
|
|
|
for ($i = 0; $i -lt $params.Count; $i++) {
|
|
|
|
$param = "'"
|
|
|
|
$param += $params[$i]
|
|
|
|
$param += "'"
|
|
|
|
$params[$i] = $param
|
|
|
|
}
|
|
|
|
$strParams = "$params"
|
|
|
|
return Invoke-Expression -Command "$prog $strParams"
|
|
|
|
}
|
|
|
|
|
|
|
|
function download_file($url, $out) {
|
2023-09-03 11:47:36 +08:00
|
|
|
if ($b1k.isfile($out)) { return }
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Downloading $url to $out ...")
|
2023-09-13 03:37:49 +08:00
|
|
|
if ([System.Version]$pwsh_ver -ge [System.Version]'7.0.0.0') {
|
2023-06-29 19:46:52 +08:00
|
|
|
curl -L $url -o $out
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-06-29 19:46:52 +08:00
|
|
|
Invoke-WebRequest -Uri $url -OutFile $out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
function download_and_expand($url, $out, $dest) {
|
|
|
|
download_file $url $out
|
2023-09-03 11:47:36 +08:00
|
|
|
if ($out.EndsWith('.zip')) {
|
2023-08-25 16:57:54 +08:00
|
|
|
Expand-Archive -Path $out -DestinationPath $dest
|
2023-09-03 11:47:36 +08:00
|
|
|
}
|
|
|
|
elseif ($out.EndsWith('.tar.gz')) {
|
2023-08-25 16:57:54 +08:00
|
|
|
if (!$dest.EndsWith('/')) {
|
|
|
|
$b1k.mkdirs($dest)
|
|
|
|
}
|
2023-09-03 11:47:36 +08:00
|
|
|
tar xf "$out" -C $dest
|
|
|
|
}
|
|
|
|
elseif ($out.EndsWith('.sh')) {
|
2023-08-25 16:57:54 +08:00
|
|
|
chmod 'u+x' "$out"
|
|
|
|
$b1k.mkdirs($dest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# setup nuget, not add to path
|
|
|
|
function setup_nuget() {
|
|
|
|
if (!$manifest['nuget']) { return $null }
|
|
|
|
$nuget_bin = Join-Path $prefix 'nuget'
|
|
|
|
$nuget_prog, $nuget_ver = find_prog -name 'nuget' -path $nuget_bin -mode 'BOTH'
|
|
|
|
if ($nuget_prog) {
|
|
|
|
return $nuget_prog
|
|
|
|
}
|
|
|
|
|
|
|
|
$b1k.rmdirs($nuget_bin)
|
|
|
|
$b1k.mkdirs($nuget_bin)
|
|
|
|
|
|
|
|
$nuget_prog = Join-Path $nuget_bin 'nuget.exe'
|
2023-09-13 03:37:49 +08:00
|
|
|
download_file "https://dist.nuget.org/win-x86-commandline/v$nuget_ver/nuget.exe" $nuget_prog
|
2023-08-25 16:57:54 +08:00
|
|
|
|
|
|
|
if ($b1k.isfile($nuget_prog)) {
|
|
|
|
$b1k.println("Using nuget: $nuget_prog, version: $nuget_ver")
|
|
|
|
return $nuget_prog
|
|
|
|
}
|
|
|
|
|
|
|
|
throw "Install nuget fail"
|
|
|
|
}
|
|
|
|
|
|
|
|
# setup glslcc, not add to path
|
|
|
|
function setup_glslcc() {
|
|
|
|
if (!$manifest['glslcc']) { return $null }
|
|
|
|
$glslcc_bin = Join-Path $prefix 'glslcc'
|
|
|
|
$glslcc_prog, $glslcc_ver = find_prog -name 'glslcc' -path $glslcc_bin -mode 'BOTH'
|
|
|
|
if ($glslcc_prog) {
|
|
|
|
return $glslcc_prog
|
|
|
|
}
|
|
|
|
|
|
|
|
$suffix = $('win64.zip', 'linux.tar.gz', 'osx.tar.gz').Get($HOST_OS)
|
|
|
|
$b1k.rmdirs($glslcc_bin)
|
|
|
|
$glslcc_pkg = "$prefix/glslcc-$suffix"
|
|
|
|
$b1k.del($glslcc_pkg)
|
|
|
|
|
|
|
|
download_and_expand "https://github.com/axmolengine/glslcc/releases/download/v$glslcc_ver/glslcc-$glslcc_ver-$suffix" "$glslcc_pkg" $glslcc_bin
|
|
|
|
|
|
|
|
$glslcc_prog = (Join-Path $glslcc_bin "glslcc$exeSuffix")
|
|
|
|
if ($b1k.isfile($glslcc_prog)) {
|
|
|
|
$b1k.println("Using glslcc: $glslcc_prog, version: $glslcc_ver")
|
|
|
|
return $glslcc_prog
|
|
|
|
}
|
|
|
|
|
|
|
|
throw "Install glslcc fail"
|
|
|
|
}
|
|
|
|
|
2023-09-13 16:00:33 +08:00
|
|
|
function setup_ninja() {
|
|
|
|
if (!$manifest['ninja']) { return $null }
|
|
|
|
$suffix = $('win', 'linux', 'mac').Get($HOST_OS)
|
|
|
|
$ninja_bin = Join-Path $prefix 'ninja'
|
|
|
|
$ninja_prog, $ninja_ver = find_prog -name 'ninja'
|
|
|
|
if ($ninja_prog) {
|
|
|
|
return $ninja_prog
|
|
|
|
}
|
|
|
|
|
|
|
|
$ninja_prog, $ninja_ver = find_prog -name 'ninja' -path $ninja_bin -silent $true
|
|
|
|
if (!$ninja_prog) {
|
|
|
|
$ninja_pkg = "$prefix/ninja-$suffix.zip"
|
|
|
|
$b1k.rmdirs($ninja_bin)
|
|
|
|
$b1k.del($ninja_pkg)
|
2023-09-12 19:32:20 +08:00
|
|
|
|
2023-09-13 16:00:33 +08:00
|
|
|
download_and_expand "https://github.com/ninja-build/ninja/releases/download/v$ninja_ver/ninja-$suffix.zip" $ninja_pkg "$prefix/ninja/"
|
|
|
|
}
|
|
|
|
if ($env:PATH.IndexOf($ninja_bin) -eq -1) {
|
|
|
|
$env:PATH = "$ninja_bin$envPathSep$env:PATH"
|
|
|
|
}
|
|
|
|
$ninja_prog = (Join-Path $ninja_bin "ninja$exeSuffix")
|
2023-09-12 19:32:20 +08:00
|
|
|
|
2023-09-13 16:00:33 +08:00
|
|
|
$b1k.println("Using ninja: $ninja_prog, version: $ninja_ver")
|
|
|
|
return $ninja_prog
|
|
|
|
}
|
2023-09-12 19:32:20 +08:00
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
# setup cmake
|
2023-09-13 16:00:33 +08:00
|
|
|
function setup_cmake([switch]$Force = $false) {
|
|
|
|
$cmake_prog, $cmake_ver = find_prog -name 'cmake'
|
|
|
|
if ($cmake_prog -and !$Force) {
|
|
|
|
return $cmake_prog
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
|
|
|
|
$cmake_root = $(Join-Path $prefix 'cmake')
|
|
|
|
$cmake_bin = Join-Path $cmake_root 'bin'
|
|
|
|
$cmake_prog, $cmake_ver = find_prog -name 'cmake' -path $cmake_bin -mode 'ONLY' -silent $true
|
2023-09-03 11:47:36 +08:00
|
|
|
if (!$cmake_prog) {
|
2023-08-25 16:57:54 +08:00
|
|
|
$b1k.rmdirs($cmake_root)
|
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
$cmake_suffix = @(".zip", ".sh", ".tar.gz").Get($HOST_OS)
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmake_dev_hash = $channels['cmake']
|
|
|
|
if ($cmake_dev_hash) {
|
|
|
|
$cmake_ver = "$cmake_ver-$cmake_dev_hash"
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
if ($HOST_OS -ne $HOST_MAC) {
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmake_pkg_name = "cmake-$cmake_ver-$HOST_OS_NAME-x86_64"
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmake_pkg_name = "cmake-$cmake_ver-$HOST_OS_NAME-universal"
|
|
|
|
}
|
2023-08-25 16:49:08 +08:00
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmake_pkg_path = Join-Path $prefix "$cmake_pkg_name$cmake_suffix"
|
|
|
|
|
|
|
|
if (!$cmake_dev_hash) {
|
|
|
|
$cmake_url = "https://github.com/Kitware/CMake/releases/download/v$cmake_ver/$cmake_pkg_name$cmake_suffix"
|
2023-09-03 11:47:36 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmake_url = "https://cmake.org/files/dev/$cmake_pkg_name$cmake_suffix"
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmake_dir = Join-Path $prefix $cmake_pkg_name
|
|
|
|
if ($IsMacOS) {
|
|
|
|
$cmake_app_contents = Join-Path $cmake_dir 'CMake.app/Contents'
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
if (!$b1k.isdir($cmake_dir)) {
|
|
|
|
download_and_expand "$cmake_url" "$cmake_pkg_path" $prefix/
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
|
|
|
|
if ($b1k.isdir($cmake_dir)) {
|
|
|
|
$cmake_root0 = $cmake_dir
|
|
|
|
if ($IsMacOS) {
|
|
|
|
$cmake_app_contents = Join-Path $cmake_dir 'CMake.app/Contents'
|
|
|
|
if ($b1k.isdir($cmake_app_contents)) {
|
|
|
|
$cmake_root0 = $cmake_app_contents
|
|
|
|
}
|
|
|
|
sudo xattr -r -d com.apple.quarantine "$cmake_root0/bin/cmake"
|
2023-08-25 16:49:08 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
$b1k.mv($cmake_root0, $cmake_root)
|
|
|
|
|
|
|
|
if ($b1k.isdir($cmake_dir)) {
|
|
|
|
$b1k.rmdirs($cmake_dir)
|
|
|
|
}
|
2023-09-03 11:47:36 +08:00
|
|
|
}
|
|
|
|
elseif ($IsLinux) {
|
2023-09-01 01:17:49 +08:00
|
|
|
$b1k.mkdirs($cmake_root)
|
|
|
|
& "$cmake_pkg_path" '--skip-license' '--exclude-subdir' "--prefix=$cmake_root"
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
|
|
|
|
$cmake_prog, $_ = find_prog -name 'cmake' -path $cmake_bin -silent $true
|
|
|
|
if (!$cmake_prog) {
|
2023-07-02 00:53:41 +08:00
|
|
|
throw "Install cmake $cmake_ver fail"
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
2023-09-13 16:00:33 +08:00
|
|
|
|
|
|
|
$b1k.println("Using cmake: $cmake_prog, version: $cmake_ver")
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
if (($null -ne $cmake_bin) -and ($env:PATH.IndexOf($cmake_bin) -eq -1)) {
|
|
|
|
$env:PATH = "$cmake_bin$envPathSep$env:PATH"
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
2023-09-13 16:00:33 +08:00
|
|
|
return $cmake_prog
|
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
|
2023-09-13 16:00:33 +08:00
|
|
|
function ensure_cmake_ninja($cmake_prog, $ninja_prog) {
|
|
|
|
# ensure ninja in cmake_bin
|
|
|
|
$cmake_bin = Split-Path $cmake_prog -Parent
|
|
|
|
$cmake_ninja_prog,$__ = find_prog -name 'ninja' -path $cmake_bin -mode 'ONLY' -silent $true
|
|
|
|
if (!$cmake_ninja_prog) { #
|
|
|
|
$ninja_symlink_target = Join-Path $cmake_bin (Split-Path $ninja_prog -Leaf)
|
|
|
|
# try link ninja exist cmake bin directory
|
|
|
|
& "$myRoot\fsync.ps1" -s $ninja_prog -d $ninja_symlink_target -l $true 2>$null
|
|
|
|
}
|
|
|
|
return $?
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
function setup_nsis() {
|
2023-09-03 11:47:36 +08:00
|
|
|
if (!$manifest['nsis']) { return $null }
|
2023-08-25 16:57:54 +08:00
|
|
|
$nsis_bin = Join-Path $prefix "nsis"
|
2023-07-15 00:21:23 +08:00
|
|
|
$nsis_prog, $nsis_ver = find_prog -name 'nsis' -cmd 'makensis' -params '/VERSION'
|
|
|
|
if ($nsis_prog) {
|
|
|
|
return $nsis_prog
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$nsis_prog, $nsis_ver = find_prog -name 'nsis' -cmd 'makensis' -params '/VERSION' -path $nsis_bin -silent $true
|
|
|
|
if (!$nsis_prog) {
|
|
|
|
$b1k.rmdirs($nsis_bin)
|
|
|
|
|
|
|
|
download_and_expand "https://nchc.dl.sourceforge.net/project/nsis/NSIS%203/$nsis_ver/nsis-$nsis_ver.zip" "$prefix/nsis-$nsis_ver.zip" "$prefix"
|
|
|
|
$nsis_dir = "$nsis_bin-$nsis_ver"
|
2023-09-03 11:47:36 +08:00
|
|
|
if ($b1k.isdir($nsis_dir)) {
|
2023-08-25 16:57:54 +08:00
|
|
|
$b1k.mv($nsis_dir, $nsis_bin)
|
|
|
|
}
|
2023-07-15 00:21:23 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
if ($env:PATH.IndexOf($nsis_bin) -eq -1) {
|
|
|
|
$env:PATH = "$nsis_bin$envPathSep$env:PATH"
|
|
|
|
}
|
|
|
|
$nsis_prog = (Join-Path $nsis_bin "makensis$exeSuffix")
|
|
|
|
|
|
|
|
$b1k.println("Using nsis: $nsis_prog, version: $nsis_ver")
|
|
|
|
return $nsis_prog
|
|
|
|
}
|
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
function setup_jdk() {
|
2023-08-25 16:57:54 +08:00
|
|
|
if (!$manifest['jdk']) { return $null }
|
|
|
|
$suffix = $('windows-x64.zip', 'linux-x64.tar.gz', 'macOS-x64.tar.gz').Get($HOST_OS)
|
2023-07-02 00:53:41 +08:00
|
|
|
$javac_prog, $jdk_ver = find_prog -name 'jdk' -cmd 'javac'
|
2023-06-30 16:53:20 +08:00
|
|
|
if ($javac_prog) {
|
2023-07-02 00:53:41 +08:00
|
|
|
return $javac_prog
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$java_home = Join-Path $prefix "jdk"
|
|
|
|
$jdk_bin = Join-Path $java_home 'bin'
|
|
|
|
$javac_prog, $jdk_ver = find_prog -name 'jdk' -cmd 'javac' -path $jdk_bin -silent $true
|
2023-09-03 11:47:36 +08:00
|
|
|
if (!$javac_prog) {
|
2023-08-25 16:57:54 +08:00
|
|
|
$b1k.rmdirs($java_home)
|
2023-08-25 16:57:38 +08:00
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
# refer to https://learn.microsoft.com/en-us/java/openjdk/download
|
|
|
|
download_and_expand "https://aka.ms/download-jdk/microsoft-jdk-$jdk_ver-$suffix" "$prefix/microsoft-jdk-$jdk_ver-$suffix" "$prefix/"
|
|
|
|
|
2023-07-01 08:52:14 +08:00
|
|
|
# move to plain folder name
|
2023-07-06 12:18:33 +08:00
|
|
|
$folderName = (Get-ChildItem -Path $prefix -Filter "jdk-$jdk_ver+*").Name
|
2023-07-01 08:52:14 +08:00
|
|
|
if ($folderName) {
|
2023-08-25 16:57:54 +08:00
|
|
|
$b1k.mv("$prefix/$folderName", $java_home)
|
2023-07-01 08:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
|
2023-07-01 08:52:14 +08:00
|
|
|
$env:JAVA_HOME = $java_home
|
2023-07-02 00:53:41 +08:00
|
|
|
$env:CLASSPATH = ".;$java_home\lib\dt.jar;$java_home\lib\tools.jar"
|
2023-07-01 08:52:14 +08:00
|
|
|
if ($env:PATH.IndexOf($jdk_bin) -eq -1) {
|
|
|
|
$env:PATH = "$jdk_bin$envPathSep$env:PATH"
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
2023-08-25 16:57:54 +08:00
|
|
|
$javac_prog = find_prog -name 'javac' -path $jdk_bin -silent $true
|
2023-07-01 08:52:14 +08:00
|
|
|
if (!$javac_prog) {
|
|
|
|
throw "Install jdk $jdk_ver fail"
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Using jdk: $javac_prog, version: $jdk_ver")
|
2023-07-06 12:18:33 +08:00
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
return $javac_prog
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
function setup_clang() {
|
|
|
|
if (!$manifest.Contains('clang')) { return $null }
|
|
|
|
$clang_prog, $clang_ver = find_prog -name 'clang'
|
|
|
|
if (!$clang_prog) {
|
|
|
|
throw 'required clang $clang_ver not installed, please install it from: https://github.com/llvm/llvm-project/releases'
|
2023-08-25 16:57:38 +08:00
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup_android_sdk() {
|
2023-08-25 16:57:54 +08:00
|
|
|
if (!$manifest['ndk']) { return $null }
|
2023-06-29 19:46:52 +08:00
|
|
|
# setup ndk
|
|
|
|
$ndk_ver = $TOOLCHAIN_VER
|
|
|
|
if (!$ndk_ver) {
|
2023-07-02 00:53:41 +08:00
|
|
|
$ndk_ver = $manifest['ndk']
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-07-01 08:52:14 +08:00
|
|
|
$IsGraterThan = if ($ndk_ver.EndsWith('+')) { '+' } else { $null }
|
2023-06-30 16:53:20 +08:00
|
|
|
if ($IsGraterThan) {
|
2023-06-29 19:46:52 +08:00
|
|
|
$ndk_ver = $ndk_ver.Substring(0, $ndk_ver.Length - 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
$sdk_root_envs = @('ANDROID_HOME', 'ANDROID_SDK_ROOT')
|
|
|
|
|
|
|
|
$ndk_minor_base = [int][char]'a'
|
2023-06-30 16:53:20 +08:00
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
# looking up require ndk installed in exists sdk roots
|
|
|
|
$sdk_root = $null
|
2023-06-30 16:53:20 +08:00
|
|
|
foreach ($sdk_root_env in $sdk_root_envs) {
|
2023-06-29 19:46:52 +08:00
|
|
|
$sdk_dir = [Environment]::GetEnvironmentVariable($sdk_root_env)
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Looking require $ndk_ver$IsGraterThan in env:$sdk_root_env=$sdk_dir")
|
2023-06-30 16:53:20 +08:00
|
|
|
if ("$sdk_dir" -ne '') {
|
2023-06-29 19:46:52 +08:00
|
|
|
$sdk_root = $sdk_dir
|
|
|
|
$ndk_root = $null
|
|
|
|
|
|
|
|
$ndk_major = ($ndk_ver -replace '[^0-9]', '')
|
|
|
|
$ndk_minor_off = "$ndk_major".Length + 1
|
2023-06-30 16:53:20 +08:00
|
|
|
$ndk_minor = if ($ndk_minor_off -lt $ndk_ver.Length) { "$([int][char]$ndk_ver.Substring($ndk_minor_off) - $ndk_minor_base)" } else { '0' }
|
2023-06-29 19:46:52 +08:00
|
|
|
$ndk_rev_base = "$ndk_major.$ndk_minor"
|
|
|
|
|
2023-07-09 20:42:51 +08:00
|
|
|
$ndk_parent = Join-Path $sdk_dir 'ndk'
|
2023-07-15 00:21:23 +08:00
|
|
|
if (!$b1k.isdir($ndk_parent)) {
|
2023-07-09 20:42:51 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
# find ndk in sdk
|
|
|
|
$ndks = [ordered]@{}
|
|
|
|
$ndk_rev_max = '0.0'
|
2023-07-09 20:42:51 +08:00
|
|
|
foreach ($item in $(Get-ChildItem -Path "$ndk_parent")) {
|
2023-06-29 19:46:52 +08:00
|
|
|
$ndkDir = $item.FullName
|
|
|
|
$sourceProps = "$ndkDir/source.properties"
|
2023-07-15 00:21:23 +08:00
|
|
|
if ($b1k.isfile($sourceProps)) {
|
2023-06-29 19:46:52 +08:00
|
|
|
$verLine = $(Get-Content $sourceProps | Select-Object -Index 1)
|
|
|
|
$ndk_rev = $($verLine -split '=').Trim()[1].split('.')[0..1] -join '.'
|
|
|
|
$ndks.Add($ndk_rev, $ndkDir)
|
|
|
|
if ($ndk_rev_max -le $ndk_rev) {
|
|
|
|
$ndk_rev_max = $ndk_rev
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($IsGraterThan) {
|
|
|
|
if ($ndk_rev_max -ge $ndk_rev_base) {
|
|
|
|
$ndk_root = $ndks[$ndk_rev_max]
|
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-06-29 19:46:52 +08:00
|
|
|
$ndk_root = $ndks[$ndk_rev_base]
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($null -ne $ndk_root) {
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Found $ndk_root in $sdk_root ...")
|
2023-06-29 19:46:52 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-15 00:21:23 +08:00
|
|
|
if (!$b1k.isdir("$ndk_root")) {
|
2023-07-02 00:53:41 +08:00
|
|
|
$sdkmanager_prog, $sdkmanager_ver = $null, $null
|
2023-07-15 00:21:23 +08:00
|
|
|
if ($b1k.isdir($sdk_root)) {
|
|
|
|
$sdkmanager_prog, $sdkmanager_ver = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$sdk_root/cmdline-tools/latest/bin" -params "--version", "--sdk_root=$sdk_root")
|
2023-07-02 00:53:41 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-07-06 12:18:33 +08:00
|
|
|
$sdk_root = Join-Path $prefix 'adt/sdk'
|
2023-07-15 00:21:23 +08:00
|
|
|
if (!$b1k.isdir($sdk_root)) {
|
|
|
|
$b1k.mkdirs($sdk_root)
|
2023-07-02 00:53:41 +08:00
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
if (!$sdkmanager_prog) {
|
2023-07-15 00:21:23 +08:00
|
|
|
$sdkmanager_prog, $sdkmanager_ver = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$prefix/cmdline-tools/bin" -params "--version", "--sdk_root=$sdk_root")
|
2023-06-29 19:46:52 +08:00
|
|
|
$suffix = $('win', 'linux', 'mac').Get($HOST_OS)
|
|
|
|
if (!$sdkmanager_prog) {
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Installing cmdlinetools version: $sdkmanager_ver ...")
|
2023-07-02 00:53:41 +08:00
|
|
|
|
|
|
|
$cmdlinetools_pkg_name = "commandlinetools-$suffix-$($cmdlinetools_rev)_latest.zip"
|
2023-07-06 12:18:33 +08:00
|
|
|
$cmdlinetools_pkg_path = Join-Path $prefix $cmdlinetools_pkg_name
|
2023-06-29 19:46:52 +08:00
|
|
|
$cmdlinetools_url = "https://dl.google.com/android/repository/$cmdlinetools_pkg_name"
|
|
|
|
download_file $cmdlinetools_url $cmdlinetools_pkg_path
|
2023-07-06 12:18:33 +08:00
|
|
|
Expand-Archive -Path $cmdlinetools_pkg_path -DestinationPath "$prefix/"
|
2023-07-15 00:21:23 +08:00
|
|
|
$sdkmanager_prog, $_ = (find_prog -name 'cmdlinetools' -cmd 'sdkmanager' -path "$prefix/cmdline-tools/bin" -params "--version", "--sdk_root=$sdk_root" -silent $True)
|
2023-06-29 19:46:52 +08:00
|
|
|
if (!$sdkmanager_prog) {
|
2023-07-02 00:53:41 +08:00
|
|
|
throw "Install cmdlinetools version: $sdkmanager_ver fail"
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
$matchInfos = (exec_prog -prog $sdkmanager_prog -params "--sdk_root=$sdk_root", '--list' | Select-String 'ndk;')
|
2023-06-29 19:46:52 +08:00
|
|
|
if ($null -ne $matchInfos -and $matchInfos.Count -gt 0) {
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Not found suitable android ndk, installing ...")
|
2023-06-30 17:26:24 +08:00
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
$ndks = @{}
|
2023-06-30 16:53:20 +08:00
|
|
|
foreach ($matchInfo in $matchInfos) {
|
2023-06-29 19:46:52 +08:00
|
|
|
$fullVer = $matchInfo.Line.Trim().Split(' ')[0] # "ndk;23.2.8568313"
|
|
|
|
$verNums = $fullVer.Split(';')[1].Split('.')
|
|
|
|
$ndkVer = 'r'
|
|
|
|
$ndkVer += $verNums[0]
|
|
|
|
|
|
|
|
$ndk_minor = [int]$verNums[1]
|
|
|
|
if ($ndk_minor -gt 0) {
|
|
|
|
$ndkVer += [char]($ndk_minor_base + $ndk_minor)
|
|
|
|
}
|
|
|
|
if (!$ndks.Contains($ndkVer)) {
|
|
|
|
$ndks.Add($ndkVer, $fullVer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ndkFullVer = $ndks[$ndk_ver]
|
|
|
|
|
2023-07-10 14:24:08 +08:00
|
|
|
((1..10 | ForEach-Object { "yes"; Start-Sleep -Milliseconds 100 }) | . $sdkmanager_prog --licenses --sdk_root=$sdk_root) | Out-Host
|
2023-06-30 16:53:20 +08:00
|
|
|
exec_prog -prog $sdkmanager_prog -params '--verbose', "--sdk_root=$sdk_root", 'platform-tools', 'cmdline-tools;latest', 'platforms;android-33', 'build-tools;30.0.3', 'cmake;3.22.1', $ndkFullVer | Out-Host
|
2023-06-29 19:46:52 +08:00
|
|
|
|
|
|
|
$fullVer = $ndkFullVer.Split(';')[1]
|
|
|
|
$ndk_root = (Resolve-Path -Path "$sdk_root/ndk/$fullVer").Path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
return $sdk_root, $ndk_root
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-09-01 16:31:14 +08:00
|
|
|
# enable emsdk emcmake
|
|
|
|
function setup_emsdk() {
|
|
|
|
$emsdk_cmd = (Get-Command emsdk -ErrorAction SilentlyContinue)
|
|
|
|
if (!$emsdk_cmd) {
|
|
|
|
$emsdk_root = Join-Path $prefix 'emsdk'
|
|
|
|
if (!(Test-Path $emsdk_root -PathType Container)) {
|
|
|
|
git clone 'https://github.com/emscripten-core/emsdk.git' $emsdk_root
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
git -C $emsdk_root pull
|
|
|
|
}
|
2023-09-03 11:47:36 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-09-01 16:31:14 +08:00
|
|
|
$emsdk_root = Split-Path $emsdk_cmd.Source -Parent
|
|
|
|
}
|
|
|
|
|
|
|
|
$emcmake = (Get-Command emcmake -ErrorAction SilentlyContinue)
|
|
|
|
if (!$emcmake) {
|
2023-09-14 19:04:08 +08:00
|
|
|
$emsdk_ver = $manifest['emsdk']
|
2023-09-14 15:35:08 +08:00
|
|
|
Push-Location $emsdk_root
|
2023-09-14 19:04:08 +08:00
|
|
|
./emsdk install $emsdk_ver
|
|
|
|
./emsdk activate $emsdk_ver
|
2023-09-01 16:31:14 +08:00
|
|
|
. ./emsdk_env.ps1
|
2023-09-14 15:35:08 +08:00
|
|
|
Pop-Location
|
2023-09-01 16:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
# preprocess methods:
|
|
|
|
# <param>-inputOptions</param> [CMAKE_OPTIONS]
|
|
|
|
function preprocess_win([string[]]$inputOptions) {
|
|
|
|
$outputOptions = $inputOptions
|
|
|
|
|
2023-08-30 08:34:33 +08:00
|
|
|
if ($options.sdk) {
|
|
|
|
$outputOptions += "-DCMAKE_SYSTEM_VERSION=$($options.sdk)"
|
2023-07-02 21:23:56 +08:00
|
|
|
}
|
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
if ($TOOLCHAIN_NAME -eq 'msvc') {
|
|
|
|
# Generate vs2019 on github ci
|
2023-06-29 19:46:52 +08:00
|
|
|
# Determine arch name
|
2023-06-30 16:53:20 +08:00
|
|
|
$arch = if ($options.a -eq 'x86') { 'Win32' } else { $options.a }
|
2023-06-29 19:46:52 +08:00
|
|
|
|
|
|
|
$VSWHERE_EXE = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
|
|
|
$eap = $ErrorActionPreference
|
|
|
|
$ErrorActionPreference = 'SilentlyContinue'
|
|
|
|
$VS2019_OR_LATER_VESION = $null
|
|
|
|
$VS2019_OR_LATER_VESION = (& $VSWHERE_EXE -version '16.0' -property installationVersion)
|
|
|
|
$ErrorActionPreference = $eap
|
|
|
|
|
|
|
|
# arch
|
2023-06-30 16:53:20 +08:00
|
|
|
if ($VS2019_OR_LATER_VESION) {
|
2023-06-29 19:46:52 +08:00
|
|
|
$outputOptions += '-A', $arch
|
|
|
|
if ($TOOLCHAIN_VER) {
|
|
|
|
$outputOptions += "-Tv$TOOLCHAIN_VER"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$gens = @{
|
|
|
|
'120' = 'Visual Studio 12 2013';
|
|
|
|
'140' = 'Visual Studio 14 2015'
|
|
|
|
"150" = 'Visual Studio 15 2017';
|
|
|
|
}
|
|
|
|
$gen = $gens[$TOOLCHAIN_VER]
|
2023-06-30 16:53:20 +08:00
|
|
|
if (!$gen) {
|
2023-06-29 19:46:52 +08:00
|
|
|
throw "Unsupported toolchain: $TOOLCHAIN"
|
|
|
|
}
|
|
|
|
if ($options.a -eq "x64") {
|
|
|
|
$gen += ' Win64'
|
|
|
|
}
|
|
|
|
$outputOptions += '-G', $gen
|
|
|
|
}
|
|
|
|
|
|
|
|
# platform
|
|
|
|
if ($BUILD_TARGET -eq "winuwp") {
|
|
|
|
'-DCMAKE_SYSTEM_NAME=WindowsStore', '-DCMAKE_SYSTEM_VERSION=10.0'
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($options.dll) {
|
|
|
|
$outputOptions += '-DBUILD_SHARED_LIBS=TRUE'
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
elseif ($TOOLCHAIN_NAME -eq 'clang') {
|
2023-06-29 19:46:52 +08:00
|
|
|
$outputOptions += '-G', 'Ninja Multi-Config', '-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++'
|
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
else {
|
|
|
|
# Generate mingw
|
2023-06-29 19:46:52 +08:00
|
|
|
$outputOptions += '-G', 'Ninja Multi-Config'
|
|
|
|
}
|
|
|
|
return $outputOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
function preprocess_linux([string[]]$inputOptions) {
|
|
|
|
$outputOptions = $inputOptions
|
|
|
|
return $outputOptions
|
|
|
|
}
|
|
|
|
|
2023-07-02 00:53:41 +08:00
|
|
|
$ninja_prog = $null
|
2023-08-30 08:34:33 +08:00
|
|
|
$is_gradlew = $options.xt.IndexOf('gradlew') -ne -1
|
2023-06-29 19:46:52 +08:00
|
|
|
function preprocess_andorid([string[]]$inputOptions) {
|
|
|
|
$outputOptions = $inputOptions
|
|
|
|
|
2023-06-30 16:53:20 +08:00
|
|
|
$t_archs = @{arm64 = 'arm64-v8a'; armv7 = 'armeabi-v7a'; x64 = 'x86_64'; x86 = 'x86'; }
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-08-30 08:34:33 +08:00
|
|
|
if ($is_gradlew) {
|
2023-06-30 16:53:20 +08:00
|
|
|
if ($options.a.GetType() -eq [object[]]) {
|
|
|
|
$archlist = [string[]]$options.a
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$archlist = $options.a.Split(';')
|
|
|
|
}
|
|
|
|
for ($i = 0; $i -lt $archlist.Count; ++$i) {
|
|
|
|
$arch = $archlist[$i]
|
|
|
|
$archlist[$i] = $t_archs[$arch]
|
|
|
|
}
|
|
|
|
|
|
|
|
$archs = $archlist -join ':' # TODO: modify gradle, split by ';'
|
|
|
|
|
2023-09-13 16:00:33 +08:00
|
|
|
$outputOptions += "-PPROP_CMAKE_VERSION=$($manifest['cmake'])"
|
2023-06-30 16:53:20 +08:00
|
|
|
$outputOptions += "-PPROP_APP_ABI=$archs"
|
|
|
|
$outputOptions += '--parallel', '--info'
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
else {
|
|
|
|
$cmake_toolchain_file = "$ndk_root\build\cmake\android.toolchain.cmake"
|
|
|
|
$arch = $t_archs[$options.a]
|
|
|
|
$outputOptions += '-G', 'Ninja', '-DANDROID_STL=c++_shared', "-DCMAKE_MAKE_PROGRAM=$ninja_prog", "-DCMAKE_TOOLCHAIN_FILE=$cmake_toolchain_file", "-DANDROID_ABI=$arch"
|
2023-07-09 23:27:24 +08:00
|
|
|
# If set to ONLY, then only the roots in CMAKE_FIND_ROOT_PATH will be searched
|
|
|
|
# If set to BOTH, then the host system paths and the paths in CMAKE_FIND_ROOT_PATH will be searched
|
|
|
|
# If set to NEVER, then the roots in CMAKE_FIND_ROOT_PATH will be ignored and only the host system root will be used
|
2023-06-30 16:53:20 +08:00
|
|
|
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH'
|
|
|
|
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH'
|
|
|
|
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH'
|
|
|
|
# by default, we want find host program only when cross-compiling
|
|
|
|
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER'
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $outputOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
function preprocess_osx([string[]]$inputOptions) {
|
|
|
|
$outputOptions = $inputOptions
|
|
|
|
$arch = $options.a
|
|
|
|
if ($arch -eq 'x64') {
|
|
|
|
$arch = 'x86_64'
|
|
|
|
}
|
|
|
|
|
|
|
|
$outputOptions += '-GXcode', "-DCMAKE_OSX_ARCHITECTURES=$arch"
|
|
|
|
return $outputOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
# build ios famliy (ios,tvos,watchos)
|
|
|
|
function preprocess_ios([string[]]$inputOptions) {
|
|
|
|
$outputOptions = $inputOptions
|
|
|
|
$arch = $options.a
|
|
|
|
if ($arch -eq 'x64') {
|
|
|
|
$arch = 'x86_64'
|
|
|
|
}
|
2023-07-03 20:01:56 +08:00
|
|
|
$cmake_toolchain_file = Join-Path $myRoot 'ios.cmake'
|
2023-06-29 19:46:52 +08:00
|
|
|
$outputOptions += '-GXcode', "-DCMAKE_TOOLCHAIN_FILE=$cmake_toolchain_file", "-DARCHS=$arch"
|
|
|
|
if ($BUILD_TARGET -eq 'tvos') {
|
|
|
|
$outputOptions += '-DPLAT=tvOS'
|
|
|
|
}
|
|
|
|
elseif ($BUILD_TARGET -eq 'watchos') {
|
|
|
|
$outputOptions += '-DPLAT=watchOS'
|
|
|
|
}
|
|
|
|
return $outputOptions
|
|
|
|
}
|
|
|
|
|
2023-09-01 16:31:14 +08:00
|
|
|
function preprocess_wasm([string[]]$inputOptions) {
|
|
|
|
return $inputOptions
|
|
|
|
}
|
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
function validHostAndToolchain() {
|
|
|
|
$appleTable = @{
|
2023-06-30 16:53:20 +08:00
|
|
|
'host' = @{'macos' = $True };
|
2023-06-29 19:46:52 +08:00
|
|
|
'toolchain' = @{'xcode' = $True; };
|
|
|
|
};
|
|
|
|
$validTable = @{
|
2023-06-30 16:53:20 +08:00
|
|
|
'win32' = @{
|
|
|
|
'host' = @{'windows' = $True };
|
|
|
|
'toolchain' = @{'msvc' = $True; 'clang' = $True; 'mingw-gcc' = $True };
|
2023-06-29 19:46:52 +08:00
|
|
|
};
|
2023-06-30 16:53:20 +08:00
|
|
|
'winuwp' = @{
|
|
|
|
'host' = @{'windows' = $True };
|
2023-06-29 19:46:52 +08:00
|
|
|
'toolchain' = @{'msvc' = $True; };
|
|
|
|
};
|
2023-06-30 16:53:20 +08:00
|
|
|
'linux' = @{
|
|
|
|
'host' = @{'linux' = $True };
|
2023-06-29 19:46:52 +08:00
|
|
|
'toolchain' = @{'gcc' = $True; };
|
|
|
|
};
|
|
|
|
'android' = @{
|
2023-06-30 16:53:20 +08:00
|
|
|
'host' = @{'windows' = $True; 'linux' = $True; 'macos' = $True };
|
2023-06-29 19:46:52 +08:00
|
|
|
'toolchain' = @{'ndk' = $True; };
|
|
|
|
};
|
2023-06-30 16:53:20 +08:00
|
|
|
'osx' = $appleTable;
|
|
|
|
'ios' = $appleTable;
|
|
|
|
'tvos' = $appleTable;
|
2023-06-29 19:46:52 +08:00
|
|
|
'watchos' = $appleTable;
|
2023-09-03 11:47:36 +08:00
|
|
|
'wasm' = @{
|
2023-09-01 16:31:14 +08:00
|
|
|
'host' = @{'windows' = $True; 'linux' = $True; 'macos' = $True };
|
|
|
|
'toolchain' = @{'emcc' = $True; };
|
|
|
|
};
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
$validInfo = $validTable[$BUILD_TARGET]
|
|
|
|
$validOS = $validInfo.host[$HOST_OS_NAME]
|
|
|
|
if (!$validOS) {
|
|
|
|
throw "Can't build target $BUILD_TARGET on $HOST_OS_NAME"
|
|
|
|
}
|
|
|
|
$validToolchain = $validInfo.toolchain[$TOOLCHAIN_NAME]
|
2023-06-30 16:53:20 +08:00
|
|
|
if (!$validToolchain) {
|
2023-06-29 19:46:52 +08:00
|
|
|
throw "Can't build target $BUILD_TARGET with toolchain $TOOLCHAIN_NAME"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$proprocessTable = @{
|
2023-06-30 16:53:20 +08:00
|
|
|
'win32' = ${function:preprocess_win};
|
|
|
|
'winuwp' = ${function:preprocess_win};
|
|
|
|
'linux' = ${function:preprocess_linux};
|
2023-06-29 19:46:52 +08:00
|
|
|
'android' = ${function:preprocess_andorid};
|
2023-06-30 16:53:20 +08:00
|
|
|
'osx' = ${function:preprocess_osx};
|
|
|
|
'ios' = ${function:preprocess_ios};
|
|
|
|
'tvos' = ${function:preprocess_ios};
|
2023-06-29 19:46:52 +08:00
|
|
|
'watchos' = ${function:preprocess_ios};
|
2023-09-01 16:31:14 +08:00
|
|
|
'wasm' = ${Function:preprocess_wasm};
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
validHostAndToolchain
|
|
|
|
|
|
|
|
########## setup build tools if not installed #######
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$null = setup_glslcc
|
2023-07-06 12:18:33 +08:00
|
|
|
|
2023-09-13 16:00:33 +08:00
|
|
|
$cmake_prog = setup_cmake
|
2023-06-30 16:53:20 +08:00
|
|
|
|
2023-06-29 19:46:52 +08:00
|
|
|
if ($BUILD_TARGET -eq 'win32') {
|
2023-07-02 00:53:41 +08:00
|
|
|
$nuget_prog = setup_nuget
|
2023-08-25 16:57:54 +08:00
|
|
|
$nsis_prog = setup_nsis
|
2023-09-03 19:55:39 +08:00
|
|
|
if ($TOOLCHAIN_NAME -eq 'clang') {
|
2023-09-13 16:00:33 +08:00
|
|
|
$ninja_prog = setup_ninja
|
2023-07-02 10:23:12 +08:00
|
|
|
$null = setup_clang
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
}
|
2023-06-30 16:53:20 +08:00
|
|
|
elseif ($BUILD_TARGET -eq 'android') {
|
2023-09-13 16:00:33 +08:00
|
|
|
$ninja_prog = setup_ninja
|
2023-07-09 23:27:24 +08:00
|
|
|
$null = setup_jdk # setup android sdk cmdlinetools require jdk
|
2023-06-30 16:53:20 +08:00
|
|
|
$sdk_root, $ndk_root = setup_android_sdk
|
|
|
|
$env:ANDROID_HOME = $sdk_root
|
|
|
|
$env:ANDROID_NDK = $ndk_root
|
2023-09-13 16:00:33 +08:00
|
|
|
|
|
|
|
# ensure ninja in cmake_bin
|
|
|
|
if(!(ensure_cmake_ninja $cmake_prog $ninja_prog)) {
|
|
|
|
$cmake_prog = setup_cmake -Force
|
|
|
|
if(!(ensure_cmake_ninja $cmake_prog $ninja_prog)) {
|
|
|
|
throw "Ensure ninja in cmake bin directory fail"
|
|
|
|
}
|
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
2023-09-03 11:47:36 +08:00
|
|
|
elseif ($BUILD_TARGET -eq 'wasm') {
|
2023-09-01 16:31:14 +08:00
|
|
|
. setup_emsdk
|
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-08-30 08:34:33 +08:00
|
|
|
if (!$setupOnly) {
|
2023-07-06 12:18:33 +08:00
|
|
|
$stored_cwd = $(Get-Location).Path
|
|
|
|
if ($options.d) {
|
|
|
|
Set-Location $options.d
|
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-09-03 11:47:36 +08:00
|
|
|
# parsing build optimize flag from build_options
|
|
|
|
$buildOptions = [array]$options.xb
|
|
|
|
$nopts = $buildOptions.Count
|
|
|
|
$optimize_flag = $null
|
|
|
|
for ($i = 0; $i -lt $nopts; ++$i) {
|
|
|
|
$optv = $buildOptions[$i]
|
|
|
|
if ($optv -eq '--config') {
|
|
|
|
if ($i -lt ($nopts - 1)) {
|
|
|
|
$optimize_flag = $buildOptions[$i + 1]
|
|
|
|
++$i
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 19:56:50 +08:00
|
|
|
$BUILD_ALL_OPTIONS = @()
|
|
|
|
$BUILD_ALL_OPTIONS += $buildOptions
|
|
|
|
if (!$optimize_flag) {
|
|
|
|
$BUILD_ALL_OPTIONS += '--config', 'Release'
|
|
|
|
$optimize_flag = 'Release'
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
# enter building steps
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Building target $BUILD_TARGET on $HOST_OS_NAME with toolchain $TOOLCHAIN ...")
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
# step1. preprocess cross make options
|
|
|
|
$CONFIG_ALL_OPTIONS = [array]$(& $proprocessTable[$BUILD_TARGET] -inputOptions $CONFIG_DEFAULT_OPTIONS)
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
if (!$CONFIG_ALL_OPTIONS) {
|
|
|
|
$CONFIG_ALL_OPTIONS = @()
|
2023-06-29 19:46:52 +08:00
|
|
|
}
|
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
# step2. apply additional cross make options
|
|
|
|
$xopts = [array]$options.xc
|
|
|
|
if ($xopts.Count -gt 0) {
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("Apply additional cross make options: $($xopts), Count={0}" -f $xopts.Count)
|
2023-07-06 12:18:33 +08:00
|
|
|
$CONFIG_ALL_OPTIONS += $xopts
|
2023-07-04 09:20:56 +08:00
|
|
|
}
|
2023-07-06 12:18:33 +08:00
|
|
|
if ("$($xopts)".IndexOf('-B') -eq -1) {
|
2023-07-10 14:24:08 +08:00
|
|
|
$is_host_target = ($BUILD_TARGET -eq 'win32') -or ($BUILD_TARGET -eq 'linux') -or ($BUILD_TARGET -eq 'osx')
|
2023-09-03 11:47:36 +08:00
|
|
|
if ($is_host_target) {
|
|
|
|
# wheither building host target?
|
2023-07-10 14:24:08 +08:00
|
|
|
$BUILD_DIR = "build_$($options.a)"
|
2023-09-03 11:47:36 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-09-01 16:31:14 +08:00
|
|
|
$BUILD_DIR = "build_${BUILD_TARGET}"
|
|
|
|
if (!$is_wasm) {
|
|
|
|
$BUILD_DIR += "_$($options.a)"
|
|
|
|
}
|
2023-07-10 14:24:08 +08:00
|
|
|
}
|
2023-07-04 09:20:56 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-07-06 12:18:33 +08:00
|
|
|
foreach ($opt in $xopts) {
|
|
|
|
if ($opt.StartsWith('-B')) {
|
|
|
|
$BUILD_DIR = $opt.Substring(2).Trim()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2023-07-04 09:20:56 +08:00
|
|
|
}
|
2023-07-15 00:21:23 +08:00
|
|
|
$b1k.println("CONFIG_ALL_OPTIONS=$CONFIG_ALL_OPTIONS, Count={0}" -f $CONFIG_ALL_OPTIONS.Count)
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-08-30 08:34:33 +08:00
|
|
|
if (($BUILD_TARGET -eq 'android') -and $is_gradlew) {
|
|
|
|
$storedLocation = (Get-Location).Path
|
|
|
|
$build_tool = (Get-Command $options.xt).Source
|
|
|
|
$build_tool_dir = Split-Path $build_tool -Parent
|
|
|
|
Set-Location $build_tool_dir
|
2023-07-06 12:18:33 +08:00
|
|
|
if ($optimize_flag -eq 'Debug') {
|
2023-08-30 08:34:33 +08:00
|
|
|
& $build_tool assembleDebug $CONFIG_ALL_OPTIONS | Out-Host
|
2023-07-06 12:18:33 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-08-30 08:34:33 +08:00
|
|
|
& $build_tool assembleRelease $CONFIG_ALL_OPTIONS | Out-Host
|
2023-07-06 12:18:33 +08:00
|
|
|
}
|
2023-08-30 08:34:33 +08:00
|
|
|
Set-Location $storedLocation
|
2023-07-06 12:18:33 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
# step3. configure
|
2023-08-25 16:57:54 +08:00
|
|
|
|
|
|
|
$workDir = $(Get-Location).Path
|
|
|
|
|
|
|
|
$mainDep = Join-Path $workDir 'CMakeLists.txt'
|
2023-09-03 11:47:36 +08:00
|
|
|
if (!$b1k.isfile($mainDep)) {
|
2023-08-25 16:57:54 +08:00
|
|
|
throw "Missing CMakeLists.txt in $workDir"
|
|
|
|
}
|
|
|
|
|
2023-09-06 12:36:24 +08:00
|
|
|
if ($options.p -eq 'linux' -or $options.p -eq 'wasm') {
|
|
|
|
if($optimize_flag -eq 'Debug') {
|
|
|
|
$CONFIG_ALL_OPTIONS += '-DCMAKE_BUILD_TYPE=Debug'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$CONFIG_ALL_OPTIONS += '-DCMAKE_BUILD_TYPE=Release'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
$mainDepChanged = $false
|
|
|
|
# A Windows file time is a 64-bit value that represents the number of 100-nanosecond
|
|
|
|
$tempFileItem = Get-Item $mainDep
|
|
|
|
$lastWriteTime = $tempFileItem.LastWriteTime.ToFileTimeUTC()
|
|
|
|
$tempFile = Join-Path $BUILD_DIR 'b1k_cache.txt'
|
|
|
|
|
2023-09-06 12:36:24 +08:00
|
|
|
$storeHash = 0
|
2023-08-25 16:57:54 +08:00
|
|
|
if ($b1k.isfile($tempFile)) {
|
2023-09-06 12:36:24 +08:00
|
|
|
$storeHash = Get-Content $tempFile -Raw
|
2023-08-25 16:57:54 +08:00
|
|
|
}
|
2023-09-06 12:36:24 +08:00
|
|
|
$hashValue = $b1k.hash("$CONFIG_ALL_OPTIONS#$lastWriteTime")
|
|
|
|
$mainDepChanged = "$storeHash" -ne "$hashValue"
|
2023-08-25 16:57:54 +08:00
|
|
|
$cmakeCachePath = Join-Path $workDir "$BUILD_DIR/CMakeCache.txt"
|
2023-09-02 19:56:50 +08:00
|
|
|
|
2023-08-25 16:57:54 +08:00
|
|
|
if ($mainDepChanged -or !$b1k.isfile($cmakeCachePath)) {
|
2023-09-01 16:31:14 +08:00
|
|
|
if (!$is_wasm) {
|
|
|
|
cmake -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
|
2023-09-03 11:47:36 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-09-01 16:31:14 +08:00
|
|
|
emcmake cmake -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
|
|
|
|
}
|
2023-09-06 12:36:24 +08:00
|
|
|
Set-Content $tempFile $hashValue -NoNewline
|
2023-08-25 16:57:54 +08:00
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-08-30 08:34:33 +08:00
|
|
|
if (!$configOnly) {
|
2023-08-27 23:21:22 +08:00
|
|
|
# step4. build
|
|
|
|
# apply additional build options
|
2023-09-02 19:56:50 +08:00
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
|
2023-08-27 23:21:22 +08:00
|
|
|
$BUILD_ALL_OPTIONS += "--parallel"
|
|
|
|
if ($BUILD_TARGET -eq 'linux') {
|
|
|
|
$BUILD_ALL_OPTIONS += "$(nproc)"
|
|
|
|
}
|
|
|
|
if ($TOOLCHAIN_NAME -eq 'xcode') {
|
|
|
|
$BUILD_ALL_OPTIONS += '--', '-quiet'
|
2023-08-28 09:44:59 +08:00
|
|
|
if ($options.a -eq 'x64') {
|
2023-09-03 11:47:36 +08:00
|
|
|
switch ($options.p) {
|
2023-08-28 09:44:59 +08:00
|
|
|
'ios' { $BUILD_ALL_OPTIONS += '-sdk', 'iphonesimulator' }
|
|
|
|
'tvos' { $BUILD_ALL_OPTIONS += '-sdk', 'appletvsimulator' }
|
|
|
|
'watchos' { $BUILD_ALL_OPTIONS += '-sdk', 'watchsimulator' }
|
|
|
|
}
|
2023-08-28 09:34:54 +08:00
|
|
|
}
|
2023-08-27 23:21:22 +08:00
|
|
|
}
|
|
|
|
$b1k.println("BUILD_ALL_OPTIONS=$BUILD_ALL_OPTIONS, Count={0}" -f $BUILD_ALL_OPTIONS.Count)
|
2023-07-06 12:18:33 +08:00
|
|
|
|
2023-08-27 23:21:22 +08:00
|
|
|
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS | Out-Host
|
|
|
|
}
|
2023-07-06 12:18:33 +08:00
|
|
|
}
|
2023-06-29 19:46:52 +08:00
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
$env:buildResult = ConvertTo-Json @{
|
|
|
|
buildDir = $BUILD_DIR;
|
|
|
|
targetOS = $BUILD_TARGET;
|
|
|
|
compilerID = $TOOLCHAIN_NAME;
|
|
|
|
}
|
2023-07-05 20:22:11 +08:00
|
|
|
|
2023-07-06 12:18:33 +08:00
|
|
|
Set-Location $stored_cwd
|
2023-07-05 20:22:11 +08:00
|
|
|
}
|