setup inital build script to start tackling compile errors

This commit is contained in:
2025-02-08 20:54:50 -05:00
parent 14d6c45e91
commit b42f4631ed
7 changed files with 254 additions and 28 deletions
+111 -7
View File
@@ -1,15 +1,119 @@
# This is meant to be used with build.ps1, and is not a standalone script.
$target_arch = Join-Path $PSScriptRoot 'target_arch.psm1'
# TODO(Ed): Need to eventually utilize the original build scripts
# For now just using something I'm used to for getting the library working..
import-module $target_arch
$misc = join-path $PSScriptRoot 'helpers/misc.ps1'
. $misc
$path_root = Get-ScriptRepoRoot
Push-Location $path_root
$path_bin = join-path $path_root bin
$path_scripts = $path_bin
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
$incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1'
$ini = join-path $PSScriptRoot 'helpers/ini.ps1'
$vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1'
. $ini
. $incremental_checks
$path_system_details = join-path $path_scripts 'system_details.ini'
if ( test-path $path_system_details ) {
$iniContent = Get-IniContent $path_system_details
$CoreCount_Physical = $iniContent["CPU"]["PhysicalCores"]
$CoreCount_Logical = $iniContent["CPU"]["LogicalCores"]
}
elseif ( $IsWindows ) {
$CPU_Info = Get-CimInstance ClassName Win32_Processor | Select-Object -Property NumberOfCores, NumberOfLogicalProcessors
$CoreCount_Physical, $CoreCount_Logical = $CPU_Info.NumberOfCores, $CPU_Info.NumberOfLogicalProcessors
new-item -path $path_system_details -ItemType File
"[CPU]" | Out-File $path_system_details
"PhysicalCores=$CoreCount_Physical" | Out-File $path_system_details -Append
"LogicalCores=$CoreCount_Logical" | Out-File $path_system_details -Append
}
write-host "Core Count - Physical: $CoreCount_Physical Logical: $CoreCount_Logical"
#region Arguments
$vendor = $null
$release = $null
[bool] $verbose = $false
[bool] $code_sanity = $false
[array] $vendors = @( "clang", "msvc" )
# This is a really lazy way of parsing the args, could use actual params down the line...
if ( $args ) { $args | ForEach-Object {
switch ($_) {
{ $_ -in $vendors } { $vendor = $_; break }
"verbose" { $verbose = $true }
"release" { $release = $true }
"debug" { $release = $false }
"code_sanity" { $code_sanity = $true }
}
}
}
#endregion Arguments
if ($IsWindows) {
# This HandmadeHero implementation is only designed for 64-bit systems
& $devshell -arch amd64
# This HandmadeHero implementation is only designed for 64-bit systems
& $devshell -arch amd64
}
if ( $vendor -eq $null ) {
write-host "No vendor specified, assuming clang available"
$vendor = "clang"
write-host "No vendor specified, assuming clang available"
$vendor = "clang"
}
if ( $release -eq $null ) {
write-host "No build type specified, assuming debug"
$release = $false
}
elseif ( $release -eq $false ) {
$debug = $true
}
else {
$optimize = $true
}
$cannot_build = $code_snaity -eq $false
if ( $cannot_build ) {
throw "No build target specified. One must be specified, this script will not assume one"
}
. $vendor_toolchain
write-host "Build Type: $(if ($release) {"Release"} else {"Debug"} )"
$path_build = join-path $path_root build
$path_code = join-path $path_root code
$path_examples = join-path $path_root examples
$path_gen_c11 = join-path $path_root gen_c11
$path_gen_cpp17 = join-path $path_root gen_cpp17
$path_tests = join-path $path_root tests
$path_third_party = join-path $path_root third_party
verify-path $path_build
if ($code_sanity)
{
write-host "Building code/metadesk.c (sanity compile) with $vendor"
$compiler_args = @()
# $compiler_args +=
$linker_args = @()
$linker_args += $flag_link_win_subsystem_console
$path_base = join-path $path_code base
$includes = @( $path_base )
$unit = join-path $path_base 'base.c'
$executable = join-path $path_build 'base.lib'
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
}
Pop-Location # $path_root
+20
View File
@@ -0,0 +1,20 @@
# This is meant to be used with build.ps1, and is not a standalone script.
function Get-IniContent { param([ string]$filePath )
$ini = @{}
$currentSection = $null
switch -regex -file $filePath
{
"^\[(.+)\]$" {
$currentSection = $matches[1].Trim()
$ini[$currentSection] = @{}
}
"^(.+?)\s*=\s*(.*)" {
$key, $value = $matches[1].Trim(), $matches[2].Trim()
if ($null -ne $currentSection) {
$ini[$currentSection][$key] = $value
}
}
}
return $ini
}
+119
View File
@@ -0,0 +1,119 @@
function clone-gitrepo { param( [string] $path, [string] $url )
if (test-path $path) {
# git -C $path pull
}
else {
Write-Host "Cloning $url ..."
git clone $url $path
}
}
function get-initcontent { param( [string] $path_file )
$ini = @{}
$currentSection = $null
switch -regex -file $path_file
{
"^\[(.+)\]$" {
$currentSection = $matches[1].Trim()
$ini[ $currentSection ] = @{}
}
"^(.+?)\s*=\s*(.*)" {
$key, $value = $matches[1].Trim(), $matches[2].Trim()
if ($null -ne $currentSection) {
$ini[ $currentSection ][ $key ] = $value
}
}
}
return $ini
}
function Get-ScriptRepoRoot {
$currentPath = $PSScriptRoot
while ($currentPath -ne $null -and $currentPath -ne "")
{
if (Test-Path (Join-Path $currentPath ".git")) {
return $currentPath
}
# Also check for .git file which indicates a submodule
$gitFile = Join-Path $currentPath ".git"
if (Test-Path $gitFile -PathType Leaf)
{
$gitContent = Get-Content $gitFile
if ($gitContent -match "gitdir: (.+)") {
return $currentPath
}
}
$currentPath = Split-Path $currentPath -Parent
}
throw "Unable to find repository root"
}
function Invoke-WithColorCodedOutput { param( [scriptblock] $command )
& $command 2>&1 | ForEach-Object {
# Write-Host "Type: $($_.GetType().FullName)" # Add this line for debugging
$color = 'White' # Default text color
switch ($_) {
{ $_ -imatch "error" } { $color = 'Red'; break }
{ $_ -imatch "warning" } { $color = 'Yellow'; break }
}
Write-Host "`t$_" -ForegroundColor $color
}
}
function update-gitrepo
{
param( [string] $path, [string] $url, [string] $build_command )
$repo_name = $url.Split('/')[-1].Replace('.git', '')
$last_built_commit = join-path $path_build "last_built_commit_$repo_name.txt"
if ( -not(test-path -Path $path))
{
write-host "Cloining repo from $url to $path"
git clone $url $path
write-host "Building $url"
push-location $path
if ( $build_command -ne '' )
{
& "$build_command"
}
pop-location
git -C $path rev-parse HEAD | out-file $last_built_commit
$script:binaries_dirty = $true
write-host
return
}
git -C $path fetch
$latest_commit_hash = git -C $path rev-parse '@{u}'
$last_built_hash = if (Test-Path $last_built_commit) { Get-Content $last_built_commit } else { "" }
if ( $latest_commit_hash -eq $last_built_hash ) {
write-host
return
}
write-host "Build out of date for: $path, updating"
write-host 'Pulling...'
git -C $path pull
write-host "Building $url"
push-location $path
if ( $build_command -ne '' )
{
& $build_command
}
pop-location
$latest_commit_hash | out-file $last_built_commit
$script:binaries_dirty = $true
write-host
}
function verify-path { param( $path )
if (test-path $path) {return $true}
new-item -ItemType Directory -Path $path
return $false
}
-20
View File
@@ -1,20 +0,0 @@
function Get-ScriptRepoRoot {
$currentPath = $PSScriptRoot
while ($currentPath -ne $null -and $currentPath -ne "")
{
if (Test-Path (Join-Path $currentPath ".git")) {
return $currentPath
}
# Also check for .git file which indicates a submodule
$gitFile = Join-Path $currentPath ".git"
if (Test-Path $gitFile -PathType Leaf)
{
$gitContent = Get-Content $gitFile
if ($gitContent -match "gitdir: (.+)") {
return $currentPath
}
}
$currentPath = Split-Path $currentPath -Parent
}
throw "Unable to find repository root"
}
-1
View File
@@ -404,7 +404,6 @@ if ( $vendor -match "msvc" )
$flag_optimize_intrinsics = '/Oi'
$flag_optimized_debug_forceinline = '/d2Obforceinline'
$flag_optimized_debug = '/Zo'
$flag_
# $flag_out_name = '/OUT:'
$flag_path_interm = '/Fo'
$flag_path_debug = '/Fd'
+3
View File
@@ -0,0 +1,3 @@
[CPU]
PhysicalCores=16
LogicalCores=32
+1
View File
@@ -2,6 +2,7 @@
#include "third_party/gencpp_c11/push_ignores.inline.h"
#define GEN_DONT_ENFORCE_GEN_TIME
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_IMPLEMENTATION