diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5be4b6140c..1d04f653238 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,6 +32,7 @@ jobs: os: - ubuntu-latest - windows-latest + - macos-latest crypto: - mbedtls - openssl @@ -59,6 +60,16 @@ jobs: toolchain: VS2019 - os: ubuntu-latest arch: ia32 + - os: macos-latest + arch: ia32 + - os: macos-latest + toolchain: GCC + - os: macos-latest + toolchain: VS2019 + - os: macos-latest + toolchain: ARM_GNU + - os: macos-latest + toolchain: LIBFUZZER - os: windows-latest toolchain: GCC arch: ia32 @@ -113,7 +124,7 @@ jobs: with: arch: x86 - name: Toolchain Setup - Clang - if: matrix.toolchain == 'CLANG' || matrix.toolchain == 'LIBFUZZER' && matrix.os == 'ubuntu-latest' + if: (matrix.toolchain == 'CLANG' || matrix.toolchain == 'LIBFUZZER') && matrix.os == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install llvm @@ -151,6 +162,16 @@ jobs: make copy_sample_key make copy_seed make -j`nproc` + - name: Build - Darwin + if: matrix.os == 'macos-latest' + run: | + mkdir -p build + cd build + cmake --version + cmake -E env CFLAGS="${{ matrix.configurations }} -DLIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG=3" cmake -DARCH=${{ matrix.arch }} -DTOOLCHAIN=${{ matrix.toolchain }} -DTARGET=${{ matrix.target }} -DCRYPTO=${{ matrix.crypto }} .. + make copy_sample_key + make copy_seed + make # process killed with multicore - name: Build - Windows if: matrix.os == 'windows-latest' && matrix.toolchain != 'GCC' run: | @@ -179,6 +200,16 @@ jobs: cmake -DARCH=x64 -DTOOLCHAIN=GCC -DTARGET=Debug -DCRYPTO=${{matrix.crypto}} -DGCOV=ON .. make copy_sample_key make -j`nproc` + - name: Build - Darwin - GCONV=ON + if: matrix.os == 'macos-latest' + run: | + mkdir -p build + cd build + cmake --version + cmake -DARCH=x64 -DTOOLCHAIN=CLANG -DTARGET=Debug -DCRYPTO=${{matrix.crypto}} -DGCOV=ON .. + make copy_sample_key + make copy_seed + make # process killed with multicore - name: Test Requester if: matrix.toolchain != 'LIBFUZZER' && matrix.toolchain != 'ARM_GNU' && matrix.configurations != '-DDISABLE_TESTS=1' run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b0c4e749fc..91a3271c58a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(STACK_USAGE STREQUAL "ON") message("STACK_USAGE = ON") endif() +elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") + if (TOOLCHAIN STREQUAL "CLANG") + message("TOOLCHAIN = CLANG") + else() + message(FATAL_ERROR "Unknown TOOLCHAIN") + endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") if(TOOLCHAIN STREQUAL "GCC") message("TOOLCHAIN = GCC") @@ -680,7 +686,19 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") add_compile_options(-m32) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32" ) endif() +elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") + if (TOOLCHAIN STREQUAL "CLANG") + set(CMAKE_C_COMPILER clang) + add_compile_options(-g -Og -fshort-wchar -fno-strict-aliasing -Wall -Wno-array-bounds -ffunction-sections -fdata-sections -fno-common -Wno-address -fpie -fno-asynchronous-unwind-tables) + + set(MBEDTLS_FLAGS "") + set(OPENSSL_FLAGS -include base.h -Wno-error=maybe-uninitialized -Wno-error=format -Wno-format -Wno-error=unused-but-set-variable) + set(CMOCKA_FLAGS -std=gnu99 -Wpedantic -Wall -Wshadow -Wmissing-prototypes -Wcast-align -Werror=address -Wstrict-prototypes -Werror=strict-prototypes -Wwrite-strings -Werror=write-strings -Werror-implicit-function-declaration -Wpointer-arith -Werror=pointer-arith -Wdeclaration-after-statement -Werror=declaration-after-statement -Wreturn-type -Werror=return-type -Wuninitialized -Werror=uninitialized -Werror=strict-overflow -Wstrict-overflow=2 -Wno-format-zero-length -Wmissing-field-initializers -Wformat-security -Werror=format-security -fno-common -Wformat -fno-common -fstack-protector-strong) + set(CMAKE_LINKER clang) + set(CMAKE_EXE_LINKER_FLAGS "-Wno-error") + set(CMAKE_C_LINK_EXECUTABLE " -o ") + endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") if(TOOLCHAIN STREQUAL "GCC") set(CMAKE_C_COMPILER gcc) @@ -879,7 +897,7 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) add_custom_target(copy_sample_key) execute_process(COMMAND uname OUTPUT_VARIABLE uname) -if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR uname MATCHES "^MINGW") +if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR uname MATCHES "^MINGW" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") add_custom_command(TARGET copy_sample_key PRE_BUILD COMMAND cp -r -f ${LIBSPDM_DIR}/unit_test/sample_key/* ${EXECUTABLE_OUTPUT_PATH}) @@ -901,7 +919,7 @@ endif() add_custom_target(copy_seed) -if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR uname MATCHES "^MINGW") +if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR uname MATCHES "^MINGW" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") add_custom_command(TARGET copy_seed PRE_BUILD COMMAND cp -r -f ${LIBSPDM_DIR}/unit_test/fuzzing/seeds ${EXECUTABLE_OUTPUT_PATH} diff --git a/os_stub/platform_lib/CMakeLists.txt b/os_stub/platform_lib/CMakeLists.txt index 0277762fc59..11a9be6edca 100644 --- a/os_stub/platform_lib/CMakeLists.txt +++ b/os_stub/platform_lib/CMakeLists.txt @@ -11,7 +11,7 @@ target_include_directories(platform_lib if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND (NOT TOOLCHAIN STREQUAL "ARM_DS2022") AND (NOT TOOLCHAIN STREQUAL "RISCV_XPACK") AND (NOT TOOLCHAIN STREQUAL "ARM_GNU_BARE_METAL")) target_sources(platform_lib PRIVATE - time_linux.c + time_unix.c watchdog.c ) elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") @@ -20,10 +20,16 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") time_win.c watchdog.c ) +elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") + target_sources(platform_lib + PRIVATE + time_unix.c + watchdog.c + ) else() target_sources(platform_lib PRIVATE time_sample.c watchdog.c ) -endif() \ No newline at end of file +endif() diff --git a/os_stub/platform_lib/time_linux.c b/os_stub/platform_lib/time_unix.c similarity index 100% rename from os_stub/platform_lib/time_linux.c rename to os_stub/platform_lib/time_unix.c diff --git a/os_stub/platform_lib_null/CMakeLists.txt b/os_stub/platform_lib_null/CMakeLists.txt index 7007070acc3..5a58836f5ac 100644 --- a/os_stub/platform_lib_null/CMakeLists.txt +++ b/os_stub/platform_lib_null/CMakeLists.txt @@ -11,7 +11,7 @@ target_include_directories(platform_lib_null if(CMAKE_SYSTEM_NAME MATCHES "Linux") target_sources(platform_lib_null PRIVATE - time_linux.c + time_unix.c watchdog.c ) elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") @@ -20,6 +20,11 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") time_win.c watchdog.c ) +elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") + target_sources(platform_lib_null + PRIVATE + time_unix.c + watchdog.c + ) endif() - diff --git a/os_stub/platform_lib_null/time_linux.c b/os_stub/platform_lib_null/time_unix.c similarity index 100% rename from os_stub/platform_lib_null/time_linux.c rename to os_stub/platform_lib_null/time_unix.c