Created
August 6, 2017 19:50
-
-
Save mortoray/0eff2a9a066ad48a6aedab8766503865 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
import os | |
Import('baseEnv') | |
env = baseEnv.Clone() | |
env.Append( LIBPATH = './' ) | |
# include LLVM | |
env.Append( LIBPATH = '$LLVM_DIR/lib' ) | |
env.Append( CXXFLAGS = ['-isystem','$LLVM_DIR/include'] ) | |
env.AppendENVPath( 'LD_LIBRARY_PATH', env.subst( '$LLVM_DIR/lib' ) ) | |
# include GMP | |
env.Append( LIBPATH = '$GMP_DIR/lib' ) | |
env.Append( CXXFLAGS = ['-isystem','$GMP_DIR/include'] ) | |
env.AppendENVPath( 'LD_LIBRARY_PATH', env.subst( '$GMP_DIR/lib' ) ) | |
if env["IS_POSIX"]: | |
lib_llvm = 'LLVM-3.8.so' | |
else: | |
lib_llvm = 'LLVM' | |
conf = Configure(env) | |
for lib in [ 'boost_regex', lib_llvm, 'libgmp', 'libgmpxx', 'boost_filesystem', 'boost_system' ]: | |
if not conf.CheckLib( lib ): | |
Exit(1) | |
# this messes up the CheckLib on OSX | |
env['RPATH'] = Literal('\\$$ORIGIN') | |
if env['IS_POSIX']: | |
env.Append(LINKFLAGS=['-z','origin']) | |
env = conf.Finish() | |
#env['SHLIBVERSION'] = '0.0.1' | |
# Using names for library references to avoid having any path information in the link table | |
lib_util_name = 'leaf_util' | |
lib_util = env.SharedLibrary( lib_util_name, [ | |
'util/dump_base.cpp', | |
'util/file.cpp', | |
'util/number.cpp', | |
'util/object_holder.cpp', | |
'util/unicode.cpp', | |
] ) | |
lib_lang_name = 'leaf_lang' | |
lib_lang = env.SharedLibrary( lib_lang_name, [ | |
'lang/assign_statement.cpp', | |
'lang/cerr.cpp', | |
'lang/class_typer.cpp', | |
'lang/context.cpp', | |
'lang/conversion_applicator.cpp', | |
'lang/declaration.cpp', | |
'lang/do_statement.cpp', | |
'lang/dump.cpp', | |
'lang/error_statement.cpp', | |
'lang/expression.cpp', | |
'lang/expression_statement.cpp', | |
'lang/expression_visitor.cpp', | |
'lang/for_statement.cpp', | |
'lang/import_statement.cpp', | |
'lang/init_statement.cpp', | |
'lang/intr_type.cpp', | |
'lang/loop_flow_statement.cpp', | |
'lang/module.cpp', | |
'lang/module_loader.cpp', | |
'lang/noop_statement.cpp', | |
'lang/return_statement.cpp', | |
'lang/scope.cpp', | |
'lang/scope_ref.cpp', | |
'lang/serial.cpp', | |
'lang/serial_expression.cpp', | |
'lang/serial_type.cpp', | |
'lang/statement_block.cpp', | |
'lang/statement.cpp', | |
'lang/statement_importer.cpp', | |
'lang/statement_visitor.cpp', | |
'lang/type_converter.cpp', | |
'lang/type_identifier.cpp', | |
'lang/type_manager.cpp', | |
'lang/typer.cpp', | |
'lang/type_ref.cpp', | |
'lang/type_spec.cpp', | |
'lang/typedef_statement.cpp', | |
'lang/var_statement.cpp', | |
'lang/expression_typer/builtin.cpp', | |
'lang/expression_typer/common.cpp', | |
'lang/expression_typer/fields.cpp', | |
'lang/expression_typer/funccall.cpp', | |
'lang/expression_typer/funcdefn.cpp', | |
'lang/expression_typer/funccall_ctor.cpp', | |
'lang/expression_typer/funccall_type.cpp', | |
'parser/intr_type_parser.cpp', | |
'parser/node_parser.cpp', | |
'parser/node_converter.cpp', | |
'parser/dump.cpp', | |
'parser/source.cpp', | |
], | |
LIBS = env['LIBS'] +[ lib_util_name ], | |
) | |
# It was easier to move this up to the above for now, OSX didn't like the dump cross-dependency | |
# (it is a bad thing in the code, injected parser "node" into the "type_spec" class!) | |
lib_parser_name = 'leaf_parser' | |
lib_parser = env.SharedLibrary( lib_parser_name, [ | |
#'parser/intr_type_parser.cpp', | |
#'parser/node_parser.cpp', | |
#'parser/node_converter.cpp', | |
#'parser/dump.cpp', | |
#'parser/source.cpp', | |
#lib_util,lib_lang | |
]) | |
lib_ir_name = 'leaf_ir' | |
lib_ir = env.SharedLibrary( lib_ir_name, [ | |
'ir/block.cpp', | |
'ir/compiler.cpp', | |
'ir/compiler_leaf.cpp', | |
'ir/dump.cpp', | |
'ir/function.cpp', | |
'ir/instruction.cpp', | |
'ir/module.cpp', | |
'ir/std_functions.cpp', | |
'ir/trace_functions.cpp', | |
'ir/type.cpp', | |
'ir/type_manager.cpp', | |
'ir/type_manager_leaf.cpp', | |
'ir/value.cpp', | |
], | |
LIBS = env['LIBS'] +[ lib_util_name, lib_lang_name ], | |
) | |
lib_ir_llvm_name = 'leaf_ir_llvm' | |
lib_ir_llvm = env.SharedLibrary( lib_ir_llvm_name, [ | |
'ir/llvm/builder.cpp', | |
'ir/llvm/gen.cpp', | |
#'ir/llvm/runtime_exception.cpp', | |
'ir/llvm/runtime_test.cpp', | |
'ir/llvm/type_manager.cpp', | |
], | |
LIBS = env['LIBS'] +[ lib_ir_name, lib_util_name ], | |
) | |
lib_runner_name = 'leaf_runner' | |
lib_runner = env.SharedLibrary( lib_runner_name, [ | |
'runner/runner.cpp', | |
], | |
LIBS = env['LIBS'] +[ lib_lang_name, lib_parser_name, lib_util_name, lib_ir_name, lib_ir_llvm_name ], | |
) | |
bo = env.Object( 'boost_test_main', 'test/boost_test_main.cpp' ) | |
unit_test = env.Program('unit_test', [ | |
bo, | |
'test/expr_conversion_test.cpp', | |
'test/statement_test.cpp', | |
'test/expr_type_test.cpp', | |
'test/full_type_test.cpp', | |
'test/gmp_test.cpp', | |
'test/intr_type_parse_test.cpp', | |
'test/lambda_test.cpp', | |
'test/number_test.cpp', | |
'test/object_holder_test.cpp', | |
'test/parse_test.cpp', | |
'test/scope_test.cpp', | |
'test/source_test.cpp', | |
'test/type_converter_cost.cpp', | |
'test/type_converter_fixate.cpp', | |
'test/type_converter_function_call.cpp', | |
'test/type_converter_match_function.cpp', | |
'test/type_converter_parameterize_type.cpp', | |
'test/type_converter_test.cpp', | |
'test/type_converter_unify.cpp', | |
'test/type_identifier_constrain.cpp', | |
'test/type_identifier_determine.cpp', | |
'test/type_identifier_expand.cpp', | |
'test/type_identifier_get_spec.cpp', | |
'test/type_identifier_infer.cpp', | |
'test/unicode_test.cpp', | |
lib_lang, lib_parser, lib_util, lib_runner, lib_ir, lib_ir_llvm, | |
]) | |
env.AddUnitTest( unit_test ) | |
# Other support files | |
def RawStringIt(varName): | |
def Impl(target, source, env): | |
content = source[0].get_text_contents() | |
with open(target[0].get_path(), 'w') as target_file: | |
target_file.write( "std::string {} = R\"~~~~({})~~~~\";".format(varName,content)) | |
return 0 | |
return Action(Impl, "creating C++ Raw String $TARGET from $SOURCE" ) | |
base_leaf = env.Command( 'include/runner/base.leaf.hpp', 'runner/base.leaf', RawStringIt("dataBaseLeaf") ) | |
base_unit_test = env.Command( 'include/runner/unit_test.leaf.hpp', 'runner/unit_test.leaf', RawStringIt("dataUnitTestLeaf") ) | |
leaf = env.Program( 'leaf', [ | |
'bin/leaf.cpp', | |
'bin/test_expecter.cpp', | |
], | |
LIBS = env['LIBS'] + [ lib_lang_name, lib_parser_name, lib_util_name, lib_ir_name, lib_ir_llvm_name, lib_runner_name ], | |
) | |
env.Requires( leaf, [base_leaf, base_unit_test] ) | |
leaf_dump = env.Program( 'leaf_dump', [ | |
'bin/leaf_dump.cpp', | |
lib_lang, lib_util, lib_parser, | |
]) | |
platform_check = env.Program( 'platform_check', [ 'bin/platform_check.cpp' ] ) | |
# Object files for static linking Leaf | |
lro_support = env.Object( 'leaf_runtime_support.o', 'ir/llvm/runtime_support.cpp' ) | |
# Shared for PIC linking (required for DWARF/EH) | |
lro_so = env.SharedLibrary( 'leaf_runtime', [ | |
'ir/llvm/runtime_support.cpp', | |
]) | |
test_node = env.Command( '#/.check/leaf_expr_tests', [ leaf, lro_support, lro_so], [ | |
'src/bin/with_env.sh src/bin/run_tests.py --all', | |
]) | |
env.Depends( test_node, unit_test ) | |
env.Alias( 'test-node', test_node ) | |
env.Alias( 'check', test_node ) | |
env.AlwaysBuild( test_node ) | |
# More permutations on testing to be run on merge and when doing flow changes | |
flow_test_node = env.Command( '#/.check/leaf_flow_tests', [ test_node ], [ | |
'src/bin/with_env.sh src/bin/run_tests.py --all', | |
'src/bin/with_env.sh src/bin/run_tests.py --all --leaf-opts', | |
'src/bin/with_env.sh src/bin/run_tests.py --all --no-opts', | |
]) | |
env.Alias( 'check-full', flow_test_node ) | |
env.AlwaysBuild( flow_test_node ) | |
# Environment file for running commands/tests | |
replace_dict = { | |
'%LLVM_LIB_DIR%': '$LLVM_DIR/lib', | |
'%GMP_LIB_DIR%': '$GMP_DIR/lib', | |
'%BUILD_DIR%': '$ABS_BUILD_DIR', | |
} | |
src_env = 'env.sh.in' | |
if env['IS_DARWIN']: | |
src_env = 'env.sh.in_darwin' | |
env_file = env.Substfile( src_env, SUBST_DICT = replace_dict ) | |
env.Alias( 'check', env_file ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment