Skip to content

Commit

Permalink
hancho build works again
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Apr 19, 2024
1 parent 290cc98 commit 3fcaea1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 38 deletions.
22 changes: 12 additions & 10 deletions build.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

print("Building Matcheroni with Hancho")

build_config.build_tag = "debug"

build_config.load("examples/c_lexer/c_lexer.hancho")
build_config.load("examples/c_parser/c_parser.hancho")
build_config.load("examples/ini/ini.hancho")
build_config.load("examples/json/json.hancho")
build_config.load("examples/regex/regex.hancho")
build_config.load("examples/toml/toml.hancho")
build_config.load("examples/tutorial/tutorial.hancho")
build_config.load("tests/tests.hancho")
hancho.build_tag = "debug"

c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho")
c_parser = hancho.load("examples/c_parser/c_parser.hancho",
c_lexer_lib = c_lexer.c_lexer_lib)

hancho.load("examples/ini/ini.hancho")
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", c_lexer_lib=c_lexer.c_lexer_lib, c_parser_lib = c_parser.c_parser_lib)
12 changes: 6 additions & 6 deletions config/rules.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

#-------------------------------------------------------------------------------

compile_cpp = build_config.rule(
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.",
includes = "-I{repo_path}",
defines = "",
build_files = "{swap_ext(source_files, '.o')}",
build_deps = "{swap_ext(source_files, '.d')}",
)

link_c_lib = build_config.rule(
link_c_lib = hancho.command(
desc = "Bundling {rel_build_files}",
command = "ar rcs {rel_build_files} {rel_source_files}",
)

link_c_bin = build_config.rule(
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'}",
Expand All @@ -28,7 +28,7 @@ link_c_bin = build_config.rule(
warnings = "-Wall",
)

test_rule = build_config.rule(
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')}",
Expand All @@ -47,6 +47,6 @@ def c_library(source_files, build_files, **kwargs):
return link_c_lib(compile_srcs(source_files, **kwargs), build_files, **kwargs)

def c_test(source_files, build_files, **kwargs):
return test_rule(c_binary(source_files, build_files, **kwargs), **kwargs)
return run_c_test(c_binary(source_files, build_files, **kwargs), **kwargs)

#-------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion examples/c_lexer/c_lexer.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------------
# Matcheroni C lexer demo

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

c_lexer_lib = rules.c_library(
["CLexer.cpp", "CToken.cpp"],
Expand Down
10 changes: 5 additions & 5 deletions examples/c_parser/c_parser.hancho
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#-------------------------------------------------------------------------------
# C parser example (not finished)

rules = build_config.include("{repo_path}/config/rules.hancho")
import sys

c_lexer = build_config.load("../c_lexer/c_lexer.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

c_parser_lib = rules.c_library(
["CContext.cpp", "CNode.cpp", "CScope.cpp"],
"c_parser.a",
source_files = ["CContext.cpp", "CNode.cpp", "CScope.cpp"],
build_files = "c_parser.a",
)

rules.c_binary(
"c_parser_benchmark.cpp",
"c_parser_benchmark",
libs = [c_lexer.c_lexer_lib, c_parser_lib],
libs = [hancho.c_lexer_lib, c_parser_lib],
)

# Broken?
Expand Down
2 changes: 1 addition & 1 deletion examples/ini/ini.hancho
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#-------------------------------------------------------------------------------
# INI parser example

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

ini_parser_lib = rules.c_library("ini_parser.cpp", "ini_parser.a")
2 changes: 1 addition & 1 deletion examples/json/json.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------------
# Matcheroni JSON parser example

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

json_parser = rules.c_library(
["json_matcher.cpp", "json_parser.cpp"],
Expand Down
2 changes: 1 addition & 1 deletion examples/regex/regex.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------------
# Matcheroni regex parsing example

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

# These are the various regex libraries that Matcheroni can be benchmarked
# against. CTRE and SRELL require that you copy their header into matcheroni/.
Expand Down
2 changes: 1 addition & 1 deletion examples/toml/toml.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------------
# TOML parser example

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

toml_lib = rules.c_library(
"toml_parser.cpp",
Expand Down
19 changes: 8 additions & 11 deletions examples/tutorial/tutorial.hancho
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#-------------------------------------------------------------------------------
# Tutorial examples

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

c_lexer = build_config.load("../c_lexer/c_lexer.hancho")
c_parser = build_config.load("../c_parser/c_parser.hancho")

rules.c_test("json_tut0a.cpp", "json_tut0a", quiet = True)
rules.c_test("json_tut1a.cpp", "json_tut1a", quiet = True)
rules.c_test("json_tut1b.cpp", "json_tut1b", quiet = True)
rules.c_test("json_tut1c.cpp", "json_tut1c", quiet = True)
rules.c_test("json_tut2a.cpp", "json_tut2a", quiet = True)
rules.c_test("json_tut2b.cpp", "json_tut2b", quiet = True)
rules.c_test("json_tut0a.cpp", "json_tut0a", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut1a.cpp", "json_tut1a", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut1b.cpp", "json_tut1b", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut1c.cpp", "json_tut1c", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut2a.cpp", "json_tut2a", command_path="{repo_path}", quiet = True)
rules.c_test("json_tut2b.cpp", "json_tut2b", command_path="{repo_path}", quiet = True)

rules.c_binary(
"tiny_c_parser.cpp",
"tiny_c_parser",
libs = [c_lexer.c_lexer_lib, c_parser.c_parser_lib],
libs = [hancho.c_lexer_lib, hancho.c_parser_lib],
)
2 changes: 1 addition & 1 deletion tests/tests.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------------
# Tests

rules = build_config.include("{repo_path}/config/rules.hancho")
rules = hancho.load("{repo_path}/config/rules.hancho")

#build obj/matcheroni/Matcheroni.hpp.iwyu : iwyu matcheroni/Matcheroni.hpp
#build obj/matcheroni/Parseroni.hpp.iwyu : iwyu matcheroni/Parseroni.hpp
Expand Down

0 comments on commit 3fcaea1

Please sign in to comment.