Simpilication of build script, added initial support for tests

This commit is contained in:
Edward R. Gonzalez 2023-08-20 12:31:24 -04:00
parent 37d9782cf2
commit a6bf60a51e
17 changed files with 574 additions and 790 deletions

View File

@ -1,7 +1,7 @@
{ {
"configurations": [ "configurations": [
{ {
"name": "Win32", "name": "Win32 msvc",
"includePath": [ "includePath": [
"${workspaceFolder}/**" "${workspaceFolder}/**"
], ],
@ -12,10 +12,24 @@
"GEN_TIME" "GEN_TIME"
], ],
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
// "compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe", "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
"compilerPath": "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe",
"intelliSenseMode": "msvc-x64", "intelliSenseMode": "msvc-x64",
// "intelliSenseMode": "windows-clang-x64", "compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
},
{
"name": "Win32 clang",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"GEN_TIME"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
"intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json" "compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
} }
], ],

4
.vscode/launch.json vendored
View File

@ -8,7 +8,7 @@
"type": "lldb", "type": "lldb",
"request": "launch", "request": "launch",
"name": "Debug gentime lldb", "name": "Debug gentime lldb",
"program": "${workspaceFolder}/test/gen/build/gencpp.exe", "program": "${workspaceFolder}/test/test.exe",
"args": [], "args": [],
"cwd": "${workspaceFolder}/test/gen/", "cwd": "${workspaceFolder}/test/gen/",
"postRunCommands": [ "postRunCommands": [
@ -18,7 +18,7 @@
"type": "cppvsdbg", "type": "cppvsdbg",
"request": "launch", "request": "launch",
"name": "Debug gentime vsdbg", "name": "Debug gentime vsdbg",
"program": "${workspaceFolder}/test/gen/build/gencpp.exe", "program": "${workspaceFolder}/test/build/test.exe",
"args": [], "args": [],
"cwd": "${workspaceFolder}/test/gen/", "cwd": "${workspaceFolder}/test/gen/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis" "visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"

View File

@ -103,10 +103,8 @@
<None Include="scripts\build.ci.ps1" /> <None Include="scripts\build.ci.ps1" />
<None Include="scripts\build.ps1" /> <None Include="scripts\build.ps1" />
<None Include="scripts\clean.ps1" /> <None Include="scripts\clean.ps1" />
<None Include="scripts\gen.ps1" />
<None Include="scripts\genccp.natstepfilter" /> <None Include="scripts\genccp.natstepfilter" />
<None Include="scripts\gencpp.refactor" /> <None Include="scripts\gencpp.refactor" />
<None Include="scripts\get_sources.ps1" />
<None Include="test\gen\meson.build" /> <None Include="test\gen\meson.build" />
<None Include="test\meson.build" /> <None Include="test\meson.build" />
<None Include="test\Readme.md" /> <None Include="test\Readme.md" />
@ -206,13 +204,9 @@
<Content Include="project\enums\ESpecifier.csv" /> <Content Include="project\enums\ESpecifier.csv" />
<Content Include="project\enums\ETokType.csv" /> <Content Include="project\enums\ETokType.csv" />
<Content Include="scripts\.clang-format" /> <Content Include="scripts\.clang-format" />
<Content Include="scripts\bootstrap.ci.ps1" />
<Content Include="scripts\bootstrap.ps1" />
<Content Include="scripts\helpers\devshell.ps1" /> <Content Include="scripts\helpers\devshell.ps1" />
<Content Include="scripts\helpers\target_arch.psm1" /> <Content Include="scripts\helpers\target_arch.psm1" />
<Content Include="scripts\refactor.ps1" /> <Content Include="scripts\refactor.ps1" />
<Content Include="scripts\singleheader.ci.ps1" />
<Content Include="scripts\singleheader.ps1" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -36,21 +36,12 @@ args:
singleheader singleheader
test test
clang clang
msvc msvc : By default this project builds with clang, specifying msvc will build with MSVC.
release debug
release : By default this project builds in debug mode, specifying release will build with optimizations.
``` ```
**`test.gen.build.ps1`** **`package_release.ps1`**
Build the metaprogram for generating the test code. Will build the project as fast as possible, then package the release into a zip file.
**`test.gen.ps1`**
Build (if not already) the metaprogram for generating test code, then run it to generate code.
**`test.build.ps1`**
Build and run metaprogram, build test program.
**`test.run.ps1`**
Build and run metaprogram, build and run test program.
*Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6* *Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6*

524
scripts/build.ci.ps1 Normal file
View File

@ -0,0 +1,524 @@
# 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
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
cls
#region Arguments
$compiler = $null
$release = $null
[bool] $bootstrap = $false
[bool] $singleheader = $false
[bool] $test = $false
[array] $compilers = @( "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 $compilers } { $compiler = $_; break }
"release" { $release = $true }
"debug" { $release = $false }
"bootstrap" { $bootstrap = $true }
"singleheader" { $singleheader = $true }
"test" { $test = $true }
}
}}
#endregion Arguments
#region Building
if ($IsWindows) {
# This library was really designed to only run on 64-bit systems.
# (Its a development tool after all)
& $devshell -arch amd64
}
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_project = Join-Path $path_root project
$path_scripts = Join-Path $path_root scripts
$path_singleheader = Join-Path $path_root singleheader
$path_test = Join-Path $path_root test
if ( $compiler -eq $null ) {
write-host "No compilier specified, assuming clang available"
$compiler = "clang"
}
if ( $release -eq $null ) {
write-host "No build type specified, assuming debug"
$release = $false
}
if ( $bootstrap -eq $false -and $singleheader -eq $false -and $test -eq $false ) {
throw "No build target specified. One must be specified, this script will not assume one"
}
write-host "Building gencpp with $compiler"
write-host "Build Type: $(if ($release) {"Release"} else {"Debug"} )"
Push-Location $path_root
function run-compiler
{
param( $compiler, $unit, $compiler_args )
write-host "`Compiling $unit"
write-host "Compiler config:"
$compiler_args | ForEach-Object {
write-host $_ -ForegroundColor Cyan
}
$time_taken = Measure-Command {
& $compiler $compiler_args 2>&1 | ForEach-Object {
$color = 'White'
switch ($_){
{ $_ -match "error" } { $color = 'Red' ; break }
{ $_ -match "warning" } { $color = 'Yellow'; break }
}
write-host `t $_ -ForegroundColor $color
}
}
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 2>&1 | 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" )
{
# https://clang.llvm.org/docs/ClangCommandLineReference.html
$flag_compile = '-c'
$flag_color_diagnostics = '-fcolor-diagnostics'
$flag_no_color_diagnostics = '-fno-color-diagnostics'
$flag_debug = '-g'
$flag_debug_codeview = '-gcodeview'
$flag_define = '-D'
$flag_include = '-I'
$flag_library = '-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_link_win_path_output = '/OUT:'
$flag_no_optimization = '-O0'
$flag_path_output = '-o'
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
$flag_profiling_debug = '-fdebug-info-for-profiling'
$flag_target_arch = '-target'
$flag_wall = '-Wall'
$flag_warning = '-W'
$flag_warning_as_error = '-Werror'
$flag_win_nologo = '/nologo'
$ignore_warning_ms_include = 'no-microsoft-include'
$target_arch = Get-TargetArchClang
$warning_ignores = @(
$ignore_warning_ms_include
)
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
$libraries = @(
'Kernel32' # For Windows API
# 'msvcrt', # For the C Runtime (Dynamically Linked)
# 'libucrt',
'libcmt' # For the C Runtime (Static Linkage)
)
function build-simple
{
param( $compiler, $linker, $includes, $unit, $executable )
$object = $executable -replace '\.exe', '.obj'
$pdb = $executable -replace '\.exe', '.pdb'
$compiler_args = @(
$flag_no_color_diagnostics,
$flag_target_arch, $target_arch,
$flag_wall,
$flag_preprocess_non_intergrated,
( $flag_define + 'GEN_TIME' ),
( $flag_path_output + $object ),
( $flag_include + $includes )
)
if ( $release -eq $false ) {
$compiler_args += ( $flag_define + 'Build_Debug' )
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
$compiler_args += $flag_no_optimization
}
$warning_ignores | ForEach-Object {
$compiler_args += $flag_warning + $_
}
$compiler_args += $flag_compile, $unit
run-compiler $compiler $unit $compiler_args
$linker_args = @(
$flag_link_win_subsystem_console,
$flag_link_win_machine_64,
$( $flag_link_win_path_output + $executable )
)
if ( $release -eq $false ) {
$linker_args += $flag_link_win_debug
$linker_args += $flag_link_win_pdb + $pdb
}
else {
}
$libraries | ForEach-Object {
$linker_args += $_ + '.lib'
}
$linker_args += $object
run-linker $linker $executable $linker_args
}
[array] $compiler_args = $null
[array] $linker_args = $null
if ( $bootstrap )
{
$path_build = join-path $path_project build
$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
}
$includes = @( $path_project )
$unit = join-path $path_project "bootstrap.cpp"
$executable = join-path $path_build "bootstrap.exe"
build-simple clang++ lld-link $include $unit $executable
Push-Location $path_project
if ( Test-Path( $executable ) ) {
write-host "`nRunning bootstrap"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $singleheader )
{
$path_build = join-path $path_singleheader build
$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
$unit = join-path $path_singleheader "singleheader.cpp"
$executable = join-path $path_build "singleheader.exe"
build-simple clang++ lld-link $include $unit $executable
Push-Location $path_singleheader
if ( Test-Path( $executable ) ) {
write-host "`nRunning singleheader generator"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $test )
{
# ... [your test compilation code here]
}
}
if ( $compiler -match "msvc" )
{
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
$flag_compile = '/c'
$flag_debug = '/Zi'
$flag_define = '/D'
$flag_include = '/I'
$flag_full_src_path = '/FC'
$flag_nologo = '/nologo'
$flag_dll = '/LD'
$flag_dll_debug = '/LDd'
$flag_linker = '/link'
$flag_link_debug = '/DEBUG'
$flag_link_pdb = '/PDB:'
$flag_link_machine_32 = '/MACHINE:X86'
$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_no_optimization = '/Od'
$flag_out_name = '/OUT:'
$flag_path_interm = '/Fo'
$flag_path_debug = '/Fd'
$flag_path_output = '/Fe'
$flag_preprocess_conform = '/Zc:preprocessor'
# This works because this project uses a single unit to build
function build-simple
{
param( $compiler, $linker, $includes, $unit, $executable )
$object = $executable -replace '\.exe', '.obj'
$pdb = $executable -replace '\.exe', '.pdb'
$compiler_args = @(
$flag_nologo,
$flag_preprocess_conform,
$flag_debug,
( $flag_define + 'GEN_TIME' ),
$flag_full_src_path,
( $flag_path_interm + $path_build + '\' ),
( $flag_path_output + $path_build + '\' )
)
if ( $release -eq $false ) {
$compiler_args += ( $flag_define + 'Build_Debug' )
$compiler_args += ( $flag_path_debug + $path_build + '\' )
$compiler_args += $flag_link_rt_static_debug
$compiler_args += $flag_no_optimization
}
else {
$compiler_args += $flag_link_rt_static
}
$compiler_args += $includes | ForEach-Object { $flag_include + $_ }
$compiler_args += $flag_compile, $unit
run-compiler $compiler $unit $compiler_args
$linker_args = @(
$flag_nologo,
$flag_link_machine_64,
$flag_link_subsystem_console,
( $flag_link_path_output + $executable )
)
if ( $release -eq $false ) {
$linker_args += $flag_link_debug
$linker_args += $flag_link_pdb + $pdb
}
else {
}
$linker_args += $object
run-linker $linker $executable $linker_args
}
[array] $compiler_args = $null
[array] $linker_args = $null
if ( $bootstrap )
{
$path_build = join-path $path_project build
$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
}
$includes = @( $path_project)
$unit = join-path $path_project "bootstrap.cpp"
$executable = join-path $path_build "bootstrap.exe"
build-simple cl link $includes $unit $executable
Push-Location $path_project
if ( Test-Path( $executable ) ) {
write-host "`nRunning bootstrap"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $singleheader )
{
$path_build = join-path $path_singleheader build
$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
}
$includes = @($path_project)
$unit = join-path $path_singleheader "singleheader.cpp"
$executable = join-path $path_build "singleheader.exe"
build-simple cl link $includes $unit $executable
Push-Location $path_singleheader
if ( Test-Path($executable) ) {
write-host "`nRunning singleheader generator"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $test )
{
$path_gen = join-path $path_test gen
$path_gen_build = join-path $path_gen build
$path_build = join-path $path_test build
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
}
if ( -not(Test-Path($path_gen_build) )) {
New-Item -ItemType Directory -Path $path_gen_build
}
$path_bootstrap = join-path $path_project gen
$include = $path_bootstrap
$unit = join-path $path_test "test.cpp"
$object = join-path $path_build "test.obj"
$executable = join-path $path_build "test.exe"
$pdb = join-path $path_build "test.pdb"
build-simple cl link $include $unit $executable
Push-Location $path_test
if ( Test-Path( $executable ) ) {
write-host "`nRunning test generator"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nTest generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
}
#endregion Building
#region Formatting
function format-cpp
{
param( $path, $include, $exclude )
# Format generated gencpp
Write-Host "`nBeginning format"
$formatParams = @(
'-i' # In-place
'-style=file:./scripts/.clang-format'
'-verbose'
)
$targetFiles = @(Get-ChildItem -Recurse -Path $path -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
$time_taken = Measure-Command {
clang-format $formatParams $targetFiles
}
Write-Host "`nFormatting complete in $($time_taken.TotalMilliseconds) ms"
}
if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
{
$path_gen = join-path $path_project gen
$include = @(
'gen.hpp', 'gen.cpp',
'gen.dep.hpp', 'gen.dep.cpp',
'gen.builder.hpp', 'gen.builder.cpp'
'gen.scanner.hpp', 'gen.scanner.cpp'
)
$exclude = $null
format-cpp $path_gen $include $exclude
}
if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) )
{
$path_gen = join-path $path_singleheader gen
$include = @(
'gen.hpp'
)
$exclude = $null
format-cpp $path_gen $include $exclude
}
if ( $test )
{
}
#endregion Formatting
Pop-Location # $path_root

View File

@ -1,548 +1,3 @@
# 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
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
cls cls
$build = Join-Path $PSScriptRoot 'build.ci.ps1'
#region Arguments & $build @args
$compiler = $null
[bool] $release = $false
[bool] $bootstrap = $false
[bool] $singleheader = $false
[bool] $tests = $false
[array] $compilers = @( "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 $compilers } { $compiler = $_; break }
"release" { $release = $true }
"bootstrap" { $bootstrap = $true }
"singleheader" { $singleheader = $true }
"tests" { $tests = $true }
}
}}
#endregion Arguments
#region Building
write-host "Building gencpp with $compiler"
if ($IsWindows) {
# This library was really designed to only run on 64-bit systems.
# (Its a development tool after all)
& $devshell -arch amd64
}
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_project = Join-Path $path_root project
$path_scripts = Join-Path $path_root scripts
$path_singleheader = Join-Path $path_root singleheader
$path_test = Join-Path $path_root test
write-host "Build Type: $(if ($release) {"Release"} else {"Debug"} )"
if ( $compiler -eq $null ) {
write-host "No compilier specified, assuming clang available"
$compiler = "clang"
}
Push-Location $path_root
function run-compiler
{
param( $compiler, $unit, $compiler_args )
write-host "`Compiling $unit"
write-host "Compiler config:"
$compiler_args | ForEach-Object {
write-host $_ -ForegroundColor Cyan
}
$time_taken = Measure-Command {
& $compiler $compiler_args 2>&1 | ForEach-Object {
$color = 'White'
switch ($_){
{ $_ -match "error" } { $color = 'Red' ; break }
{ $_ -match "warning" } { $color = 'Yellow'; break }
}
write-host `t $_ -ForegroundColor $color
}
}
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 2>&1 | 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" )
{
# https://clang.llvm.org/docs/ClangCommandLineReference.html
$flag_compile = '-c'
$flag_color_diagnostics = '-fcolor-diagnostics'
$flag_no_color_diagnostics = '-fno-color-diagnostics'
$flag_debug = '-g'
$flag_debug_codeview = '-gcodeview'
$flag_define = '-D'
$flag_include = '-I'
$flag_library = '-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_link_win_path_output = '/OUT:'
$flag_no_optimization = '-O0'
$flag_path_output = '-o'
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
$flag_profiling_debug = '-fdebug-info-for-profiling'
$flag_target_arch = '-target'
$flag_wall = '-Wall'
$flag_warning = '-W'
$flag_warning_as_error = '-Werror'
$flag_win_nologo = '/nologo'
$ignore_warning_ms_include = 'no-microsoft-include'
$target_arch = Get-TargetArchClang
$warning_ignores = @(
$ignore_warning_ms_include
)
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
$libraries = @(
'Kernel32' # For Windows API
# 'msvcrt', # For the C Runtime (Dynamically Linked)
# 'libucrt',
'libcmt' # For the C Runtime (Static Linkage)
)
if ( $bootstrap )
{
$path_build = join-path $path_project build
$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
$unit = join-path $path_project "bootstrap.cpp"
$object = join-path $path_build "bootstrap.obj"
$executable = join-path $path_build "bootstrap.exe"
$pdb = join-path $path_build "bootstrap.pdb"
$compiler_args = @(
$flag_no_color_diagnostics,
$flag_target_arch, $target_arch,
$flag_wall,
$flag_preprocess_non_intergrated,
( $flag_define + 'GEN_TIME' ),
( $flag_path_output + $object ),
( $flag_include + $include )
)
$warning_ignores | ForEach-Object {
$compiler_args += $flag_warning + $_
}
if ( $release -eq $false ) {
$compiler_args += ( $flag_define + 'Build_Debug' )
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
}
$compiler_args += $flag_compile, $unit
run-compiler clang++ $unit $compiler_args
$linker_args = @(
$flag_link_win_subsystem_console,
$flag_link_win_machine_64,
$( $flag_link_win_path_output + $executable )
)
if ( $release -eq $false ) {
$linker_args += $flag_link_win_debug
$linker_args += $flag_link_win_pdb + $pdb
}
else {
}
$libraries | ForEach-Object {
$linker_args += $_ + '.lib'
}
$linker_args += $object
run-linker lld-link $executable $linker_args
Push-Location $path_project
if ( Test-Path( $executable ) ) {
write-host "`nRunning bootstrap"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $singleheader )
{
$path_build = join-path $path_singleheader build
$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
$unit = join-path $path_singleheader "singleheader.cpp"
$object = join-path $path_build "singleheader.obj"
$executable = join-path $path_build "singleheader.exe"
$pdb = join-path $path_build "singleheader.pdb"
$compiler_args = @(
$flag_no_color_diagnostics,
$flag_target_arch, $target_arch,
$flag_wall,
$flag_preprocess_non_intergrated,
( $flag_define + 'GEN_TIME' ),
( $flag_path_output + $object ),
( $flag_include + $include )
)
if ( $release -eq $false ) {
$compiler_args += ( $flag_define + 'Build_Debug' )
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
}
$warning_ignores | ForEach-Object {
$compiler_args += $flag_warning + $_
}
$compiler_args += $flag_compile, $unit
run-compiler clang $unit $compiler_args
$linker_args = @(
$flag_link_win_subsystem_console,
$flag_link_win_machine_64,
$( $flag_link_win_path_output + $executable )
)
if ( $release -eq $false ) {
$linker_args += $flag_link_win_debug
$linker_args += $flag_link_win_pdb + $pdb
}
else {
}
$libraries | ForEach-Object {
$linker_args += $_ + '.lib'
}
$linker_args += $object
run-linker lld-link $executable $linker_args
Push-Location $path_singleheader
if ( Test-Path( $executable ) ) {
write-host "`nRunning singleheader generator"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $test )
{
# ... [your test compilation code here]
}
}
if ( $compiler -match "msvc" )
{
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
$flag_compile = '/c'
$flag_debug = '/Zi'
$flag_define = '/D'
$flag_include = '/I'
$flag_full_src_path = '/FC'
$flag_nologo = '/nologo'
$flag_dll = '/LD'
$flag_dll_debug = '/LDd'
$flag_linker = '/link'
$flag_link_debug = '/DEBUG'
$flag_link_pdb = '/PDB:'
$flag_link_machine_32 = '/MACHINE:X86'
$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] $linker_args = $null
if ( $bootstrap )
{
$path_build = join-path $path_project build
$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
$unit = join-path $path_project "bootstrap.cpp"
$object = join-path $path_build "bootstrap.obj"
$executable = join-path $path_build "bootstrap.exe"
$pdb = join-path $path_build "bootstrap.pdb"
$compiler_args = @(
$flag_nologo,
$flag_preprocess_conform,
$flag_define + 'GEN_TIME',
$flag_full_src_path,
( $flag_path_interm + $path_build + '\' ),
( $flag_path_output + $path_build + '\' ),
( $flag_include + $include )
)
if ( $release -eq $false ) {
$compiler_args += ( $flag_define + 'Build_Debug' )
$compiler_args += $flag_debug
$compiler_args += ( $flag_path_debug + $path_build + '\' )
$compiler_args += $flag_link_rt_static_debug
}
else {
$compiler_args += $flag_link_rt_static
}
$compiler_args += $flag_compile, $unit
run-compiler cl $unit $compiler_args
$linker_args = @(
$flag_nologo,
$flag_link_machine_64,
$flag_link_subsystem_console,
( $flag_link_path_output + $executable )
)
if ( $release -eq $false ) {
$linker_args += $flag_link_debug
$linker_args += $flag_link_pdb + $pdb
}
else {
}
$linker_args += $object
run-linker link $executable $linker_args
Push-Location $path_project
if ( Test-Path( $executable ) ) {
write-host "`nRunning bootstrap"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $singleheader )
{
$path_build = join-path $path_singleheader build
$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
$unit = join-path $path_singleheader "singleheader.cpp"
$object = join-path $path_build "singleheader.obj"
$executable = join-path $path_build "singleheader.exe"
$pdb = join-path $path_build "singleheader.pdb"
$compiler_args = @(
$flag_nologo,
$flag_preprocess_conform,
$flag_debug,
( $flag_define + 'GEN_TIME' ),
$flag_full_src_path,
( $flag_path_interm + $path_build + '\' ),
( $flag_path_output + $path_build + '\' ),
( $flag_include + $include )
)
if ( $release -eq $false ) {
$compiler_args += ( $flag_define + 'Build_Debug' )
$compiler_args += ( $flag_path_debug + $path_build + '\' )
$compiler_args += $flag_link_rt_static_debug
}
else {
$compiler_args += $flag_link_rt_static
}
$compiler_args += $flag_compile, $unit
run-compiler cl $unit $compiler_args
$linker_args = @(
$flag_nologo,
$flag_link_machine_64,
$flag_link_subsystem_console,
( $flag_link_path_output + $executable )
)
if ( $release -eq $false ) {
$linker_args += $flag_link_debug
$linker_args += $flag_link_pdb + $pdb
}
else {
}
$linker_args += $object
run-linker link $executable $linker_args
Push-Location $path_singleheader
if ( Test-Path($executable) ) {
write-host "`nRunning singleheader generator"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
if ( $test )
{
}
}
#endregion Building
#region Formatting
if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
{
$path_gen = join-path $path_project gen
# Format generated gencpp
Write-Host "`nBeginning format"
$formatParams = @(
'-i' # In-place
'-style=file:./scripts/.clang-format'
'-verbose'
)
$include = @(
'gen.hpp', 'gen.cpp',
'gen.dep.hpp', 'gen.dep.cpp',
'gen.builder.hpp', 'gen.builder.cpp'
'gen.scanner.hpp', 'gen.scanner.cpp'
)
$exclude = $null
$targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
$time_taken = Measure-Command {
clang-format $formatParams $targetFiles
}
Write-Host "`nFormatting complete in $($time_taken.TotalMilliseconds) ms"
}
if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) )
{
$path_gen = join-path $path_singleheader gen
# Format generated gencpp
Write-Host "`nBeginning format"
$formatParams = @(
'-i' # In-place
'-style=file:./scripts/.clang-format'
'-verbose'
)
$include = @(
'gen.hpp'
)
$exclude = $null
$targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
$time_taken = Measure-Command {
clang-format $formatParams $targetFiles
}
Write-Host "`nFormatting complete in $($time_taken.TotalMilliseconds) ms"
}
if ( $test )
{
}
#endregion Formatting
Pop-Location # $path_root

View File

@ -20,4 +20,4 @@ if ( -not (Test-Path $vs_devshell) ) {
# Launch the Visual Studio Developer Shell # Launch the Visual Studio Developer Shell
Push-Location Push-Location
& $vs_devshell @args & $vs_devshell @args
Pop-Location Pop-Location

View File

@ -1,6 +1,13 @@
cls cls
Invoke-Expression "& $(Join-Path $PSScriptRoot 'bootstrap.ci.ps1')"
Invoke-Expression "& $(Join-Path $PSScriptRoot 'singleheader.ci.ps1')" $build = Join-Path $PSScriptRoot 'build.ci.ps1'
if ( $IsWindows ) {
& $build release msvc bootstrap singleheader
}
else {
& $build release clang bootstrap singleheader
}
$path_root = git rev-parse --show-toplevel $path_root = git rev-parse --show-toplevel
$path_docs = Join-Path $path_root docs $path_docs = Join-Path $path_root docs
@ -24,10 +31,10 @@ $readme_root = Join-Path $path_root Readme.md
$readme_docs = Join-Path $path_docs Readme.md $readme_docs = Join-Path $path_docs Readme.md
$readme_parsing = Join-Path $path_docs Parsing.md $readme_parsing = Join-Path $path_docs Parsing.md
Copy-Item $license -Destination $(Join-Path $path_release_content "LICENSE") Copy-Item $license -Destination (Join-Path $path_release_content "LICENSE")
Copy-Item $readme_root -Destination $(Join-Path $path_release_content "Readme.md") Copy-Item $readme_root -Destination (Join-Path $path_release_content "Readme.md")
Copy-Item $readme_docs -Destination $(Join-Path $path_release_content "Readme_Docs.md") Copy-Item $readme_docs -Destination (Join-Path $path_release_content "Readme_Docs.md")
Copy-Item $readme_parsing -Destination $(Join-Path $path_release_content "Parsing.md") Copy-Item $readme_parsing -Destination (Join-Path $path_release_content "Parsing.md")
# Singleheader # Singleheader
Copy-Item -Path $path_singleheader_gen\gen.hpp -Destination $path_release_content\gen.hpp Copy-Item -Path $path_singleheader_gen\gen.hpp -Destination $path_release_content\gen.hpp

View File

@ -1,45 +0,0 @@
[string] $type = $null
[string] $test = $false
foreach ( $arg in $args )
{
if ( $arg -eq "test" )
{
$test = $true
}
else
{
$type = $arg
}
}
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_scripts = Join-Path $path_root scripts
$path_test = Join-Path $path_root test
$path_gen = Join-Path $path_test gen
$path_test_build = Join-Path $path_test build
$path_gen_build = Join-Path $path_gen build
write-host "`n`nBuilding Test`n"
if ( -not( Test-Path $path_gen_build ) )
{
# Generate build files for meta-program
Push-Location $path_gen
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_gen_build
& meson $args_meson
Pop-Location
}
# Compile meta-program
Push-Location $path_root
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_gen_build
& ninja $args_ninja
Pop-Location

View File

@ -1,2 +0,0 @@
cls
Invoke-Expression "& $(Join-Path $PSScriptRoot 'test.gen_build.ci.ps1') $args"

View File

@ -1,102 +0,0 @@
cls
[string] $type = $null
[string] $test = $false
foreach ( $arg in $args )
{
if ( $arg -eq "test" )
{
$test = $true
}
else
{
$type = $arg
}
}
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_scripts = Join-Path $path_root scripts
$path_test = Join-Path $path_root test
$path_gen = Join-Path $path_test gen
$path_test_build = Join-Path $path_test build
$path_gen_build = Join-Path $path_gen build
# Invoke-Expression "& $(Join-Path $PSScriptRoot 'bootstrap.ci.ps1')"
# Invoke-Expression "& $(Join-Path $PSScriptRoot 'singleheader.ci.ps1')"
write-host "`n`nBuilding Test`n"
if ( -not( Test-Path $path_gen_build ) )
{
# Generate build files for meta-program
Push-Location $path_gen
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_gen_build
& meson $args_meson
Pop-Location
}
# Compile meta-program
Push-Location $path_root
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_gen_build
& ninja $args_ninja
Pop-Location
Push-location $path_gen
# Run meta-program
$gencpp = Join-Path $path_gen_build gencpp.exe
Write-Host `nRunning tests...
& $gencpp
# Format generated files
$path_clang_format = Join-Path $path_scripts .clang-format
Write-Host `nBeginning format...
$formatParams = @(
'-i' # In-place
"-style=file:$path_clang_format" # Search for a .clang-format file in the parent directory of the source file.
'-verbose'
)
$include = @('*.gen.hpp', '*.gen.cpp')
$exclude = $null
$targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
clang-format $formatParams $targetFiles
Write-Host "`nFormatting complete"
Pop-Location
# Build the program depending on generated files.
if ( -not( Test-Path $path_test_build ) )
{
Push-Location $path_test
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_test_build
# & meson $args_meson
Pop-Location
}
Push-Location $path_root
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_test_build
# ninja $args_ninja
Pop-Location
Push-Location $path_test
$testcpp = Join-Path $path_test_build testcpp.exe
# & $testcpp
Pop-Location

View File

@ -2,8 +2,8 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen/gen.hpp" #include "gen.hpp"
#include "gen/gen.builder.hpp" #include "gen.builder.hpp"
using namespace gen; using namespace gen;
Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 ) Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )

View File

@ -1,27 +0,0 @@
project( 'test', 'c', 'cpp', default_options : ['buildtype=debug'] )
# add_global_arguments('-E', language : 'cpp')
includes = include_directories(
[
'../../project',
# '../../thirdparty'
])
# get_sources = files('./get_sources.ps1')
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
sources = [ '../test.cpp' ]
if get_option('buildtype').startswith('debug')
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
# add_project_arguments('-E', language : ['c', 'cpp'])
endif
# add_project_arguments('-E', language : ['c', 'cpp'])
# add_global_arguments( '-E', language : ['cpp'])
add_project_arguments('-DGEN_TIME', language : ['c', 'cpp'])
executable( 'gencpp', sources, include_directories : includes )

View File

@ -1,25 +0,0 @@
project( 'test', 'c', 'cpp', default_options : ['buildtype=debug'] )
# add_global_arguments('-E', language : 'cpp')
includes = include_directories(
[
'./gen',
'../project',
# '../thirdparty'
])
# get_sources = files('./get_sources.ps1')
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
sources = [ 'test.cpp' ]
if get_option('buildtype').startswith('debug')
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
endif
add_project_arguments('-Druntime', language : ['c', 'cpp'])
executable( 'testcpp', sources, include_directories : includes )

View File

@ -4,8 +4,8 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen/gen.hpp" #include "gen.hpp"
#include "gen/gen.builder.hpp" #include "gen.builder.hpp"
void check_sanity() void check_sanity()
{ {

View File

@ -2,8 +2,8 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen/gen.cpp" #include "gen.cpp"
#include "gen/gen.builder.cpp" #include "gen.builder.cpp"
#include "sanity.cpp" #include "sanity.cpp"
#include "SOA.cpp" #include "SOA.cpp"
#include "test.singleheader_ast.cpp" #include "test.singleheader_ast.cpp"

View File

@ -2,9 +2,9 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen/gen.hpp" #include "gen.hpp"
#include "gen/gen.builder.hpp" #include "gen.builder.hpp"
#include "gen/gen.scanner.hpp" #include "gen.scanner.hpp"
using namespace gen; using namespace gen;
void check_singleheader_ast() void check_singleheader_ast()