Skip to content

Commit

Permalink
Add dump compiler preprocessors support
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Apr 13, 2024
1 parent ca568bb commit af04205
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 30 deletions.
26 changes: 17 additions & 9 deletions 1k/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ $options = @{
minsdk = $null
dll = $false
u = $false # whether delete 1kdist cross-platform prebuilt folder: path/to/_x
dm = $false # dump compiler preprocessors
}

$optName = $null
Expand All @@ -252,6 +253,10 @@ foreach ($arg in $args) {
continue
}
}
if($options[$optName] -is [bool]) {
$options[$optName] = $true
$optName = $null
}
}
}
else {
Expand Down Expand Up @@ -878,7 +883,7 @@ function setup_nasm() {
$nasm_prog, $nasm_ver = find_prog -name 'nasm' -path "$external_prefix/nasm" -mode 'BOTH' -silent $true

if (!$nasm_prog) {
if ($IsWindows) {
if ($IsWin) {
$nasm_bin = Join-Path $external_prefix "nasm-$nasm_ver"

if (!$b1k.isdir($nasm_bin)) {
Expand Down Expand Up @@ -1420,7 +1425,7 @@ function preprocess_ios([string[]]$inputOptions) {
}

function preprocess_wasm([string[]]$inputOptions) {
if ($options.p -eq 'wasm64') { $inputOptions += '-DCMAKE_C_FLAGS="-sMEMORY64 -Wno-experimental"', '-DCMAKE_CXX_FLAGS=-sMEMORY64 -Wno-experimental'}
if ($options.p -eq 'wasm64') { $inputOptions += '-DCMAKE_C_FLAGS="-sMEMORY64 -Wno-experimental"', '-DCMAKE_CXX_FLAGS=-sMEMORY64 -Wno-experimental' }
return $inputOptions
}

Expand Down Expand Up @@ -1454,7 +1459,7 @@ function validHostAndToolchain() {
'host' = @{'windows' = $True; 'linux' = $True; 'macos' = $True };
'toolchain' = @{'clang' = $True; };
};
'wasm64' = @{
'wasm64' = @{
'host' = @{'windows' = $True; 'linux' = $True; 'macos' = $True };
'toolchain' = @{'clang' = $True; };
};
Expand All @@ -1480,7 +1485,7 @@ $proprocessTable = @{
'tvos' = ${function:preprocess_ios};
'watchos' = ${function:preprocess_ios};
'wasm' = ${Function:preprocess_wasm};
'wasm64' = ${Function:preprocess_wasm};
'wasm64' = ${Function:preprocess_wasm};
}

validHostAndToolchain
Expand Down Expand Up @@ -1745,12 +1750,15 @@ if (!$setupOnly) {
$cmakeCachePath = $b1k.realpath("$BUILD_DIR/CMakeCache.txt")

if ($mainDepChanged -or !$b1k.isfile($cmakeCachePath) -or $forceConfig) {
if (!$is_wasm) {
cmake -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
}
else {
emcmake cmake -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
$config_cmd = if (!$is_wasm) { 'cmake' } else { 'emcmake' }
if ($options.dm) {
$b1k.println("Dumping compiler preprocessors ...")
$dmcp_dir = Join-Path $PSScriptRoot 'dmcp'
$dmcp_build_dir = Join-Path $dmcp_dir 'build'
&$config_cmd -S $dmcp_dir -B $dmcp_build_dir $CONFIG_ALL_OPTIONS | Out-Host ; Remove-Item $dmcp_build_dir -Recurse -Force
$b1k.println("Finish dump compiler preprocessors")
}
&$config_cmd -B $BUILD_DIR $CONFIG_ALL_OPTIONS | Out-Host
Set-Content $tempFile $hashValue -NoNewline
}

Expand Down
10 changes: 6 additions & 4 deletions 1k/dmcp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ cmake_minimum_required(VERSION 3.23)

project(dmcp)

message(STATUS "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
if(NOT WIN32)
execute_process(COMMAND /bin/sh "${CMAKE_CURRENT_SOURCE_DIR}/dmcp.sh" "${CMAKE_CXX_COMPILER}")
endif()
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)

message(STATUS "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")

if(${CMAKE_C_COMPILER} MATCHES ".*cl\.exe" OR "${MSVC_VERSION}" GREATER_EQUAL 1928)
execute_process(COMMAND ${PWSH_PROG} "${CMAKE_CURRENT_SOURCE_DIR}/dmcp.ps1" "${CMAKE_C_COMPILER}" "${CMAKE_C_FLAGS}")
endif()
17 changes: 17 additions & 0 deletions 1k/dmcp/dmcp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
param(
$cc,
$cflags
)

$IsWin = $IsWindows -or ("$env:OS" -eq 'Windows_NT')

echo "cflags=${cflags}"

$cflags = $cflags.Split(' ')

if($cc.EndsWith('cl.exe')) {
# vs2019+ support:
&$cc /EP /Zc:preprocessor /PD $cflags (Join-Path $PSScriptRoot 'dummy.c')
} else {
echo ''| &$cc -E -dM $cflags -
}
1 change: 0 additions & 1 deletion 1k/dmcp/dmcp.sh

This file was deleted.

Empty file added 1k/dmcp/dummy.c
Empty file.
45 changes: 29 additions & 16 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ if (!$libs) {
'luajit'
'angle'
)
} else {
if($libs -isnot [array]) { # not array, split by ','
}
else {
if ($libs -isnot [array]) {
# not array, split by ','
$libs = $libs -split ","
}
}
Expand All @@ -54,7 +56,7 @@ $install_path = "install_${target_os}"
if ($target_cpu -ne '*') {
$install_path = "${install_path}_$target_cpu"
}
if($sdk.StartsWith('sim')) { $install_path += '_sim' }
if ($sdk.StartsWith('sim')) { $install_path += '_sim' }
$install_root = Join-Path $_1k_root $install_path

# Create buildsrc tmp dir for build libs
Expand All @@ -66,14 +68,14 @@ if ((Get-Module -ListAvailable -Name powershell-yaml) -eq $null) {
}

$forward_args = @{}
if($rebuild) {
if ($rebuild) {
$forward_args['rebuild'] = $true
}
if($sdk) {
if ($sdk) {
$forward_args['sdk'] = $sdk
}

if($target_os -eq 'osx') {
if ($target_os -eq 'osx') {
$forward_args['minsdk'] = '10.13'
}

Expand All @@ -84,10 +86,10 @@ if ($IsWin) {
#relocate powershell.exe to opensource edition pwsh.exe to solve angle gclient execute issues:
# Get-FileHash is not recognized as a name of a cmdlet
$pwshPath = $(Get-Command pwsh).Path
$pwshDir = Split-Path -Path $pwshPath
$pwshDir = Split-Path -Path $pwshPath

echo "Before relocate powershell"
powershell -Command {$pwshVSI='PowerShell ' + $PSVersionTable.PSVersion.ToString();echo $pwshVSI}
powershell -Command { $pwshVSI = 'PowerShell ' + $PSVersionTable.PSVersion.ToString(); echo $pwshVSI }

$eap = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
Expand All @@ -96,12 +98,12 @@ if ($IsWin) {

$env:Path = "$pwshPath;$env:Path"
echo "After relocate powershell"
powershell -Command {$pwshVSI='PowerShell ' + $PSVersionTable.PSVersion.ToString();echo $pwshVSI}
powershell -Command { $pwshVSI = 'PowerShell ' + $PSVersionTable.PSVersion.ToString(); echo $pwshVSI }
}

if ($Global:is_android) {
active_ndk_toolchain
$Global:android_api_level = @{arm64 = 21; x64 = 22; armv7 = 16; x86 = 16}[$target_cpu]
$Global:android_api_level = @{arm64 = 21; x64 = 22; armv7 = 16; x86 = 16 }[$target_cpu]
}
elseif ($is_darwin_family) {
# query xcode version
Expand Down Expand Up @@ -140,6 +142,8 @@ if ($is_darwin_family) {
$darwin_family = 'darwin'
}

$compiler_dumped = $false

Foreach ($lib_name in $libs) {
$build_conf_path = Join-Path $_1k_root "src/$lib_name/build.yml"
$build_conf = ConvertFrom-Yaml -Yaml (Get-Content $build_conf_path -raw)
Expand All @@ -158,8 +162,9 @@ Foreach ($lib_name in $libs) {
$version = $build_conf.ver
$revision = $null # commit_hash
if (Test-Path $rel_script -PathType Leaf) {
$version,$revision = &$rel_script $build_conf.ver
} else {
$version, $revision = &$rel_script $build_conf.ver
}
else {
$revision = "$($build_conf.tag_prefix)$version"
if ($build_conf.tag_dot2ul) {
$revision = $revision.Replace('.', '_')
Expand Down Expand Up @@ -220,11 +225,19 @@ Foreach ($lib_name in $libs) {
}

$_config_options += "-DCMAKE_INSTALL_PREFIX=$install_dir"

&$build_script -p $target_os -a $target_cpu -xc $_config_options -xb '--target', 'install' @forward_args
} elseif($is_gn) {

if ($compiler_dumped) {
&$build_script -p $target_os -a $target_cpu -xc $_config_options -xb '--target', 'install' @forward_args
}
else {
&$build_script -p $target_os -a $target_cpu -xc $_config_options -xb '--target', 'install' @forward_args -dm
$compiler_dumped = $true
}
}
elseif ($is_gn) {
&$build_script -p $target_os -a $target_cpu -xc $_config_options -xt 'gn' -t "$($build_conf.cb_target)" @forward_args
} else {
}
else {
throw "Unsupported cross build tool: $($build_conf.cb_tool)"
}
}
Expand Down

0 comments on commit af04205

Please sign in to comment.