### Installing Development Tools via Chocolatey (Windows) Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command installs required build dependencies (CMake, Ninja, Perl, Python, Ruby, Gperf) on Windows using the Chocolatey package manager. Chocolatey must be installed beforehand. ```Command Line choco install cmake ninja activeperl python2 ruby1.9 gperf ``` -------------------------------- ### Installing Development Tools via APT (Linux) Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command installs required build dependencies (CMake, Ninja, Gperf, Ruby, Clang, libgcrypt, lld) on Debian-based Linux distributions using the apt package manager. It requires root privileges (sudo). ```Command Line sudo apt install cmake ninja-build gperf ruby clang libgcrypt20 libgcrypt11-dev lld-4.0 ``` -------------------------------- ### Installing Development Tools via Homebrew (macOS) Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command installs the CMake and Ninja build tools on macOS using the Homebrew package manager. Homebrew must be installed, and Xcode Command Line Tools/SDK might be needed depending on the context. ```Command Line brew install cmake ninja ``` -------------------------------- ### Installing Library with SCons - Shell Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/dtoa/README.md Builds and installs the double-conversion library's static and shared library files to the default system locations as configured by SCons. This requires SCons to be installed and accessible in the environment. ```shell scons install ``` -------------------------------- ### Installing mimalloc Library (Shell) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Command to install the compiled mimalloc library files (.so, .dylib, .a, .o) and header files to the system directories, typically /usr/local/lib and /usr/local/include, after building the library with make. ```Shell sudo make install ``` -------------------------------- ### Installing Library to Custom Directory with SCons - Shell Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/dtoa/README.md Builds and installs the double-conversion library to a user-specified root directory using the SCons build system. The `DESTDIR` environment variable or option overrides the default installation path. ```shell scons DESTDIR=alternative_directory install ``` -------------------------------- ### Building Release x64 on Windows Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command initiates a standard 64-bit release build of the Ultralight WebCore port on Windows using the provided Makefile. It assumes the necessary build environment and dependencies are set up. ```Command Line make release x64 ``` -------------------------------- ### Configuring Mimalloc Library Build - CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/CMakeLists.txt Defines the CMake build and installation process for the mimalloc library. It conditionally sets install paths, derives library names based on features, creates build targets for shared, static, and object libraries, configures their properties (definitions, options, libraries, includes), handles platform-specific requirements (like Windows DLL redirection), and sets up installation rules, including headers, libraries, CMake package files, and pkg-config files. It also includes test target setup and integration with WebKit framework macros. ```cmake # are either installed at top level, or use versioned directories for side-by-side installation (default) if (MI_INSTALL_TOPLEVEL) set(mi_install_objdir "${CMAKE_INSTALL_LIBDIR}") set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}") set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc") else() set(mi_install_objdir "${CMAKE_INSTALL_LIBDIR}/mimalloc-${mi_version}") # for static library and object files set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}/mimalloc-${mi_version}") # for includes set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc-${mi_version}") # for cmake package info endif() set(mi_basename "mimalloc") if(MI_SECURE) set(mi_basename "${mi_basename}-secure") endif() if(MI_TRACK_VALGRIND) set(mi_basename "${mi_basename}-valgrind") endif() if(MI_TRACK_ASAN) set(mi_basename "${mi_basename}-asan") endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")) set(mi_basename "${mi_basename}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version endif() if(MI_BUILD_SHARED) list(APPEND mi_build_targets "shared") endif() if(MI_BUILD_STATIC) list(APPEND mi_build_targets "static") endif() if(MI_BUILD_OBJECT) list(APPEND mi_build_targets "object") endif() if(MI_BUILD_TESTS) list(APPEND mi_build_targets "tests") endif() message(STATUS "") message(STATUS "Library base name: ${mi_basename}") message(STATUS "Version : ${mi_version}") message(STATUS "Build type : ${CMAKE_BUILD_TYPE_LC}") if(MI_USE_CXX) message(STATUS "C++ Compiler : ${CMAKE_CXX_COMPILER}") else() message(STATUS "C Compiler : ${CMAKE_C_COMPILER}") endif() message(STATUS "Compiler flags : ${mi_cflags}") message(STATUS "Compiler defines : ${mi_defines}") message(STATUS "Link libraries : ${mi_libraries}") message(STATUS "Build targets : ${mi_build_targets}") message(STATUS "") # ----------------------------------------------------------------------------- # Main targets # ----------------------------------------------------------------------------- # shared library if(MI_BUILD_SHARED) add_library(mimalloc SHARED ${mi_sources}) set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_basename} ) target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT) target_compile_options(mimalloc PRIVATE ${mi_cflags}) target_link_libraries(mimalloc PRIVATE ${mi_libraries}) target_include_directories(mimalloc PUBLIC $ $ ) if(WIN32 AND MI_WIN_REDIRECT) # On windows, link and copy the mimalloc redirection dll too. if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(MIMALLOC_REDIRECT_SUFFIX "32") else() set(MIMALLOC_REDIRECT_SUFFIX "") endif() target_link_libraries(mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.lib) add_custom_command(TARGET mimalloc POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" $ COMMENT "Copy mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll to output directory") install(FILES "$/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${mi_install_libdir}) endif() install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_libdir} LIBRARY) install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) endif() # static library if (MI_BUILD_STATIC) add_library(mimalloc-static STATIC ${mi_sources}) set_property(TARGET mimalloc-static PROPERTY POSITION_INDEPENDENT_CODE ON) target_compile_definitions(mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB) target_compile_options(mimalloc-static PRIVATE ${mi_cflags}) target_link_libraries(mimalloc-static PRIVATE ${mi_libraries}) target_include_directories(mimalloc-static PUBLIC $ $ ) if(WIN32) # When building both static and shared libraries on Windows, a static library should use a # different output name to avoid the conflict with the import library of a shared one. string(REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename}) set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name}) else() set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename}) endif() install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY) install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) endif() # install include files install(FILES include/mimalloc.h DESTINATION ${mi_install_incdir}) install(FILES include/mimalloc-override.h DESTINATION ${mi_install_incdir}) install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_incdir}) install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_cmakedir}) install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_cmakedir}) # single object file for more predictable static overriding if (MI_BUILD_OBJECT) add_library(mimalloc-obj OBJECT src/static.c) set_property(TARGET mimalloc-obj PROPERTY POSITION_INDEPENDENT_CODE ON) target_compile_definitions(mimalloc-obj PRIVATE ${mi_defines}) target_compile_options(mimalloc-obj PRIVATE ${mi_cflags}) target_include_directories(mimalloc-obj PUBLIC $ $ ) # Copy the generated object file (`static.o`) to the output directory (as `mimalloc.o`) if(NOT WIN32) set(mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION}") set(mimalloc-obj-out "${CMAKE_CURRENT_BINARY_DIR}/${mi_basename}${CMAKE_C_OUTPUT_EXTENSION}") add_custom_command(OUTPUT ${mimalloc-obj-out} DEPENDS mimalloc-obj COMMAND "${CMAKE_COMMAND}" -E copy "${mimalloc-obj-static}" "${mimalloc-obj-out}") add_custom_target(mimalloc-obj-target ALL DEPENDS ${mimalloc-obj-out}) endif() # the following seems to lead to cmake warnings/errors on some systems, disable for now :-( # install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_objdir}) # the FILES expression can also be: $ # but that fails cmake versions less than 3.10 so we leave it as is for now install(FILES ${mimalloc-obj-static} DESTINATION ${mi_install_objdir} RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} ) endif() # pkg-config file support include("cmake/JoinPaths.cmake") join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") configure_file(mimalloc.pc.in mimalloc.pc @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") # ----------------------------------------------------------------------------- # API surface testing # ----------------------------------------------------------------------------- if (MI_BUILD_TESTS) enable_testing() foreach(TEST_NAME api api-fill stress) add_executable(mimalloc-test-${TEST_NAME} test/test-${TEST_NAME}.c) target_compile_definitions(mimalloc-test-${TEST_NAME} PRIVATE ${mi_defines}) target_compile_options(mimalloc-test-${TEST_NAME} PRIVATE ${mi_cflags}) target_include_directories(mimalloc-test-${TEST_NAME} PRIVATE include) target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc ${mi_libraries}) add_test(NAME test-${TEST_NAME} COMMAND mimalloc-test-${TEST_NAME}) endforeach() endif() # ----------------------------------------------------------------------------- # Set override properties # ----------------------------------------------------------------------------- if (MI_OVERRIDE) if (MI_BUILD_SHARED) target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE) endif() if(NOT WIN32) # It is only possible to override malloc on Windows when building as a DLL. if (MI_BUILD_STATIC) target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE) endif() if (MI_BUILD_OBJECT) target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE) endif() endif() endif() set(mimalloc_SOURCES ${mi_sources}) set(mimalloc_LIBRARIES ${mi_libraries}) set(mimalloc_INTERFACE_LIBRARIES mimalloc) set(mimalloc_INTERFACE_INCLUDE_DIRECTORIES ${mimalloc_FRAMEWORK_HEADERS_DIR}) set(mimalloc_INTERFACE_DEPENDENCIES mimalloc_CopyHeaders) set(mimalloc_PRIVATE_DEFINITIONS ${mi_defines} MI_STATIC_LIB) set(mimalloc_COMPILE_OPTIONS ${mi_cflags}) set(mimalloc_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include) WEBKIT_FRAMEWORK_DECLARE(mimalloc) WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS() WEBKIT_COPY_FILES(mimalloc_CopyHeaders DESTINATION ${mimalloc_FRAMEWORK_HEADERS_DIR} FILES ${mimalloc_PUBLIC_HEADERS} ) WEBKIT_WRAP_SOURCELIST(${mimalloc_SOURCES}) WEBKIT_FRAMEWORK(mimalloc) WEBKIT_FRAMEWORK_TARGET(mimalloc) ``` -------------------------------- ### Building Debug x64 on Windows Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command initiates a 64-bit debug build of the Ultralight WebCore port on Windows using the provided Makefile. This build includes debug PDBs and is not optimized. ```Command Line make debug x64 ``` -------------------------------- ### Building on macOS and Linux Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command executes the main build script for the Ultralight WebCore port on macOS and Linux. It performs the build process using the configured environment and dependencies. ```Command Line ./make ``` -------------------------------- ### Compiling C Program with mimalloc (Shell) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Example command using the GCC compiler to compile a C source file (`myfile.c`) into an executable (`myprogram`) and link it with the installed mimalloc library. This uses the standard library linking flag `-l`. ```Shell gcc -o myprogram -lmimalloc myfile.c ``` -------------------------------- ### Building Release x64 with Local Dependencies on Windows Source: https://github.com/ultralight-ux/webcore/blob/master/README.md This command initiates a 64-bit release build of the Ultralight WebCore port on Windows, specifically using dependencies located in the local /deps folder instead of fetching pre-built ones. This is useful for building against modified dependencies. ```Command Line make release x64 local ``` -------------------------------- ### Starting ETW Trace Recording with WPR (Windows Command Prompt) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Provides the Windows command to start recording an ETW trace using the Windows Performance Recorder (WPR). The command specifies a mimalloc-specific profile file (`etw-mimalloc.wprp`) and file mode recording. This command requires administrator privileges. ```shell wpr -start src\prim\windows\etw-mimalloc.wprp -filemode ``` -------------------------------- ### Set Haiku Install Directories (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/CMakeLists.txt Sets specific installation directories (`CMAKE_INSTALL_LIBDIR`, `CMAKE_INSTALL_INCLUDEDIR`) if the target system name matches "Haiku". ```CMake if(CMAKE_SYSTEM_NAME MATCHES "Haiku") SET(CMAKE_INSTALL_LIBDIR ~/config/non-packaged/lib) SET(CMAKE_INSTALL_INCLUDEDIR ~/config/non-packaged/headers) endif() ``` -------------------------------- ### Define Installation Directory (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/CMakeLists.txt Sets the variable `mi_install_libdir` to `CMAKE_INSTALL_LIBDIR`, which determines the installation path for dynamic and shared libraries and symlinks. ```CMake # ----------------------------------------------------------------------------- # Install and output names # ----------------------------------------------------------------------------- # dynamic/shared library and symlinks always go to /usr/local/lib equivalent set(mi_install_libdir "${CMAKE_INSTALL_LIBDIR}") # static libraries and object files, includes, and cmake config files ``` -------------------------------- ### Compiling Program with Address Sanitizer and mimalloc ASAN Lib (Clang) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Gives a Clang command example demonstrating how to compile a source file (`test/test-wrong.c`) with Address Sanitizer (`-fsanitize=address`) and link it against the ASan-enabled static mimalloc library (`libmimalloc-asan-debug.a`) built previously. ```shell clang -g -o test-wrong -Iinclude test/test-wrong.c out/debug/libmimalloc-asan-debug.a -lpthread -fsanitize=address -fsanitize-recover=address ``` -------------------------------- ### Running Program During ETW Trace Recording (Placeholder) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md This placeholder represents the execution of the target program instrumented with ETW-enabled mimalloc. This command should be run in the same command prompt session as the WPR start and stop commands, specifically after starting the trace and before stopping it. ```shell ``` -------------------------------- ### Installing mimalloc Build Dependencies (Shell) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Commands to install necessary build tools like CMake and CCMake (a curses-based CMake GUI) using apt-get on Debian-based Linux distributions. These tools are required for building mimalloc via CMake. ```Shell sudo apt-get install cmake ``` ```Shell sudo apt-get install cmake-curses-gui ``` -------------------------------- ### Running Program with mimalloc Stats (Shell) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Demonstrates how to run an executable (`./cfrac`) with the `MIMALLOC_SHOW_STATS=1` environment variable set. This enables mimalloc to print detailed memory allocation statistics to the console upon program termination, as shown in the example output. ```Shell env MIMALLOC_SHOW_STATS=1 ./cfrac 175451865205073170563711388363 175451865205073170563711388363 = 374456281610909315237213 * 468551 heap stats: peak total freed unit normal 2: 16.4 kb 17.5 mb 17.5 mb 16 b ok normal 3: 16.3 kb 15.2 mb 15.2 mb 24 b ok normal 4: 64 b 4.6 kb 4.6 kb 32 b ok normal 5: 80 b 118.4 kb 118.4 kb 40 b ok normal 6: 48 b 48 b 48 b 48 b ok normal 17: 960 b 960 b 960 b 320 b ok heap stats: peak total freed unit normal: 33.9 kb 32.8 mb 32.8 mb 1 b ok huge: 0 b 0 b 0 b 1 b ok total: 33.9 kb 32.8 mb 32.8 mb 1 b ok malloc requested: 32.8 mb committed: 58.2 kb 58.2 kb 58.2 kb 1 b ok reserved: 2.0 mb 2.0 mb 2.0 mb 1 b ok reset: 0 b 0 b 0 b 1 b ok segments: 1 1 1 -abandoned: 0 pages: 6 6 6 -abandoned: 0 mmaps: 3 mmap fast: 0 mmap slow: 1 threads: 0 elapsed: 2.022s process: user: 1.781s, system: 0.016s, faults: 756, reclaims: 0, rss: 2.7 mb ``` -------------------------------- ### Final C++ Compilation Setup (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/CMakeLists.txt Finalizes the C++ compilation setup if `MI_USE_CXX` is ON. It sets source file properties to compile them as C++ and adds compiler-specific C++ flags for AppleClang, Clang, and Intel compilers. ```CMake if(MI_USE_CXX) message(STATUS "Use the C++ compiler to compile (MI_USE_CXX=ON)") set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX ) set_source_files_properties(src/static.c test/test-api.c test/test-api-fill test/test-stress PROPERTIES LANGUAGE CXX ) if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang") list(APPEND mi_cflags -Wno-deprecated) endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") list(APPEND mi_cflags -Kc++) endif() endif() ``` -------------------------------- ### Statically Linking mimalloc Object File (GCC) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Provides an example GCC command for statically linking the `mimalloc.o` object file directly into a program (`myprogram`). Linking the mimalloc object file as the first object prioritizes its implementation for resolving standard `malloc` symbols. ```shell gcc -o myprogram mimalloc.o myfile1.c ... ``` -------------------------------- ### Starting and Stopping Windows Performance Recording (WPR) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/src/prim/windows/readme.md This snippet provides the command-line sequence to initiate a Windows Performance Recorder (WPR) session using the `etw-mimalloc.wprp` profile, run a target program, and then stop the recording, saving the trace data to an ETL file. The resulting `test.etl` file can then be opened in Windows Performance Analyzer (WPA) for detailed analysis of ETW events. ```Shell wpr -start src\prim\windows\etw-mimalloc.wprp -filemode wpr -stop test.etl ``` -------------------------------- ### Including External CMake Files (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/CMakeLists.txt This snippet includes necessary CMake modules and configuration files. CheckIncludeFiles helps verify header availability, GNUInstallDirs provides standard installation directory variables, and mimalloc-config-version.cmake likely defines version information. ```CMake include(CheckIncludeFiles) include(GNUInstallDirs) include("cmake/mimalloc-config-version.cmake") ``` -------------------------------- ### Setting PAL Public Headers (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/PAL/pal/CMakeLists.txt Defines the list of public header files for the PAL framework using the `set` command in CMake. These headers are typically designated for installation or for generating forwarding headers that expose the framework's public API. ```CMake set(PAL_PUBLIC_HEADERS ExportMacros.h FileSizeFormatter.h HysteresisActivity.h LogMacros.h Logging.h SessionID.h crypto/CryptoDigest.h system/Clock.h system/ClockGeneric.h system/SleepDisabler.h system/Sound.h system/SystemSleepListener.h text/KillRing.h text/UnencodableHandling.h ) ``` -------------------------------- ### Defining JavaScript Shell Install Option in CMake Source: https://github.com/ultralight-ux/webcore/blob/master/CMakeLists.txt Defines a boolean option named `SHOULD_INSTALL_JS_SHELL`. This option, if set to ON, will generate an installation rule to include the built JavaScript shell executable in the installation target. ```CMake # ----------------------------------------------------------------------------- # Install JavaScript shell # ----------------------------------------------------------------------------- option(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell") ``` -------------------------------- ### Installing Shared Library on Non-Mac (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/JavaScriptCore/CMakeLists.txt Conditionally installs the built JavaScriptCore shared library if the current platform is not 'Mac' and the library type is 'SHARED'. It also sets version properties for the shared library before installation. ```CMake if (NOT "${PORT}" STREQUAL "Mac") if (${JavaScriptCore_LIBRARY_TYPE} STREQUAL "SHARED") WEBKIT_POPULATE_LIBRARY_VERSION(JAVASCRIPTCORE) set_target_properties(JavaScriptCore PROPERTIES VERSION ${JAVASCRIPTCORE_VERSION} SOVERSION ${JAVASCRIPTCORE_VERSION_MAJOR}) install(TARGETS JavaScriptCore DESTINATION "${LIB_INSTALL_DIR}") endif () endif () ``` -------------------------------- ### Defining Dummy Target and Setting Dependencies (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/GetDeps/CMakeLists.txt This snippet defines a simple executable target named 'dummy' from a source file 'dummy.c'. It then uses 'add_dependencies' to ensure that the 'WebCoreDeps' and 'UltralightCoreBin' targets are built or processed before the 'dummy' target. This pattern is commonly used to manage build order for dependencies. ```CMake add_executable(dummy dummy.c) add_dependencies(dummy WebCoreDeps UltralightCoreBin) ``` -------------------------------- ### Building and Running Tests with CMake - Shell Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/dtoa/README.md Configures CMake to enable building tests, compiles the project and the test executable using Make, and then executes all discovered tests. This sequence first configures, then builds, and finally runs the test suite. ```shell cmake . -DBUILD_TESTING=ON make test/cctest/cctest --list | tr -d '<' | xargs test/cctest/cctest ``` -------------------------------- ### Conditionally Installing Main Executable - CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/JavaScriptCore/shell/CMakeLists.txt Installs the built `jsc` executable to the specified `LIBEXEC_INSTALL_DIR` if the `SHOULD_INSTALL_JS_SHELL` CMake option is enabled. ```CMake if (SHOULD_INSTALL_JS_SHELL) install(TARGETS jsc DESTINATION "${LIBEXEC_INSTALL_DIR}") endif () ``` -------------------------------- ### Building and Testing with Make - Shell Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/dtoa/README.md Executes the default Makefile targets to build the double-conversion library and then run all associated test cases. This Makefile typically acts as a wrapper around SCons. ```shell make make test ``` -------------------------------- ### Configuring Build with CMake - Shell Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/dtoa/README.md Initializes the CMake build system in the current directory, preparing the project for compilation. Running this command will typically generate platform-specific build files, like Makefiles or Visual Studio project files. ```shell cmake . ``` -------------------------------- ### Identifying Target Operating System and Port in CMake Source: https://github.com/ultralight-ux/webcore/blob/master/CMakeLists.txt Verifies that the `PORT` variable has been set (indicating the target operating system/port configuration from the toolchain), raises a fatal error if not, sets the `WTF_PLATFORM_ULTRALIGHT` flag, derives the `WEBKIT_PORT_DIR` from the `PORT` variable, and includes the `Deps.cmake` file for dependency configuration. ```CMake # ----------------------------------------------------------------------------- # Determine the operating system and port # ----------------------------------------------------------------------------- # This should be set in platform toolchain. if (NOT PORT) message(FATAL_ERROR "Unknown PORT '${PORT}'") endif () set(WTF_PLATFORM_ULTRALIGHT 1) string(TOLOWER ${PORT} WEBKIT_PORT_DIR) include(Deps.cmake) ``` -------------------------------- ### Running Program Under Valgrind with mimalloc Build Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Provides the basic command to execute a program under the Valgrind tool. This command is used when mimalloc has been built with `MI_TRACK_VALGRIND=ON`. ```shell valgrind ``` -------------------------------- ### Including ExternalProject Module in CMake Source: https://github.com/ultralight-ux/webcore/blob/master/CMakeLists.txt Includes the standard CMake module `ExternalProject.cmake` from the CMake installation root, which provides functionality for downloading, building, and integrating external projects as part of the main build. ```CMake include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) ``` -------------------------------- ### Declaring Framework Target in CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/CMakeLists.txt Calls a custom macro `WEBKIT_FRAMEWORK_DECLARE(WTF)`. This macro likely performs initial setup or declaration for a framework target named 'WTF', specific to the WebKit build system. ```CMake WEBKIT_FRAMEWORK_DECLARE(WTF) ``` -------------------------------- ### Running Valgrind with Static Override and Stats (Shell) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Demonstrates how to run a program, statically linked with mimalloc, under Valgrind while ensuring Valgrind's own interceptors do not interfere and displaying mimalloc's statistics using `MIMALLOC_SHOW_STATS=1` and `--soname-synonyms`. ```shell MIMALLOC_SHOW_STATS=1 valgrind --soname-synonyms=somalloc=*mimalloc* -- ``` -------------------------------- ### Building mimalloc Release using CMake (Shell) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Steps to build the release version of the mimalloc library using the CMake build system on Unix-like platforms (macOS, Linux, BSD). This involves creating a build directory, configuring CMake from the source root, and compiling with make. ```Shell mkdir -p out/release cd out/release cmake ../.. make ``` -------------------------------- ### Building mimalloc with Valgrind Support (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Shows the CMake command used to configure the mimalloc build process to include support for the Valgrind memory analysis tool. This enables tracking capabilities within mimalloc that Valgrind can utilize. ```shell cmake ../.. -DMI_TRACK_VALGRIND=ON ``` -------------------------------- ### Declaring JavaScriptCore Framework (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/JavaScriptCore/CMakeLists.txt Calls a WebKit-specific CMake macro `WEBKIT_FRAMEWORK_DECLARE(JavaScriptCore)` which likely performs initial setup or declaration steps required for defining JavaScriptCore as a framework target within the build system. ```CMake WEBKIT_FRAMEWORK_DECLARE(JavaScriptCore) ``` -------------------------------- ### Finding mimalloc Package in CMake (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md CMake command used within a project's `CMakeLists.txt` file to locate an installed mimalloc library package. The `REQUIRED` keyword ensures that the build fails if the package is not found. ```CMake find_package(mimalloc 1.4 REQUIRED) ``` -------------------------------- ### Configuring POTFILES List (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/platform/gtk/po/CMakeLists.txt Copies and processes the `POTFILES.in` template file, replacing CMake variables within it, to create the final `POTFILES` file. This file lists all source code files that `xgettext` should scan for translatable strings. ```CMake configure_file(POTFILES.in ${potfiles_file}) ``` -------------------------------- ### Finding the mimalloc Package Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/test/CMakeLists.txt This command searches for the installed mimalloc package, requiring version 2.0 or higher, and explicitly prevents searching system environment paths. A status message is printed confirming the location where mimalloc was found. ```CMake find_package(mimalloc 2.0 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH) message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR} (${MIMALLOC_VERSION_DIR})") ``` -------------------------------- ### Building mimalloc with ETW Support (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Shows the CMake command used to configure the mimalloc build process to include support for Event Tracing for Windows (ETW). This enables mimalloc to emit allocation/deallocation events that can be captured by ETW. ```shell cmake ../.. -DMI_TRACE_ETW=ON ``` -------------------------------- ### Setting Interface Include Directories Variable CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/bmalloc/CMakeLists.txt Sets the `bmalloc_INTERFACE_INCLUDE_DIRECTORIES` variable to the value of `${bmalloc_FRAMEWORK_HEADERS_DIR}`. This variable specifies the directory where public header files for the bmalloc framework will be located or installed, making them available to projects linking against bmalloc. ```CMake set(bmalloc_INTERFACE_INCLUDE_DIRECTORIES ${bmalloc_FRAMEWORK_HEADERS_DIR}) ``` -------------------------------- ### Using mimalloc via LD_PRELOAD Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Demonstrates how to use mimalloc as a drop-in replacement for the standard `malloc` on dynamically linked ELF-based systems (like Linux or BSD) by setting the `LD_PRELOAD` environment variable to the path of the mimalloc shared library before running a program. ```Shell > LD_PRELOAD=/usr/lib/libmimalloc.so myprogram ``` -------------------------------- ### Show Detailed Stats with Debug Override (Linux/BSD) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Illustrates how to run a program with the debug version of mimalloc preloaded (`libmimalloc-debug.so`) and the `MIMALLOC_SHOW_STATS=1` environment variable set to display detailed runtime statistics collected by mimalloc. ```shell env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram ``` -------------------------------- ### Adding Target Dependencies - CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/CMakeLists.txt These commands establish build order dependencies, ensuring that the `WebCoreBindings` and `UltralightCoreBin` targets are built successfully before the `WebCore` target is built. `WebCorePrivateFrameworkHeaders` also depends on `WebCoreBindings`. ```CMake add_dependencies(WebCore WebCoreBindings) add_dependencies(WebCorePrivateFrameworkHeaders WebCoreBindings) add_dependencies(WebCore UltralightCoreBin) ``` -------------------------------- ### Setting Public Header Files Variable CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/bmalloc/CMakeLists.txt Defines the `bmalloc_PUBLIC_HEADERS` variable, listing all the header files (.h) that are intended to be part of the public interface of the bmalloc library. These headers are later used by the build system, likely for installation or copying. ```CMake set(bmalloc_PUBLIC_HEADERS bmalloc/Algorithm.h bmalloc/AllIsoHeaps.h bmalloc/AllIsoHeapsInlines.h bmalloc/Allocator.h bmalloc/AvailableMemory.h bmalloc/BAssert.h bmalloc/BCompiler.h bmalloc/BExport.h bmalloc/BInline.h bmalloc/BMalloced.h bmalloc/BPlatform.h bmalloc/BVMTags.h bmalloc/Bits.h bmalloc/BulkDecommit.h bmalloc/BumpAllocator.h bmalloc/BumpRange.h bmalloc/Cache.h bmalloc/Chunk.h bmalloc/CryptoRandom.h bmalloc/Deallocator.h bmalloc/DebugHeap.h bmalloc/DeferredDecommit.h bmalloc/DeferredDecommitInlines.h bmalloc/DeferredTrigger.h bmalloc/DeferredTriggerInlines.h bmalloc/EligibilityResult.h bmalloc/EligibilityResultInlines.h bmalloc/Environment.h bmalloc/FixedVector.h bmalloc/FreeList.h bmalloc/FreeListInlines.h bmalloc/Gigacage.h bmalloc/Heap.h bmalloc/HeapKind.h bmalloc/IsoAllocator.h bmalloc/IsoAllocatorInlines.h bmalloc/IsoConfig.h bmalloc/IsoDeallocator.h bmalloc/IsoDeallocatorInlines.h bmalloc/IsoDirectory.h bmalloc/IsoDirectoryInlines.h bmalloc/IsoDirectoryPage.h bmalloc/IsoDirectoryPageInlines.h bmalloc/IsoHeap.h bmalloc/IsoHeapImpl.h bmalloc/IsoHeapImplInlines.h bmalloc/IsoHeapInlines.h bmalloc/IsoPage.h bmalloc/IsoPageInlines.h bmalloc/IsoPageTrigger.h bmalloc/IsoSharedConfig.h bmalloc/IsoSharedHeap.h bmalloc/IsoSharedHeapInlines.h bmalloc/IsoSharedPage.h bmalloc/IsoSharedPageInlines.h bmalloc/IsoTLS.h bmalloc/IsoTLSAllocatorEntry.h bmalloc/IsoTLSAllocatorEntryInlines.h bmalloc/IsoTLSDeallocatorEntry.h bmalloc/IsoTLSDeallocatorEntryInlines.h bmalloc/IsoTLSEntry.h bmalloc/IsoTLSEntryInlines.h bmalloc/IsoTLSInlines.h bmalloc/IsoTLSLayout.h bmalloc/LargeMap.h bmalloc/LargeRange.h bmalloc/LineMetadata.h bmalloc/List.h bmalloc/Logging.h bmalloc/Map.h bmalloc/Mutex.h bmalloc/Object.h bmalloc/ObjectType.h bmalloc/PerHeapKind.h bmalloc/PerProcess.h bmalloc/PerThread.h bmalloc/PhysicalPageMap.h bmalloc/ProcessCheck.h bmalloc/Range.h bmalloc/Scavenger.h bmalloc/ScopeExit.h bmalloc/Sizes.h bmalloc/SmallLine.h bmalloc/SmallPage.h bmalloc/StaticPerProcess.h bmalloc/StdLibExtras.h bmalloc/Syscall.h bmalloc/VMAllocate.h bmalloc/VMHeap.h bmalloc/Vector.h bmalloc/Zone.h bmalloc/bmalloc.h ) ``` -------------------------------- ### Initializing CMake Project and Including External Projects Source: https://github.com/ultralight-ux/webcore/blob/master/Source/GetDeps/CMakeLists.txt This snippet sets the minimum required CMake version, defines the project name 'GetDeps', and includes the 'ExternalProject.cmake' module. The ExternalProject module is crucial for fetching, configuring, and building external dependencies within the CMake build process. ```CMake cmake_minimum_required(VERSION 3.3.2) project(GetDeps) include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) ``` -------------------------------- ### Declaring WebKit Framework CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/bmalloc/CMakeLists.txt Invokes the custom WebKit build system macro `WEBKIT_FRAMEWORK_DECLARE` with the argument "bmalloc". This macro likely performs internal setup and configuration necessary for defining a library or framework target within the WebKit build structure. ```CMake WEBKIT_FRAMEWORK_DECLARE(bmalloc) ``` -------------------------------- ### Detecting Operating System and Setting Port Variable (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/GetDeps/CMakeLists.txt This code block detects the operating system using CMake's built-in variables. It checks if the system is UNIX (then differentiates between Apple and other UNIX) or Windows, setting the 'PORT' variable accordingly. It includes a fatal error message for any other unrecognized operating system. ```CMake if (UNIX) if (APPLE) set(PORT UltralightMac) else () set(PORT UltralightLinux) endif () elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") set(PORT UltralightWin) else () message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'") endif () ``` -------------------------------- ### Generating Translation Template File (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/platform/gtk/po/CMakeLists.txt Defines a custom build command that executes the `xgettext` utility. It scans the source files listed in the generated `POTFILES` file and extracts translatable strings to create the master translation template file (`.pot`). Various command-line arguments configure the output, domain, comments, package information, keywords for string extraction, and encoding. ```CMake add_custom_command( OUTPUT ${pot_file} DEPENDS ${potfiles_file} COMMAND xgettext --default-domain=${domain} --add-comments --msgid-bugs-address="http://bugs.webkit.org" --files-from=${potfiles_file} --package-version=${PROJECT_VERSION} --package-name="webkitgtk" --keyword=_ --keyword=N_ --keyword=WEB_UI_STRING:1 --keyword=WEB_UI_STRING_KEY:3c,1 --keyword=WEB_UI_STRING_WITH_MNEMONIC:2 --from-code=UTF-8 -o ${pot_file} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. ) ``` -------------------------------- ### Conditional Build Logic for Malloc (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WTF/wtf/CMakeLists.txt This CMake command starts a conditional block. The subsequent build commands (not shown in this snippet) will only be processed if the CMake variable USE_SYSTEM_MALLOC is not set or is false. This allows tailoring the build process based on whether a system-provided or custom memory allocator is used. ```CMake if (NOT USE_SYSTEM_MALLOC) ``` -------------------------------- ### Setting PAL Source Files (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/PAL/pal/CMakeLists.txt Defines the list of source files (typically .cpp files) that are compiled to build the PAL framework library. The `set` command is used to populate the `PAL_SOURCES` variable with the relevant file paths. ```CMake set(PAL_SOURCES FileSizeFormatter.cpp Logging.cpp SessionID.cpp system/SleepDisabler.cpp system/SystemSleepListener.cpp ) ``` -------------------------------- ### Configuring SQLite Library Build using CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/SQLite/CMakeLists.txt This CMake script configures the build process for the SQLite library. It specifies the minimum CMake version required (2.8.8), defines the project name ('SQLite'), organizes the directory in the build tree, includes the directory containing SQLite headers via the ${SQLITE_DIR} variable, adds the position-independent code flag (-fPIC) when the PORT variable matches 'UltralightLinux', and defines a static library target named 'sqlite3' compiled from the 'sqlite3.c' source file. ```CMake cmake_minimum_required(VERSION 2.8.8) project(SQLite) set_property(DIRECTORY . PROPERTY FOLDER "Deps/SQLite") include_directories("${SQLITE_DIR}") if (PORT MATCHES "UltralightLinux") add_definitions(-fPIC) endif() add_library(sqlite3 sqlite3.c) ``` -------------------------------- ### Initializing Build Flags and Libraries (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/CMakeLists.txt This snippet initializes two empty variables, `mi_cflags` and `mi_libraries`. These variables are intended to be populated later in the script with necessary compiler flags and linker libraries, respectively. ```CMake set(mi_cflags "") set(mi_libraries "") ``` -------------------------------- ### Adding Project Modules with CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/CMakeLists.txt This CMake code snippet adds various subdirectories (modules) to the build process. It includes `bmalloc` (conditionally on non-Windows), `mimalloc`, `WTF`, `JavaScriptCore`, `SQLite`, and `WebCore`. Finally, it includes additional configuration files if present. This is a core part of defining the project's build structure by incorporating dependencies and core components. ```CMake # -----------------------------------------------------------------------------\n# Add module directories\n# -----------------------------------------------------------------------------\n# FIXME: Port bmalloc to Windows. https://bugs.webkit.org/show_bug.cgi?id=143310\nif (NOT WIN32)\n add_subdirectory(bmalloc)\nendif ()\n\nadd_subdirectory(mimalloc)\nadd_subdirectory(WTF)\nadd_subdirectory(JavaScriptCore)\nadd_subdirectory(SQLite)\nadd_subdirectory(WebCore)\n\nWEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS() ``` -------------------------------- ### Enable Verbose Output with Dynamic Override (Linux/BSD) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/readme.md Shows how to use the `MIMALLOC_VERBOSE=1` environment variable in conjunction with `LD_PRELOAD` to enable verbose output from mimalloc, allowing verification that mimalloc is being used during program execution. ```shell env MIMALLOC_VERBOSE=1 LD_PRELOAD=/usr/lib/libmimalloc.so myprogram ``` -------------------------------- ### Setting Main Executable Libraries - CMake Source: https://github.com/ultralight-ux/webcore/blob/master/Source/JavaScriptCore/shell/CMakeLists.txt Specifies the list of libraries that the `jsc` executable needs to link against. It includes system dynamic loading libraries, JavaScriptCore, and the WTF library, optionally with a debug suffix. ```CMake set(jsc_LIBRARIES ${CMAKE_DL_LIBS} JavaScriptCore${DEBUG_SUFFIX} WTF${DEBUG_SUFFIX} ) ``` -------------------------------- ### Setting Translation Variables (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/platform/gtk/po/CMakeLists.txt Defines several CMake variables used throughout the script to specify the gettext domain, the build directory for translation files, and the paths for the generated `.pot` template file and the `POTFILES` list. ```CMake set(domain WebKit2GTK-${WEBKITGTK_API_VERSION}) set(build_directory ${CMAKE_BINARY_DIR}/Source/WebCore/platform/gtk/po) set(pot_file ${build_directory}/${domain}.pot) set(potfiles_file ${build_directory}/POTFILES) ``` -------------------------------- ### Initializing CMake Project Configuration in CMake Source: https://github.com/ultralight-ux/webcore/blob/master/CMakeLists.txt Sets the minimum required CMake version for the project, appends a custom directory to the CMake module search path, includes a common configuration script, and defines the project name as 'WebCore'. ```CMake cmake_minimum_required(VERSION 3.15.0) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) include(common) project(WebCore) ``` -------------------------------- ### Including External Dependency Definitions (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/GetDeps/CMakeLists.txt This line includes another CMake file located relative to the current file. The included 'Deps.cmake' file is expected to contain definitions and configuration steps for the project's external dependencies. ```CMake include(../../Deps.cmake) ``` -------------------------------- ### Setting PAL Private Include Directories (CMake) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/WebCore/PAL/pal/CMakeLists.txt Specifies the directories containing private header files or intermediate/generated files necessary for compiling the PAL sources. The `set` command lists these paths, including build directory, derived sources, and the source directory itself. ```CMake set(PAL_PRIVATE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}" "${PAL_DERIVED_SOURCES_DIR}" "${PAL_DIR}" "${PAL_DIR}/pal" "${PAL_DIR}/pal/crypto" "${PAL_DIR}/pal/system" "${PAL_DIR}/pal/text" ) ``` -------------------------------- ### Adding Executable Linking Static mimalloc Library (C++) Source: https://github.com/ultralight-ux/webcore/blob/master/Source/mimalloc/test/CMakeLists.txt This snippet creates an executable 'static-override-cxx' from 'main-override.cpp' and links it against the 'mimalloc-static' library, testing the static linking method in C++. Similar to the C version, linker order issues are noted. ```CMake add_executable(static-override-cxx main-override.cpp) target_link_libraries(static-override-cxx PUBLIC mimalloc-static) ```