Created
November 10, 2024 20:10
-
-
Save zenspider/ee3801a9cc5e554a5a8568bee2dc595b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn build(b: *std.Build) void { | |
const target = b.standardTargetOptions(.{}); | |
const optimize = b.standardOptimizeOption(.{}); | |
// TODO: import cppunit as direct build | |
const flags = .{ | |
// TODO: "-std=c++17", | |
"-std=c++11", // TODO: antlr requires 11, we use headers, soooo | |
"-g", | |
"-pedantic", | |
"-Wall", | |
"-W", | |
"-Werror", | |
"-Waggregate-return", | |
"-Wcast-align", | |
"-Wcast-qual", | |
"-Wconversion", | |
"-Winline", | |
"-Wmissing-noreturn", | |
"-Wmissing-prototypes", | |
"-Wno-deprecated", | |
"-Wno-missing-field-initializers", | |
"-Wno-self-assign-overloaded", | |
"-Wno-sign-conversion", | |
"-Wpointer-arith", | |
"-Wredundant-decls", | |
"-Wsign-compare", | |
"-Wstrict-prototypes", | |
"-Wundef", | |
"-Wwrite-strings", | |
}; | |
const antlr_flags = .{ | |
"-std=c++11", // TODO: antlr requires 11 | |
"-g", | |
"-pedantic", | |
"-Wall", | |
"-W", | |
// TODO: "-Werror", | |
"-Waggregate-return", | |
"-Wcast-align", | |
"-Wcast-qual", | |
"-Wconversion", | |
"-Winline", | |
"-Wmissing-noreturn", | |
"-Wmissing-prototypes", | |
"-Wno-deprecated", | |
"-Wno-missing-field-initializers", | |
"-Wno-self-assign-overloaded", | |
"-Wno-sign-conversion", | |
"-Wpointer-arith", | |
"-Wredundant-decls", | |
"-Wsign-compare", | |
"-Wstrict-prototypes", | |
"-Wundef", | |
"-Wwrite-strings", | |
}; | |
//////////////////////////////////////////////////////////// | |
// cppunit (ugh!): | |
const cppunit = b.addStaticLibrary(.{ | |
.name = "cppunit", | |
.target = target, | |
.optimize = optimize, | |
}); | |
cppunit.addIncludePath(b.path("src/cppunit/include")); | |
cppunit.linkLibCpp(); | |
const MESSY_flags = .{ | |
"-std=c++17", | |
"-g", | |
"-pedantic", | |
"-Wall", | |
"-W", | |
"-Werror", | |
"-Waggregate-return", | |
"-Wcast-align", | |
"-Wconversion", | |
"-Winline", | |
"-Wmissing-prototypes", | |
"-Wno-deprecated", | |
"-Wno-missing-field-initializers", | |
"-Wno-self-assign-overloaded", | |
"-Wno-sign-conversion", | |
"-Wno-shorten-64-to-32", | |
"-Wpointer-arith", | |
"-Wredundant-decls", | |
"-Wsign-compare", | |
"-Wstrict-prototypes", | |
"-Wundef", | |
"-Wwrite-strings", | |
}; | |
cppunit.addCSourceFiles(.{ | |
.files = &.{ | |
"src/cppunit/src/cppunit/AdditionalMessage.cpp", | |
"src/cppunit/src/cppunit/Asserter.cpp", | |
"src/cppunit/src/cppunit/BriefTestProgressListener.cpp", | |
"src/cppunit/src/cppunit/CompilerOutputter.cpp", | |
"src/cppunit/src/cppunit/DefaultProtector.cpp", | |
"src/cppunit/src/cppunit/DynamicLibraryManager.cpp", | |
"src/cppunit/src/cppunit/DynamicLibraryManagerException.cpp", | |
"src/cppunit/src/cppunit/Exception.cpp", | |
"src/cppunit/src/cppunit/Message.cpp", | |
"src/cppunit/src/cppunit/PlugInManager.cpp", | |
"src/cppunit/src/cppunit/PlugInParameters.cpp", | |
"src/cppunit/src/cppunit/Protector.cpp", | |
"src/cppunit/src/cppunit/ProtectorChain.cpp", | |
"src/cppunit/src/cppunit/RepeatedTest.cpp", | |
"src/cppunit/src/cppunit/ShlDynamicLibraryManager.cpp", | |
"src/cppunit/src/cppunit/SourceLine.cpp", | |
"src/cppunit/src/cppunit/StringTools.cpp", | |
"src/cppunit/src/cppunit/SynchronizedObject.cpp", | |
"src/cppunit/src/cppunit/Test.cpp", | |
"src/cppunit/src/cppunit/TestAssert.cpp", | |
"src/cppunit/src/cppunit/TestCase.cpp", | |
"src/cppunit/src/cppunit/TestCaseDecorator.cpp", | |
"src/cppunit/src/cppunit/TestComposite.cpp", | |
"src/cppunit/src/cppunit/TestDecorator.cpp", | |
"src/cppunit/src/cppunit/TestFactoryRegistry.cpp", | |
"src/cppunit/src/cppunit/TestFailure.cpp", | |
"src/cppunit/src/cppunit/TestLeaf.cpp", | |
"src/cppunit/src/cppunit/TestNamer.cpp", | |
"src/cppunit/src/cppunit/TestPath.cpp", | |
"src/cppunit/src/cppunit/TestPlugInDefaultImpl.cpp", | |
"src/cppunit/src/cppunit/TestResult.cpp", | |
"src/cppunit/src/cppunit/TestResultCollector.cpp", | |
"src/cppunit/src/cppunit/TestRunner.cpp", | |
"src/cppunit/src/cppunit/TestSetUp.cpp", | |
"src/cppunit/src/cppunit/TestSuccessListener.cpp", | |
"src/cppunit/src/cppunit/TestSuite.cpp", | |
"src/cppunit/src/cppunit/TestSuiteBuilderContext.cpp", | |
"src/cppunit/src/cppunit/TextOutputter.cpp", | |
"src/cppunit/src/cppunit/TextTestProgressListener.cpp", | |
"src/cppunit/src/cppunit/TextTestResult.cpp", | |
"src/cppunit/src/cppunit/TextTestRunner.cpp", | |
"src/cppunit/src/cppunit/TypeInfoHelper.cpp", | |
"src/cppunit/src/cppunit/UnixDynamicLibraryManager.cpp", | |
"src/cppunit/src/cppunit/XmlDocument.cpp", | |
"src/cppunit/src/cppunit/XmlElement.cpp", | |
"src/cppunit/src/cppunit/XmlOutputter.cpp", | |
"src/cppunit/src/cppunit/XmlOutputterHook.cpp", | |
}, | |
.flags = &MESSY_flags, | |
}); | |
b.installArtifact(cppunit); | |
//////////////////////////////////////////////////////////// | |
// Low: | |
const low = b.addStaticLibrary(.{ | |
.name = "low", | |
.target = target, | |
.optimize = optimize, | |
}); | |
low.addIncludePath(b.path("src")); | |
low.linkLibCpp(); | |
low.addCSourceFiles(.{ | |
.files = &.{ | |
"src/low/boolean.cc", | |
"src/low/debug.cc", | |
"src/low/flt.cc", | |
"src/low/sinteger.cc", | |
"src/low/str.cc", | |
"src/low/tracer.cc", | |
"src/low/uinteger.cc", | |
}, | |
.flags = &flags, | |
}); | |
b.installArtifact(low); | |
const low_tests = b.addExecutable(.{ | |
.name = "test-low", | |
.root_source_file = b.path("src/low/main.zig"), | |
.target = target, | |
.optimize = optimize, | |
}); | |
low_tests.addIncludePath(b.path("src")); | |
low_tests.addIncludePath(b.path("src/cppunit/include")); | |
low_tests.linkLibCpp(); | |
low_tests.linkLibrary(cppunit); | |
low_tests.linkLibrary(low); | |
low_tests.addCSourceFiles(.{ | |
.files = &.{ | |
"src/low/block_test.cc", | |
"src/low/boolean_test.cc", | |
"src/low/debug_test.cc", | |
"src/low/dynblock_test.cc", | |
"src/low/flt_test.cc", | |
"src/low/list_test.cc", | |
"src/low/listnode_test.cc", | |
"src/low/ptr_test.cc", | |
"src/low/queue_test.cc", | |
"src/low/sinteger_test.cc", | |
"src/low/stack_test.cc", | |
"src/low/str_test.cc", | |
"src/low/template_test.cc", | |
"src/low/tracer_test.cc", | |
"src/low/uinteger_test.cc", | |
"src/low/test_suite.cc", | |
}, | |
.flags = &flags, | |
}); | |
const run_low_tests = b.addRunArtifact(low_tests); | |
b.installArtifact(low_tests); | |
//////////////////////////////////////////////////////////// | |
// Medium: | |
const med = b.addStaticLibrary(.{ | |
.name = "med", | |
.target = target, | |
.optimize = optimize, | |
}); | |
med.addIncludePath(b.path("src")); | |
med.addIncludePath(b.path("src/medium")); // TODO: remove | |
med.linkLibCpp(); | |
med.linkLibrary(low); | |
med.addCSourceFiles(.{ | |
.files = &.{ | |
"src/medium/gc/gcable.cc", | |
"src/medium/gc/memory.cc", | |
"src/medium/objects/arrayptr.cc", | |
"src/medium/objects/assocptr.cc", | |
"src/medium/objects/charptr.cc", | |
"src/medium/objects/classptr.cc", | |
"src/medium/objects/cntxptr.cc", | |
"src/medium/objects/descptr.cc", | |
"src/medium/objects/dictptr.cc", | |
"src/medium/objects/floatptr.cc", | |
"src/medium/objects/gobjects.cc", | |
"src/medium/objects/intptr.cc", | |
"src/medium/objects/methptr.cc", | |
"src/medium/objects/nodeptr.cc", | |
"src/medium/objects/object.cc", | |
"src/medium/objects/objptr.cc", | |
"src/medium/objects/stackptr.cc", | |
"src/medium/objects/strptr.cc", | |
"src/medium/objects/symptr.cc", | |
"src/medium/tools/bytestor.cc", | |
"src/medium/tools/mbuilder.cc", | |
}, | |
.flags = &flags, | |
}); | |
b.installArtifact(med); | |
const med_tests = b.addExecutable(.{ | |
.name = "test-med", | |
.root_source_file = b.path("src/medium/main.zig"), | |
.target = target, | |
.optimize = optimize, | |
}); | |
med_tests.addIncludePath(b.path("src")); | |
med_tests.addIncludePath(b.path("src/medium")); // TODO: remove | |
med_tests.addIncludePath(b.path("src/cppunit/include")); | |
med_tests.linkLibCpp(); | |
med_tests.linkLibrary(low); | |
med_tests.linkLibrary(med); | |
med_tests.linkLibrary(cppunit); | |
med_tests.addCSourceFiles(.{ | |
.files = &.{ | |
"src/medium/test_suite.cc", | |
"src/medium/gc/memory_test.cc", | |
"src/medium/objects/arrayptr_test.cc", | |
// "src/medium/objects/assocptr_test.cc", | |
"src/medium/objects/charptr_test.cc", | |
// "src/medium/objects/classptr_test.cc", | |
"src/medium/objects/cntxptr_test.cc", | |
"src/medium/objects/descptr_test.cc", | |
"src/medium/objects/dictptr_test.cc", // next | |
"src/medium/objects/floatptr_test.cc", | |
"src/medium/objects/intptr_test.cc", | |
"src/medium/objects/methptr_test.cc", | |
// "src/medium/objects/nodeptr_test.cc", | |
"src/medium/objects/objptr_test.cc", | |
"src/medium/objects/stackptr_test.cc", | |
"src/medium/objects/strptr_test.cc", | |
"src/medium/objects/symptr_test.cc", | |
}, | |
.flags = &flags, | |
}); | |
const run_med_tests = b.addRunArtifact(med_tests); | |
b.installArtifact(med_tests); | |
//////////////////////////////////////////////////////////// | |
// Antlr: ugh | |
const antlr = b.addStaticLibrary(.{ | |
.name = "antlr", | |
.target = target, | |
.optimize = optimize, | |
}); | |
antlr.addIncludePath(b.path("src")); | |
antlr.linkLibCpp(); | |
antlr.addCSourceFiles(.{ | |
.files = &.{ | |
"src/antlr/ANTLRUtil.cpp", | |
"src/antlr/ASTFactory.cpp", | |
"src/antlr/ASTNULLType.cpp", | |
"src/antlr/ASTRefCount.cpp", | |
"src/antlr/BaseAST.cpp", | |
"src/antlr/BitSet.cpp", | |
"src/antlr/CharBuffer.cpp", | |
"src/antlr/CharScanner.cpp", | |
"src/antlr/CommonAST.cpp", | |
"src/antlr/CommonASTWithHiddenTokens.cpp", | |
"src/antlr/CommonHiddenStreamToken.cpp", | |
"src/antlr/CommonToken.cpp", | |
"src/antlr/InputBuffer.cpp", | |
"src/antlr/LLkParser.cpp", | |
"src/antlr/MismatchedCharException.cpp", | |
"src/antlr/MismatchedTokenException.cpp", | |
"src/antlr/NoViableAltException.cpp", | |
"src/antlr/NoViableAltForCharException.cpp", | |
"src/antlr/Parser.cpp", | |
"src/antlr/RecognitionException.cpp", | |
"src/antlr/String.cpp", | |
"src/antlr/Token.cpp", | |
"src/antlr/TokenBuffer.cpp", | |
"src/antlr/TokenStreamBasicFilter.cpp", | |
"src/antlr/TokenStreamHiddenTokenFilter.cpp", | |
"src/antlr/TokenStreamSelector.cpp", | |
"src/antlr/TokenStreamRewriteEngine.cpp", | |
"src/antlr/TreeParser.cpp", | |
"src/antlr/TokenRefCount.cpp", | |
}, | |
.flags = &antlr_flags, | |
}); | |
b.installArtifact(antlr); | |
//////////////////////////////////////////////////////////// | |
// High: | |
const high = b.addStaticLibrary(.{ | |
.name = "high", | |
.target = target, | |
.optimize = optimize, | |
}); | |
high.addIncludePath(b.path("src")); | |
high.addIncludePath(b.path("src/medium")); // TODO: remove | |
high.addIncludePath(b.path("src/high")); // TODO: remove | |
high.linkLibCpp(); | |
// high.linkLibrary(low); | |
high.linkLibrary(med); | |
high.linkLibrary(antlr); | |
high.addCSourceFiles(.{ | |
.files = &.{ | |
"src/high/grammar/grammar_utils.cc", | |
"src/high/grammar/ST80Lexer.cpp", | |
"src/high/grammar/ST80Parser.cpp", | |
"src/high/interpre/doprim.cc", | |
"src/high/interpre/interpre.cc", | |
"src/high/interpre/primdana.cc", | |
"src/high/interpre/primmatt.cc", | |
"src/high/interpre/vcpu.cc", | |
"src/high/main/satori.cc", | |
}, | |
.flags = &flags, | |
}); | |
b.installArtifact(high); | |
const high_tests = b.addExecutable(.{ | |
.name = "test-high", | |
.root_source_file = b.path("src/high/main.zig"), | |
.target = target, | |
.optimize = optimize, | |
}); | |
high_tests.addIncludePath(b.path("src")); | |
high_tests.addIncludePath(b.path("src/low")); // TODO: remove | |
high_tests.addIncludePath(b.path("src/medium")); // TODO: remove | |
high_tests.addIncludePath(b.path("src/high")); // TODO: remove | |
high_tests.addIncludePath(b.path("src/cppunit/include")); | |
high_tests.linkLibCpp(); | |
high_tests.linkLibrary(cppunit); | |
high_tests.linkLibrary(low); | |
high_tests.linkLibrary(med); | |
high_tests.linkLibrary(antlr); | |
high_tests.linkLibrary(high); | |
high_tests.addCSourceFiles(.{ | |
.files = &.{ | |
"src/high/test_suite.cc", | |
"src/high/grammar/grammar_test.cc", | |
}, | |
.flags = &flags, | |
}); | |
const run_high_tests = b.addRunArtifact(high_tests); | |
b.installArtifact(high_tests); | |
//////////////////////////////////////////////////////////// | |
// Steps: | |
const test_all_step = b.step("test", "Run all tests"); | |
test_all_step.dependOn(&run_low_tests.step); | |
test_all_step.dependOn(&run_med_tests.step); | |
test_all_step.dependOn(&run_high_tests.step); | |
const test_low_step = b.step("test-low", "Run low tests"); | |
test_low_step.dependOn(&run_low_tests.step); | |
const test_med_step = b.step("test-med", "Run medium tests"); | |
test_med_step.dependOn(&run_med_tests.step); | |
const test_high_step = b.step("test-high", "Run high tests"); | |
test_high_step.dependOn(&run_high_tests.step); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment