tree-sitter/project.gyp
Phil Turnbull 798ef5e4dc Add libFuzzer support
This adds support for fuzzing tree-sitter grammars with libFuzzer. This
currently only works on Linux because of linking issues on macOS. Breifly, the
AddressSanitizer library is dynamically linked into the fuzzer binary and
cannot be found at runtime if built with a compiler that wasn't provided by
Xcode(?). The runtime library is statically linked on Linux so this isn't a
problem.
2017-07-14 13:50:41 -07:00

163 lines
4.7 KiB
Python

{
'targets': [
{
'target_name': 'compiler',
'type': 'static_library',
'include_dirs': [
'include',
'src',
'externals/utf8proc',
'externals/json-parser',
],
'sources': [
'src/compiler/build_tables/build_parse_table.cc',
'src/compiler/build_tables/build_tables.cc',
'src/compiler/build_tables/lex_item.cc',
'src/compiler/build_tables/lex_item_transitions.cc',
'src/compiler/build_tables/lex_conflict_manager.cc',
'src/compiler/build_tables/lex_table_builder.cc',
'src/compiler/build_tables/lookahead_set.cc',
'src/compiler/build_tables/parse_item.cc',
'src/compiler/build_tables/parse_item_set_builder.cc',
'src/compiler/build_tables/rule_can_be_blank.cc',
'src/compiler/compile.cc',
'src/compiler/generate_code/c_code.cc',
'src/compiler/lex_table.cc',
'src/compiler/parse_grammar.cc',
'src/compiler/parse_table.cc',
'src/compiler/precedence_range.cc',
'src/compiler/prepare_grammar/expand_repeats.cc',
'src/compiler/prepare_grammar/expand_tokens.cc',
'src/compiler/prepare_grammar/extract_choices.cc',
'src/compiler/prepare_grammar/extract_tokens.cc',
'src/compiler/prepare_grammar/flatten_grammar.cc',
'src/compiler/prepare_grammar/intern_symbols.cc',
'src/compiler/prepare_grammar/normalize_rules.cc',
'src/compiler/prepare_grammar/parse_regex.cc',
'src/compiler/prepare_grammar/prepare_grammar.cc',
'src/compiler/prepare_grammar/token_description.cc',
'src/compiler/rule.cc',
'src/compiler/rules/character_set.cc',
'src/compiler/rules/choice.cc',
'src/compiler/rules/metadata.cc',
'src/compiler/rules/repeat.cc',
'src/compiler/rules/seq.cc',
'src/compiler/util/string_helpers.cc',
'externals/utf8proc/utf8proc.c',
'externals/json-parser/json.c',
],
'cflags_cc': [
'-std=c++14',
],
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'c++14',
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
},
'direct_dependent_settings': {
'include_dirs': [
'include'
],
},
# Mac OS has an old version of libstdc++ that doesn't support c++11.
# libc++ is only present on 10.7 and later.
'conditions': [
['OS == "mac"', {
'cflags_cc': [ '-stdlib=libc++' ],
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
},
'direct_dependent_settings': {
'cflags_cc': [ '-stdlib=libc++' ],
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
},
},
}]
],
},
{
'target_name': 'runtime',
'type': 'static_library',
'include_dirs': [
'include',
'src',
'externals/utf8proc',
],
'sources': [
'src/runtime/document.c',
'src/runtime/error_costs.c',
'src/runtime/language.c',
'src/runtime/lexer.c',
'src/runtime/node.c',
'src/runtime/stack.c',
'src/runtime/parser.c',
'src/runtime/string_input.c',
'src/runtime/tree.c',
'src/runtime/utf16.c',
'externals/utf8proc/utf8proc.c',
],
'cflags_c': [
'-std=c99'
],
'ldflags': [
'-g',
],
'direct_dependent_settings': {
'include_dirs': [
'include'
],
},
},
],
'target_defaults': {
'default_configuration': 'Release',
'configurations': {
'Debug': {
'cflags': [ '-g' ],
'ldflags': [ '-g' ],
'xcode_settings': {
'OTHER_LDFLAGS': ['-g'],
'GCC_OPTIMIZATION_LEVEL': '0',
},
},
'Test': {
'defines': ['TREE_SITTER_WRAP_MALLOC=true'],
'cflags': [ '-g' ],
'ldflags': [ '-g' ],
'xcode_settings': {
'OTHER_LDFLAGS': ['-g'],
'GCC_OPTIMIZATION_LEVEL': '0',
'OTHER_CPLUSPLUSFLAGS': ['-fsanitize=address'],
},
},
'Fuzz': {
'cflags': [ '-g', '-fsanitize=address,undefined', '-fsanitize-coverage=trace-pc-guard' ],
'ldflags': [ '-g', '-fsanitize=address,undefined', '-fsanitize-coverage=trace-pc-guard' ],
},
'Release': {
'cflags': [ '-O2', '-fno-strict-aliasing' ],
'cflags!': [ '-O3', '-fstrict-aliasing' ],
},
},
'cflags': [
'-Wall',
'-Wextra',
'-Wno-unused-parameter'
],
'xcode_settings': {
'ALWAYS_SEARCH_USER_PATHS': 'NO',
'WARNING_CFLAGS': [
'-Wall',
'-Wextra',
'-Wno-unused-parameter'
],
},
}
}