MSVC in latest script works

Clang is having issues.
This commit is contained in:
Edward R. Gonzalez 2023-08-19 17:08:13 -04:00
parent 32a910515e
commit 8985f0a4d9
4 changed files with 140 additions and 54 deletions

View File

@ -59,7 +59,7 @@ String AST::to_string()
} }
index++; index++;
str_copy( line, Content + curr, length ); str_copy( line, (char const*)Content + curr, length );
result.append_fmt( "//%.*s", length, line ); result.append_fmt( "//%.*s", length, line );
mem_set( line, 0, MaxCommentLineLength); mem_set( line, 0, MaxCommentLineLength);

View File

@ -73,8 +73,10 @@
) )
// #else // #else
// This doesn't work on latest msvc so I had to use /Zc:preprocessor flag.
// Supports 1-50 arguments // Supports 1-50 arguments
// #define num_args_impl( \ // #define num_args_impl( \
// _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ // _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
// _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ // _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ // _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
@ -88,7 +90,7 @@
// N, ... \ // N, ... \
// ) N // ) N
// #define num_args(...) \ // #define num_args(...) \
// num_args_impl( __VA_ARGS__, \ // num_args_impl( __VA_ARGS__, \
// 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \ // 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
// 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \ // 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
@ -102,7 +104,7 @@
// 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ // 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
// 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \ // 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
// ) // )
// // #endif // #endif
// Stringizing // Stringizing
#define stringize_va( ... ) #__VA_ARGS__ #define stringize_va( ... ) #__VA_ARGS__

View File

