-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
189 additions
and
135 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
# matcheroni/build.hancho | ||
|
||
hancho.build_tag = "debug" | ||
import hancho | ||
|
||
hancho.rules = hancho.load("config/rules.hancho") | ||
hancho.c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho") | ||
hancho.c_parser = hancho.load("examples/c_parser/c_parser.hancho") | ||
imports.config = hancho.Config(build_tag = "debug") | ||
imports.rules = hancho.load("config/rules.hancho", imports) | ||
imports.c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho", imports) | ||
imports.c_parser = hancho.load("examples/c_parser/c_parser.hancho", imports) | ||
|
||
hancho.rules.c_library("examples/ini/ini_parser.cpp", "examples/ini/ini_parser.a") | ||
exports.c_lexer = imports.c_lexer | ||
exports.c_parser = imports.c_parser | ||
exports.json = hancho.load("examples/json/json.hancho", imports) | ||
exports.regex = hancho.load("examples/regex/regex.hancho", imports) | ||
exports.toml = hancho.load("examples/toml/toml.hancho", imports) | ||
exports.tests = hancho.load("tests/tests.hancho", imports) | ||
exports.tutorial = hancho.load("examples/tutorial/tutorial.hancho", imports) | ||
|
||
hancho.load("examples/json/json.hancho") | ||
hancho.load("examples/regex/regex.hancho") | ||
hancho.load("examples/toml/toml.hancho") | ||
hancho.load("tests/tests.hancho") | ||
hancho.load("examples/tutorial/tutorial.hancho") | ||
exports.ini = imports.rules.c_library( | ||
imports.config, | ||
in_srcs = "examples/ini/ini_parser.cpp", | ||
out_lib = "examples/ini/ini_parser.a", | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,73 @@ | ||
# matcheroni/config/rules.hancho | ||
|
||
#------------------------------------------------------------------------------- | ||
import hancho | ||
|
||
compile_cpp = hancho.command( | ||
desc = "Compiling {rel_source_files} -> {rel_build_files} ({build_tag})", | ||
command = "g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {rel_source_files} -o {rel_build_files}", | ||
cpp_std = "-std=c++20", | ||
gcc_opt = "{'-O3' if build_tag == 'release' else '-g -O0'} -MMD", | ||
warnings = "-Wall -Werror -Wno-unused-variable -Wno-unused-local-typedefs -Wno-unused-but-set-variable", | ||
includes = "-I{repo_path}", | ||
defines = "", | ||
build_files = "{swap_ext(source_files, '.o')}", | ||
build_deps = "{swap_ext(source_files, '.d')}", | ||
) | ||
#------------------------------------------------------------------------------- | ||
|
||
link_c_lib = hancho.command( | ||
desc = "Bundling {rel_build_files}", | ||
command = "ar rcs {rel_build_files} {rel_source_files}", | ||
) | ||
def link_c_lib(in_objs, out_lib, *args, **kwargs): | ||
config = hancho.Config(*args, **kwargs) | ||
command = hancho.Config( | ||
desc = "Bundling {rel(out_lib)}", | ||
command = "ar rcs {rel(out_lib)} {rel(in_objs)}", | ||
) | ||
return command(config, in_objs = in_objs, out_lib = out_lib) | ||
|
||
link_c_bin = hancho.command( | ||
desc = "Linking {rel_build_files}", | ||
command = "g++ {ld_opt} {warnings} {rel_source_files} {libs} {sys_libs} -o {rel_build_files}", | ||
ld_opt = "{'-O3' if build_tag == 'release' else '-g -O0'}", | ||
libs = "", | ||
sys_libs = "", | ||
warnings = "-Wall", | ||
) | ||
|
||
run_c_test = hancho.command( | ||
desc = "Running test {rel_source_files}", | ||
command = "rm -f {rel_build_files} && {rel_source_files} {args} && touch {rel_build_files}", | ||
build_files = "{swap_ext(source_files, '.pass')}", | ||
args = "", | ||
) | ||
def link_c_bin(in_objs, out_bin, *args, **kwargs): | ||
config = hancho.Config(*args, **kwargs) | ||
command = hancho.Config( | ||
desc = "Linking {rel(out_bin)}", | ||
command = "g++ {ld_opt} {warnings} {rel(in_objs)} {libs} {sys_libs} -o {rel(out_bin)}", | ||
ld_opt = "{'-O3' if build_tag == 'release' else '-g -O0'}", | ||
libs = "", | ||
sys_libs = "", | ||
warnings = "-Wall", | ||
) | ||
return command(config, in_objs = in_objs, out_bin = out_bin) | ||
|
||
#------------------------------------------------------------------------------- | ||
|
||
def compile_srcs(config, source_files): | ||
objs = [] | ||
for file in hancho.flatten(source_files): | ||
if isinstance(file, hancho.Task): | ||
objs.append(file) | ||
else: | ||
objs.append(compile_cpp(file, config)) | ||
pass | ||
return objs | ||
def compile_srcs(*args, in_srcs, **kwargs): | ||
config = hancho.Config(*args, **kwargs) | ||
command = hancho.Config( | ||
desc = "Compiling {rel(in_src)} -> {rel(out_obj)} ({build_tag})", | ||
command = "g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {rel(in_src)} -o {rel(out_obj)}", | ||
cpp_std = "-std=c++20", | ||
gcc_opt = "{'-O3' if build_tag == 'release' else '-g -O0'} -MMD", | ||
warnings = "-Wall -Werror -Wno-unused-variable -Wno-unused-local-typedefs -Wno-unused-but-set-variable", | ||
includes = "-I{repo_path}", | ||
defines = "", | ||
out_obj = "{swap_ext(in_src, '.o')}", | ||
dep_gcc = "{swap_ext(in_src, '.d')}", | ||
) | ||
return [command(config, in_src = file) for file in hancho.flatten(in_srcs)] | ||
|
||
def c_binary(config): | ||
source_files = config.pop("source_files") | ||
build_files = config.pop("build_files") | ||
objs = compile_srcs(config, source_files) | ||
return link_c_bin(objs, build_files, config) | ||
def c_binary(*args, in_srcs = [], in_objs = [], out_bin, **kwargs): | ||
config = hancho.Config(*args, **kwargs) | ||
objs = compile_srcs(config, in_srcs = in_srcs) | ||
return link_c_bin(objs + in_objs, out_bin, config) | ||
|
||
def c_library(config): | ||
source_files = config.pop("source_files") | ||
build_files = config.pop("build_files") | ||
objs = compile_srcs(config, source_files) | ||
return link_c_lib(objs, build_files, config) | ||
def c_library(*args, in_srcs = [], in_objs = [], out_lib, **kwargs): | ||
config = hancho.Config(*args, **kwargs) | ||
objs = compile_srcs(config, in_srcs=in_srcs) | ||
return link_c_lib(objs + in_objs, out_lib, config) | ||
|
||
def c_test(config): | ||
return run_c_test(c_binary(config), config) | ||
def c_test(*args, in_srcs = [], in_objs = [], out_bin, **kwargs): | ||
config = hancho.Config(*args, **kwargs) | ||
objs = compile_srcs(config, in_srcs = in_srcs) | ||
bin = link_c_bin(objs + in_objs, out_bin, config) | ||
result = hancho.Task( | ||
config, | ||
desc = "Running test {rel(in_test)}", | ||
command = "rm -f {rel(out_pass)} && {in_test} {args} && touch {rel(out_pass)}", | ||
in_test = bin, | ||
out_pass = "{swap_ext(in_test, '.pass')}", | ||
args = "" | ||
) | ||
return result | ||
|
||
#------------------------------------------------------------------------------- | ||
|
||
export.c_binary = hancho.callback(c_binary) | ||
export.c_library = hancho.callback(c_library) | ||
export.c_test = hancho.callback(c_test) | ||
exports.c_binary = c_binary | ||
exports.c_library = c_library | ||
exports.c_test = c_test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
#------------------------------------------------------------------------------- | ||
# Matcheroni C lexer demo | ||
|
||
c_lexer_lib = hancho.rules.c_library( | ||
["CLexer.cpp", "CToken.cpp"], | ||
"c_lexer.a", | ||
rules = imports.rules | ||
config = imports.config | ||
|
||
c_lexer_lib = rules.c_library( | ||
config, | ||
in_srcs = ["CLexer.cpp", "CToken.cpp"], | ||
out_lib = "c_lexer.a", | ||
) | ||
|
||
hancho.rules.c_test( | ||
"c_lexer_test.cpp", | ||
"c_lexer_test", | ||
rules.c_test( | ||
config, | ||
in_srcs = "c_lexer_test.cpp", | ||
out_bin = "c_lexer_test", | ||
libs = c_lexer_lib, | ||
quiet = True, | ||
) | ||
|
||
hancho.rules.c_binary( | ||
"c_lexer_benchmark.cpp", | ||
"c_lexer_benchmark", | ||
libs = c_lexer_lib, | ||
rules.c_binary( | ||
config, | ||
in_srcs = "c_lexer_benchmark.cpp", | ||
out_bin = "c_lexer_benchmark", | ||
libs = c_lexer_lib, | ||
) | ||
|
||
export.lib = c_lexer_lib | ||
exports.lib = c_lexer_lib |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
#------------------------------------------------------------------------------- | ||
# Matcheroni JSON parser example | ||
|
||
json_parser = hancho.rules.c_library( | ||
["json_matcher.cpp", "json_parser.cpp"], | ||
"json_parser.a", | ||
rules = imports.rules | ||
config = imports.config | ||
|
||
json_parser = rules.c_library( | ||
config, | ||
in_srcs = ["json_matcher.cpp", "json_parser.cpp"], | ||
out_lib = "json_parser.a", | ||
) | ||
|
||
hancho.rules.c_binary( | ||
"json_conformance.cpp", | ||
"json_conformance", | ||
rules.c_binary( | ||
config, | ||
in_srcs = "json_conformance.cpp", | ||
out_bin = "json_conformance", | ||
libs = json_parser | ||
) | ||
|
||
hancho.rules.c_binary( | ||
"json_benchmark.cpp", | ||
"json_benchmark", | ||
rules.c_binary( | ||
config, | ||
in_srcs = "json_benchmark.cpp", | ||
out_bin = "json_benchmark", | ||
libs = json_parser, | ||
) | ||
|
||
hancho.rules.c_binary( | ||
"json_demo.cpp", | ||
"json_demo", | ||
rules.c_binary( | ||
config, | ||
in_srcs = "json_demo.cpp", | ||
out_bin = "json_demo", | ||
libs = json_parser, | ||
) | ||
|
||
hancho.rules.c_test( | ||
"json_test.cpp", | ||
"json_test", | ||
rules.c_test( | ||
config, | ||
in_srcs = "json_test.cpp", | ||
out_bin = "json_test", | ||
libs = json_parser, | ||
quiet = True | ||
) | ||
|
||
export.lib = json_parser | ||
exports.lib = json_parser |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
#------------------------------------------------------------------------------- | ||
# TOML parser example | ||
|
||
toml_lib = hancho.rules.c_library( | ||
"toml_parser.cpp", | ||
"toml_lib.a", | ||
rules = imports.rules | ||
config = imports.config | ||
|
||
toml_lib = rules.c_library( | ||
config, | ||
in_srcs = "toml_parser.cpp", | ||
out_lib = "toml_lib.a", | ||
) | ||
|
||
hancho.rules.c_test( | ||
"toml_test.cpp", | ||
"toml_test", | ||
rules.c_test( | ||
config, | ||
in_srcs = "toml_test.cpp", | ||
out_bin = "toml_test", | ||
libs = toml_lib, | ||
quiet = True | ||
) |
Oops, something went wrong.