Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/fuzz/CMakeLists.txt
2723 views
1
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
if(${CMAKE_VERSION} VERSION_LESS "3.26")
3
message(WARNING "Building the Luau fuzzer requires CMake version 3.26 or higher.")
4
return()
5
endif()
6
7
include(FetchContent)
8
9
cmake_policy(SET CMP0054 NEW)
10
cmake_policy(SET CMP0058 NEW)
11
cmake_policy(SET CMP0074 NEW)
12
cmake_policy(SET CMP0077 NEW)
13
cmake_policy(SET CMP0091 NEW)
14
15
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
16
message(WARNING "Building the Luau fuzzer requires Clang to be used. AppleClang is not sufficient.")
17
return()
18
endif()
19
20
if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
21
message(WARNING "Building the Luau fuzzer for ARM64 is currently unsupported.")
22
return()
23
endif()
24
25
# protobuf / std integer types vary based on platform; disable sign-compare
26
# warnings for portability.
27
set(FUZZ_COMPILE_OPTIONS ${LUAU_OPTIONS} -fsanitize=address,fuzzer -g2 -Wno-sign-compare)
28
set(FUZZ_LINK_OPTIONS ${LUAU_OPTIONS} -fsanitize=address,fuzzer)
29
30
FetchContent_Declare(
31
ProtobufMutator
32
GIT_REPOSITORY https://github.com/google/libprotobuf-mutator
33
GIT_TAG 212a7be1eb08e7f9c79732d2aab9b2097085d936
34
# libprotobuf-mutator unconditionally configures its examples, but this
35
# doesn't actually work with how we're building Protobuf from source. This
36
# patch disables configuration of the examples.
37
PATCH_COMMAND
38
git apply
39
--reverse
40
--check
41
--ignore-space-change
42
--ignore-whitespace
43
"${CMAKE_CURRENT_SOURCE_DIR}/libprotobuf-mutator-patch.patch"
44
||
45
git apply
46
--ignore-space-change
47
--ignore-whitespace
48
"${CMAKE_CURRENT_SOURCE_DIR}/libprotobuf-mutator-patch.patch"
49
)
50
51
FetchContent_Declare(
52
Protobuf
53
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
54
# Needs to match the Protobuf version that libprotobuf-mutator is written for, roughly.
55
GIT_TAG v22.3
56
GIT_SHALLOW ON
57
58
# libprotobuf-mutator will need to be able to find this at configuration
59
# time.
60
OVERRIDE_FIND_PACKAGE
61
)
62
63
set(protobuf_BUILD_TESTS OFF)
64
set(protobuf_BUILD_SHARED_LIBS OFF)
65
# libprotobuf-mutator relies on older module support.
66
set(protobuf_MODULE_COMPATIBLE ON)
67
68
find_package(Protobuf CONFIG REQUIRED)
69
70
# libprotobuf-mutator happily ignores CMP0077 because of its minimum version
71
# requirement. To override that, we set the policy default here.
72
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
73
set(LIB_PROTO_MUTATOR_TESTING OFF)
74
75
FetchContent_MakeAvailable(ProtobufMutator)
76
77
# This patches around the fact that find_package isn't going to set the right
78
# values for libprotobuf-mutator to link against protobuf libraries.
79
target_link_libraries(protobuf-mutator-libfuzzer protobuf::libprotobuf)
80
target_link_libraries(protobuf-mutator protobuf::libprotobuf)
81
82
set(LUAU_PB_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf)
83
set(LUAU_PB_SOURCES ${LUAU_PB_DIR}/luau.pb.cc ${LUAU_PB_DIR}/luau.pb.h)
84
85
add_custom_command(
86
OUTPUT ${LUAU_PB_SOURCES}
87
COMMAND ${CMAKE_COMMAND} -E make_directory ${LUAU_PB_DIR}
88
COMMAND ${protobuf_PROTOC} ${CMAKE_CURRENT_SOURCE_DIR}/luau.proto --proto_path=${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${LUAU_PB_DIR}
89
DEPENDS ${protobuf_PROTOC} ${CMAKE_CURRENT_SOURCE_DIR}/luau.proto
90
)
91
92
add_executable(Luau.Fuzz.Proto)
93
target_compile_options(Luau.Fuzz.Proto PRIVATE ${FUZZ_COMPILE_OPTIONS})
94
target_link_options(Luau.Fuzz.Proto PRIVATE ${FUZZ_LINK_OPTIONS})
95
target_compile_features(Luau.Fuzz.Proto PRIVATE cxx_std_17)
96
target_include_directories(Luau.Fuzz.Proto PRIVATE ${LUAU_PB_DIR} ${protobufmutator_SOURCE_DIR})
97
target_sources(Luau.Fuzz.Proto PRIVATE ${LUAU_PB_SOURCES} proto.cpp protoprint.cpp)
98
target_link_libraries(Luau.Fuzz.Proto PRIVATE protobuf::libprotobuf protobuf-mutator-libfuzzer protobuf-mutator Luau.Analysis Luau.Compiler Luau.Ast Luau.Config Luau.VM Luau.CodeGen)
99
set_target_properties(Luau.Fuzz.Proto PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF OUTPUT_NAME fuzz-proto)
100
101
add_executable(Luau.Fuzz.ProtoTest)
102
target_compile_options(Luau.Fuzz.ProtoTest PRIVATE ${FUZZ_COMPILE_OPTIONS})
103
target_link_options(Luau.Fuzz.ProtoTest PRIVATE ${FUZZ_LINK_OPTIONS})
104
target_compile_features(Luau.Fuzz.ProtoTest PRIVATE cxx_std_17)
105
target_include_directories(Luau.Fuzz.ProtoTest PRIVATE ${LUAU_PB_DIR} ${protobufmutator_SOURCE_DIR})
106
target_sources(Luau.Fuzz.ProtoTest PRIVATE ${LUAU_PB_SOURCES} prototest.cpp protoprint.cpp)
107
target_link_libraries(Luau.Fuzz.ProtoTest PRIVATE protobuf::libprotobuf protobuf-mutator-libfuzzer protobuf-mutator)
108
set_target_properties(Luau.Fuzz.ProtoTest PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF OUTPUT_NAME fuzz-prototest)
109
110