@ -1,15 +1,19 @@
# This build script was written to build on windows, however I did setup some generalization to allow for cross platform building.
# It will most likely need a partial rewrite to segment the build process into separate script invocations based on the OS.
# That or just rewrite it in an sh script and call it a day.
Import-Module ./helpers/target_arch.psm1 Import-Module ./helpers/target_arch.psm1
cls cls
#region Arguments #region Arguments
$compiler = $null $compiler = $null
[bool] $release = $false [bool] $release = $false
[bool] $bootstrap = $false [bool] $bootstrap = $false
[bool] $singleheader = $false [bool] $singleheader = $false
[bool] $tests = $false [bool] $tests = $false
[array] $compilers = @( "clang", "gcc", "msvc" ) [array] $compilers = @( "clang", "msvc" )
# This is a really lazy way of parsing the args, could use actual params down the line... # This is a really lazy way of parsing the args, could use actual params down the line...
@ -27,7 +31,9 @@ if ( $args ) { $args | ForEach-Object {
#region Building #region Building
write-host "Building gencpp with $compiler" write-host "Building gencpp with $compiler"
Invoke-Expression "& $(join-path $PSScriptRoot 'helpers/devshell.ps1') -arch x64" if ( $IsWindows ) {
Invoke-Expression "& $(join-path $PSScriptRoot 'helpers/devshell.ps1')"
}
$path_root = git rev-parse --show-toplevel $path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build $path_build = Join-Path $path_root build
@ -47,21 +53,14 @@ Push-Location $path_root
function run-compiler function run-compiler
{ {
param( $compiler, $executable, $path_build, $path_gen, $compiler_args ) param( $compiler, $unit, $compiler_args )
write-host "`nBuilding $executable" write-host "`Compiling $unit"
write-host "Compiler config:" write-host "Compiler config:"
$compiler_args | ForEach-Object { $compiler_args | ForEach-Object {
write-host $_ -ForegroundColor Cyan write-host $_ -ForegroundColor Cyan
} }
if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build
}
if ( -not(Test-Path($path_gen) )) {
New-Item -ItemType Directory -Path $path_gen
}
$time_taken = Measure-Command { $time_taken = Measure-Command {
& $compiler $compiler_args & $compiler $compiler_args
| ForEach-Object { | ForEach-Object {
@ -73,31 +72,70 @@ function run-compiler
write-host `t $_ -ForegroundColor $color write-host `t $_ -ForegroundColor $color
} }
} }
write-host "$executable built in $($time_taken.TotalMilliseconds) ms"
if ( Test-Path($unit) ) {
write-host "$unit compile finished in $($time_taken.TotalMilliseconds) ms"
}
else {
write-host "Compile failed for $unit" -ForegroundColor Red
}
}
function run-linker
{
param( $linker, $binary, $linker_args )
write-host "`Linking $binary"
write-host "Linker config:"
$linker_args | ForEach-Object {
write-host $_ -ForegroundColor Cyan
}
$time_taken = Measure-Command {
& $linker $linker_args
| ForEach-Object {
$color = 'White'
switch ($_){
{ $_ -match "error" } { $color = 'Red' ; break }
{ $_ -match "warning" } { $color = 'Yellow'; break }
}
write-host `t $_ -ForegroundColor $color
}
}
if ( Test-Path($binary) ) {
write-host "$binary linking finished in $($time_taken.TotalMilliseconds) ms"
}
else {
write-host "Linking failed for $binary" -ForegroundColor Red
}
} }
if ( $compiler -match "clang" ) if ( $compiler -match "clang" )
{ {
$target_arch = Get-TargetArchClang $target_arch = Get-TargetArchClang
$flag_compile_only = '-c' $flag_compile = '-c'
$flag_debug = '-g' $flag_debug = '-g'
$flag_debug_codeview = '-gcodeview' $flag_debug_codeview = '-gcodeview'
$flag_define = '-D' $flag_define = '-D'
$flag_include = '-I' $flag_include = '-I'
$flag_library = '-l' $flag_library = '-l'
$flag_library_path = '-L' $flag_library_path = '-L'
$flag_link_win = '-Wl,'
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
$flag_link_win_machine_32 = '/MACHINE:X86'
$flag_link_win_machine_64 = '/MACHINE:X64'
$flag_link_win_debug = '/DEBUG'
$flag_link_win_pdb = '/PDB:'
$flag_no_optimization = '-O0'
$flag_path_output = '-o' $flag_path_output = '-o'
$flag_preprocess_non_intergrated = '-no-integrated-cpp' $flag_preprocess_non_intergrated = '-no-integrated-cpp'
$flag_profiling_debug = '-fdebug-info-for-profiling' $flag_profiling_debug = '-fdebug-info-for-profiling'
$flag_target_arch = '-target' $flag_target_arch = '-target'
$flag_x_linker = '-Xlinker' $flag_x_linker = '-Xlinker'
$flag_machine_32 = '/machine:X64' $flag_wall = '-Wall'
$flag_machine_64 = '/machine:X64' $flag_win_nologo = '/nologo'
$flag_win_linker = '-Wl,'
$flag_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
$flag_win_machine_32 = '/MACHINE:X86'
$flag_win_machine_64 = '/MACHINE:X64'
# $library_paths = @( # $library_paths = @(
# 'C:\Windows\System32' # 'C:\Windows\System32'
@ -111,10 +149,12 @@ if ( $compiler -match "clang" )
$include = $path_project $include = $path_project
$unit = join-path $path_project "bootstrap.cpp" $unit = join-path $path_project "bootstrap.cpp"
$object = join-path $path_build "bootstrap.o"
$executable = join-path $path_build "bootstrap.exe" $executable = join-path $path_build "bootstrap.exe"
$compiler_args = @( $compiler_args = @(
$flag_target_arch, $target_arch, $flag_target_arch, $target_arch,
$flag_wall,
$flag_preprocess_non_intergrated, $flag_preprocess_non_intergrated,
$( $flag_define + 'GEN_TIME' ), $( $flag_define + 'GEN_TIME' ),
$flag_path_output, $executable, $flag_path_output, $executable,
@ -125,9 +165,12 @@ if ( $compiler -match "clang" )
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug $compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
} }
$compiler_args += $flag_compile, $unit
run-compiler clang++ $executable $path_build $path_gen $compiler_args
$linker_args = @( $linker_args = @(
$flag_x_linker, $flag_x_linker,
# $( $flag_linker + $flag_win_subsystem_console ), $( $flag_linker + $flag_win_subsystem_console ),
$( $flag_linker + $flag_machine_64 ) $( $flag_linker + $flag_machine_64 )
) )
$libraries = @( $libraries = @(
@ -136,11 +179,9 @@ if ( $compiler -match "clang" )
'libucrt', 'libucrt',
'libcmt' # For the C Runtime (Static Linkage) 'libcmt' # For the C Runtime (Static Linkage)
) )
$compiler_args += $linker_args
$compiler_args += $libraries | ForEach-Object { $flag_library + $_ }
$compiler_args += $unit # $compiler_args += $linker_args
run-compiler clang $executable $path_build $path_gen $compiler_args # $compiler_args += $libraries | ForEach-Object { $flag_library + $_ }
Push-Location $path_project Push-Location $path_project
if ( Test-Path($executable) ) { if ( Test-Path($executable) ) {
@ -200,17 +241,29 @@ if ( $compiler -match "clang" )
if ( $compiler -match "msvc" ) if ( $compiler -match "msvc" )
{ {
$flag_debug = '/Zi' $flag_compile = '/c'
$flag_define = '/D' $flag_debug = '/Zi'
$flag_include = '/I' $flag_define = '/D'
$flag_full_src_path = '/FC' $flag_include = '/I'
$flag_nologo = '/nologo' $flag_full_src_path = '/FC'
$flag_linker = '/link' $flag_nologo = '/nologo'
$flag_out_name = '/OUT:' $flag_dll = '/LD'
$flag_path_interm = '/Fo' $flag_dll_debug = '/LDd'
$flag_path_debug = '/Fd' $flag_linker = '/link'
$flag_path_output = '/Fe' $flag_link_machine_32 = '/MACHINE:X86'
$flag_preprocess_conform = '/Zc:preprocessor' $flag_link_machine_64 = '/MACHINE:X64'
$flag_link_path_output = '/OUT:'
$flag_link_rt_dll = '/MD'
$flag_link_rt_dll_debug = '/MDd'
$flag_link_rt_static = '/MT'
$flag_link_rt_static_debug = '/MTd'
$flag_link_subsystem_console = '/SUBSYSTEM:CONSOLE'
$flag_link_subsystem_windows = '/SUBSYSTEM:WINDOWS'
$flag_out_name = '/OUT:'
$flag_path_interm = '/Fo'
$flag_path_debug = '/Fd'
$flag_path_output = '/Fe'
$flag_preprocess_conform = '/Zc:preprocessor'
[array] $compiler_args = $null [array] $compiler_args = $null
@ -219,11 +272,18 @@ if ( $compiler -match "msvc" )
$path_build = join-path $path_project build $path_build = join-path $path_project build
$path_gen = join-path $path_project gen $path_gen = join-path $path_project gen
if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build
}
if ( -not(Test-Path($path_gen) )) {
New-Item -ItemType Directory -Path $path_gen
}
$include = $path_project $include = $path_project
$unit = join-path $path_project "bootstrap.cpp" $unit = join-path $path_project "bootstrap.cpp"
$object = join-path $path_build "bootstrap.obj"
$executable = join-path $path_build "bootstrap.exe" $executable = join-path $path_build "bootstrap.exe"
$compiler_args = @( $compiler_args = @(
$flag_nologo, $flag_nologo,
$flag_debug, $flag_debug,
@ -238,10 +298,27 @@ if ( $compiler -match "msvc" )
if ( $release -eq $false ) { if ( $release -eq $false ) {
$compiler_args += $( $flag_define + 'Build_Debug' ) $compiler_args += $( $flag_define + 'Build_Debug' )
$compiler_args += $( $flag_path_debug + $path_build + '\' ) $compiler_args += $( $flag_path_debug + $path_build + '\' )
$compiler_args += $flag_link_rt_static_debug
}
else {
$compiler_args += $flag_link_rt_static
} }
$compiler_args += $unit $compiler_args += $flag_compile, $unit
run-compiler cl $executable $path_build $path_gen $compiler_args run-compiler cl $unit $compiler_args
$linker_args = @(
$flag_nologo,
$flag_link_machine_64,
$flag_link_subsystem_console,
$( $flag_link_path_output + $executable ),
$object
)
if ( $release -eq $false ) {
}
else {
}
run-linker link $executable $linker_args
Push-Location $path_project Push-Location $path_project
if ( Test-Path($executable) ) { if ( Test-Path($executable) ) {
@ -261,6 +338,13 @@ if ( $compiler -match "msvc" )
$path_build = join-path $path_singleheader build $path_build = join-path $path_singleheader build
$path_gen = join-path $path_singleheader gen $path_gen = join-path $path_singleheader gen
if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build
}
if ( -not(Test-Path($path_gen) )) {
New-Item -ItemType Directory -Path $path_gen
}
$include = $path_project $include = $path_project
$unit = join-path $path_singleheader "singleheader.cpp" $unit = join-path $path_singleheader "singleheader.cpp"
$executable = join-path $path_build "singleheader.exe" $executable = join-path $path_build "singleheader.exe"
@ -302,9 +386,9 @@ if ( $compiler -match "msvc" )
} }
} }
#pragma endregion Building #endregion Building
#pragma region Formatting #region Formatting
if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) ) if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
{ {
$path_gen = join-path $path_project gen $path_gen = join-path $path_project gen
@ -362,6 +446,6 @@ if ( $test )
{ {
} }
#pragma endregion Formatting #endregion Formatting
Pop-Location # $path_root Pop-Location # $path_root

View File

@ -1,6 +1,6 @@
param ( param (
[ValidateSet("x64", "x86", "arm", "arm64")] [ValidateSet("amd64", "x86", "arm", "arm64")]
[string]$arch = "x64" [string]$arch = "amd64"
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
@ -23,9 +23,9 @@ if ( -not (Test-Path $vs_devshell) ) {
} }
# Set the target architecture based on the parameter # Set the target architecture based on the parameter
$env:VSCMD_ARG_TGT_ARCH=$arch # $env:VSCMD_ARG_TGT_ARCH=$arch
# Launch the Visual Studio Developer Shell # Launch the Visual Studio Developer Shell
Push-Location Push-Location
& $vs_devshell @args & $vs_devshell -Arch amd64
Pop-Location Pop-Location