luau/fuzz/CMakeLists.txt
Hunter Goldstein 92cce5776c
Sync to upstream/release/674 (#1832)
# General

* Expose an optional `get_alias` API as an alternative to `get_config`
in Luau.Require and Luau.RequireNavigator.
* Improve the Luau CLI's virtual filesystem implementation to fix bugs
related to `init.luau`. Fixes
https://github.com/luau-lang/luau/issues/1816


# New Type Solver

* Avoid double reporting errors when erroneous arguments are provided to
type functions.
* Fix some instances of unresovable cyclic type functions in loops by
only considering the first loop cycles. This results in some type
inference inaccuracies when the type of a variable in loop through
multiple iterations. Fixes
https://github.com/luau-lang/luau/issues/1413.
* Better generalize free types that have meaningful lower and upper
bounds, especially for table indexers.
* Report more specific errors when assigning or returning table literal
types, instead of citing the *entire* table type.
* Inference for functions with generic type packs is greatly improved.
* Fix some internal compiler exceptions when using type-stating
functions like `table.freeze` in `if _ then _ else _` expressions and
short circuiting binary operations.
* More consistently simplify unions of primitive types, especially in
array-like and dictionary-like tables.
* Fix a crash when type checking an erroneous type alias containing
`typeof` with a type assertion expression, as in:
  ```
  type MyTable = {}
  -- This will error at type checking time as it's a duplicate
  type MyTable = typeof(setmetatable(SomeTable :: {}, SomeMetaTable));
  ```
* Fix a crash when inferring the type of an index expression where the
indexee is invalid (e.g. `nil`).

# Runtime
* Avoid throwing an exception from `luau_load` if we run out of memory.
* Type functions are no longer compiled and included in bytecode. Fixes
#1817.
* Fix some instances of Luau C API functions reading invalid debug
information (generally when the first or last instruction of a block was
being inspected). Fixes #1369.
* Avoid potential signed integer overflow when doing bounds checks on
tables.
* Support 16 byte aligned userdata objects when system allocation
alignment is also 16 bytes.
* Fix memory leaks in `Luau.Require` when using VM build with no
exceptions. Fixes #1827.

---------

Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: James McNellis <jmcnellis@roblox.com>
Co-authored-by: Sora Kanosue <skanosue@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2025-05-16 12:39:58 -07:00

108 lines
4.5 KiB
CMake

# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
if(${CMAKE_VERSION} VERSION_LESS "3.26")
message(WARNING "Building the Luau fuzzer requires CMake version 3.26 or higher.")
return()
endif()
include(FetchContent)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0058 NEW)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0091 NEW)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(WARNING "Building the Luau fuzzer requires Clang to be used. AppleClang is not sufficient.")
return()
endif()
if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
message(WARNING "Building the Luau fuzzer for ARM64 is currently unsupported.")
return()
endif()
# protobuf / std integer types vary based on platform; disable sign-compare
# warnings for portability.
set(FUZZ_COMPILE_OPTIONS ${LUAU_OPTIONS} -fsanitize=address,fuzzer -g2 -Wno-sign-compare)
set(FUZZ_LINK_OPTIONS ${LUAU_OPTIONS} -fsanitize=address,fuzzer)
FetchContent_Declare(
ProtobufMutator
GIT_REPOSITORY https://github.com/google/libprotobuf-mutator
GIT_TAG 212a7be1eb08e7f9c79732d2aab9b2097085d936
# libprotobuf-mutator unconditionally configures its examples, but this
# doesn't actually work with how we're building Protobuf from source. This
# patch disables configuration of the examples.
PATCH_COMMAND
git apply
--reverse
--check
--ignore-space-change
--ignore-whitespace
"${CMAKE_CURRENT_SOURCE_DIR}/libprotobuf-mutator-patch.patch"
||
git apply
--ignore-space-change
--ignore-whitespace
"${CMAKE_CURRENT_SOURCE_DIR}/libprotobuf-mutator-patch.patch"
)
FetchContent_Declare(
Protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
# Needs to match the Protobuf version that libprotobuf-mutator is written for, roughly.
GIT_TAG v22.3
GIT_SHALLOW ON
# libprotobuf-mutator will need to be able to find this at configuration
# time.
OVERRIDE_FIND_PACKAGE
)
set(protobuf_BUILD_TESTS OFF)
set(protobuf_BUILD_SHARED_LIBS OFF)
# libprotobuf-mutator relies on older module support.
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf CONFIG REQUIRED)
# libprotobuf-mutator happily ignores CMP0077 because of its minimum version
# requirement. To override that, we set the policy default here.
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(LIB_PROTO_MUTATOR_TESTING OFF)
FetchContent_MakeAvailable(ProtobufMutator)
# This patches around the fact that find_package isn't going to set the right
# values for libprotobuf-mutator to link against protobuf libraries.
target_link_libraries(protobuf-mutator-libfuzzer protobuf::libprotobuf)
target_link_libraries(protobuf-mutator protobuf::libprotobuf)
set(LUAU_PB_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf)
set(LUAU_PB_SOURCES ${LUAU_PB_DIR}/luau.pb.cc ${LUAU_PB_DIR}/luau.pb.h)
add_custom_command(
OUTPUT ${LUAU_PB_SOURCES}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LUAU_PB_DIR}
COMMAND ${protobuf_PROTOC} ${CMAKE_CURRENT_SOURCE_DIR}/luau.proto --proto_path=${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${LUAU_PB_DIR}
DEPENDS ${protobuf_PROTOC} ${CMAKE_CURRENT_SOURCE_DIR}/luau.proto
)
add_executable(Luau.Fuzz.Proto)
target_compile_options(Luau.Fuzz.Proto PRIVATE ${FUZZ_COMPILE_OPTIONS})
target_link_options(Luau.Fuzz.Proto PRIVATE ${FUZZ_LINK_OPTIONS})
target_compile_features(Luau.Fuzz.Proto PRIVATE cxx_std_17)
target_include_directories(Luau.Fuzz.Proto PRIVATE ${LUAU_PB_DIR} ${protobufmutator_SOURCE_DIR})
target_sources(Luau.Fuzz.Proto PRIVATE ${LUAU_PB_SOURCES} proto.cpp protoprint.cpp)
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)
set_target_properties(Luau.Fuzz.Proto PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF OUTPUT_NAME fuzz-proto)
add_executable(Luau.Fuzz.ProtoTest)
target_compile_options(Luau.Fuzz.ProtoTest PRIVATE ${FUZZ_COMPILE_OPTIONS})
target_link_options(Luau.Fuzz.ProtoTest PRIVATE ${FUZZ_LINK_OPTIONS})
target_compile_features(Luau.Fuzz.ProtoTest PRIVATE cxx_std_17)
target_include_directories(Luau.Fuzz.ProtoTest PRIVATE ${LUAU_PB_DIR} ${protobufmutator_SOURCE_DIR})
target_sources(Luau.Fuzz.ProtoTest PRIVATE ${LUAU_PB_SOURCES} prototest.cpp protoprint.cpp)
target_link_libraries(Luau.Fuzz.ProtoTest PRIVATE protobuf::libprotobuf protobuf-mutator-libfuzzer protobuf-mutator)
set_target_properties(Luau.Fuzz.ProtoTest PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF OUTPUT_NAME fuzz-prototest)