Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.28...4.3)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

set(VCPKG_MANIFEST_INSTALL OFF)
set(VCPKG_INSTALLED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed)

set (VCPKG_OVERLAY_TRIPLETS ENV{VCPKG_OVERLAY_TRIPLETS})
set(CMAKE_CXX_STANDARD 26)
include(homebrewClang.cmake)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# No C++ modules in the codebase yet: CMake >= 3.28 (CMP0155) would otherwise
# scan all C++20+ sources for module imports, injecting GCC scanning flags
# (-fmodules-ts, -fmodule-mapper, -fdeps-format) into compile_commands.json,
# which clangd rejects. The modules migration will turn scanning back on.
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
include(cmake/homebrewClang.cmake)

enable_testing()

Expand Down
76 changes: 76 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"version": 8,
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build"
},
{
"name": "host-debug",
"displayName": "Host build (Debug)",
"inherits": "base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "host-release",
"displayName": "Host build (Release)",
"inherits": "base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "ios-base",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "arm64-ios",
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/overlaytriplets/arm64-ios.cmake",
"PLATFORM": "OS64"
}
},
{
"name": "ios-debug",
"displayName": "iOS cross-build (arm64-ios, Debug)",
"inherits": "ios-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "ios-release",
"displayName": "iOS cross-build (arm64-ios, Release)",
"inherits": "ios-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "android-base",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "arm64-android",
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "$env{ANDROID_NDK}/build/cmake/android.toolchain.cmake",
"ANDROID_ABI": "arm64-v8a",
"ANDROID_PLATFORM": "24"
}
},
{
"name": "android-debug",
"displayName": "Android cross-build (arm64-android, Debug)",
"inherits": "android-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "android-release",
"displayName": "Android cross-build (arm64-android, Release)",
"inherits": "android-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
}
],
"buildPresets": [
{ "name": "host-debug", "configurePreset": "host-debug" },
{ "name": "host-release", "configurePreset": "host-release" },
{ "name": "ios-debug", "configurePreset": "ios-debug" },
{ "name": "ios-release", "configurePreset": "ios-release" },
{ "name": "android-debug", "configurePreset": "android-debug" },
{ "name": "android-release", "configurePreset": "android-release" }
]
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ source install-prerequisities.sh

This script will recognize the operating system type and install the prerequisities for the SDK. It will also create a `setenvs.sh` file in the root directory of the repository that you can use to set the correct environment variables for the SDK when you resume development in a new terminal.

All builds use the [Ninja](https://ninja-build.org/) CMake generator (exported as `CMAKE_GENERATOR=Ninja` by `install-prerequisities.sh`/`setenvs.sh`). Ninja is faster than Makefiles and is required by CMake's C++ modules support. **If you have build directories configured with the previous Makefile generator, run `./clean.sh` once after updating.**

### Install all the dependencies and build the SDK for MacOS and Linux

```bash
Expand All @@ -55,8 +57,8 @@ The `install.sh` script supports an optional `--prod` parameter. When this param

`install.sh` does the following:

1. Loops through packages listed in `MonorepoPackages.cmake`, and builds each using `cmake` and `make`. This will trigger the fetching of dependencies using `vcpkg` and the building of each package in its own `build` directory.
2. Builds the SDK in the root directory using `cmake` and `make`. This will trigger the building of the SDK in the `build` folder of the root directory. This is needed for VSCode and its extensions to work correctly.
1. Loops through packages listed in `MonorepoPackages.cmake`, and builds each using `cmake` (Ninja generator). This will trigger the fetching of dependencies using `vcpkg` and the building of each package in its own `build` directory.
2. Builds the SDK in the root directory using `cmake` (Ninja generator). This will trigger the building of the SDK in the `build` folder of the root directory. This is needed for VSCode and its extensions to work correctly.

### Install all the dependencies and build the SDK for iOS

Expand Down Expand Up @@ -124,8 +126,10 @@ The Streamr Native SDK monorepo has two GIT submodules at its root:

#### CMake files
* `MonorepoPackages.cmake` - a CMake file that lists all the packages in the monorepo. **The order of the packages in this file is important.** The packages are built in the order of the list and the dependencies between the packages are resolved based on the order of the packages in the list.
* `homebrewClang.cmake` - a CMake file that takes the latest version of the Clang compiler and associated tools into use in the build on macOS.
* `cmake/` - the canonical copies of the CMake helper files that every package carries a copy of (`homebrewClang.cmake`, `monorepoPackage.cmake`). Edit the files here and run `./sync-cmake-files.sh` to update the package copies; `lint.sh` and CI fail if the copies are out of sync. The per-package copies are intentional: they let a package be published as a standalone vcpkg package later.
* `cmake/homebrewClang.cmake` - a CMake file that takes the latest version of the Clang compiler and associated tools into use in the build on macOS.
* `CMakeLists.txt` - the main CMake file for the whole monorepo. Includes all the packages listed in `MonorepoPackages.cmake` into the build using `add_subdirectory()` of CMAKE.
* `CMakePresets.json` - CMake configure/build presets (`host-debug`, `host-release`, `ios-debug/-release`, `android-debug/-release`) encoding the generator, triplet and toolchain combinations for IDEs and manual `cmake --preset` use.

#### Scripts
| Script | Ts equivalent | Description |
Expand All @@ -138,6 +142,7 @@ The Streamr Native SDK monorepo has two GIT submodules at its root:
| `test.sh` | npm run test | Run the tests of the whole monorepo. |
| `clean.sh` | npm run clean | Clean the build folders of all the packages in the monorepo. |
| `merge-dependencies.sh` | N/A | A helper script called by install.sh to merge the VCPKG dependencies of the monorepo packages to the root vcpkg.json **must not be invoked by the user** |
| `sync-cmake-files.sh` | N/A | Copy the canonical CMake helper files from `cmake/` into every package (`--check` verifies without copying; run by `lint.sh` and CI). |
| `iostest.sh`| N/A | Run selected unit tests in iOS Device (In MacOS by default). Unit tests can be selected by adding tests (Drag and drop) to the App iOSUnitTesting. |


Expand Down
6 changes: 6 additions & 0 deletions homebrewClang.cmake → cmake/homebrewClang.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# CANONICAL COPY — the per-package copies in packages/*/homebrewClang.cmake
# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and
# run the sync script; do not edit the package copies directly.
# (Each package carries its own copy so that it can be published as a
# standalone vcpkg package later.)

if (APPLE AND NOT (VCPKG_TARGET_TRIPLET MATCHES "android" OR VCPKG_TARGET_TRIPLET MATCHES "linux"))
message(STATUS "APPLE is defined")
set(HOMEBREW_PREFIX $ENV{HOMEBREW_PREFIX})
Expand Down
56 changes: 56 additions & 0 deletions cmake/monorepoPackage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# CANONICAL COPY — the per-package copies in packages/*/monorepoPackage.cmake
# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and
# run the sync script; do not edit the package copies directly.
# (Each package carries its own copy so that it can be published as a
# standalone vcpkg package later.)

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../MonorepoPackages.cmake)
message(STATUS "In monorepo sub-package ${CMAKE_CURRENT_SOURCE_DIR}")

# if in monorepo, do not install vcpkg dependencies
set(VCPKG_MANIFEST_INSTALL OFF)

# if in monorepo, use the vcpkg dependencies from the monorepo root
set(OWNPATH ../../build/vcpkg_installed)
file(REAL_PATH ${OWNPATH} OWNPATH)
message(STATUS "OWNPATH: ${OWNPATH}")
set(VCPKG_INSTALLED_DIR ${OWNPATH})

# if in monorepo, use the monorepo deps from filesystem
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json VCPKG_JSON)

string(JSON VCPKG_JSON_DECODED ERROR_VARIABLE parse_error GET ${VCPKG_JSON} "features")
if(VCPKG_JSON_DECODED)
string(JSON MONOREPO_EXISTS ERROR_VARIABLE parse_error GET ${VCPKG_JSON_DECODED} "monorepo")
if(MONOREPO_EXISTS)
string(JSON MONOREPO_DEPENDENCIES ERROR_VARIABLE parse_error GET ${MONOREPO_EXISTS} "dependencies")
set(MONOREPO_DEPENDENCIES ${MONOREPO_DEPENDENCIES})

string(JSON MONOREPO_DEPENDENCIES_LENGTH ERROR_VARIABLE parse_error LENGTH ${MONOREPO_DEPENDENCIES})
math(EXPR END_INDEX "${MONOREPO_DEPENDENCIES_LENGTH}-1")
message(STATUS "END_INDEX: ${END_INDEX}")
foreach(idx RANGE "${END_INDEX}")
string(JSON MONOREPO_DEPENDENCY ERROR_VARIABLE parse_error GET ${MONOREPO_DEPENDENCIES} "${idx}")
file(REAL_PATH "../${MONOREPO_DEPENDENCY}/build" MONBUILDDIR)
set(${MONOREPO_DEPENDENCY}_DIR ${MONBUILDDIR})
# Append to both search variables: CMAKE_PREFIX_PATH covers
# native builds, CMAKE_FIND_ROOT_PATH is needed when a
# cross-compiling toolchain (iOS/Android) re-roots find_*.
list(APPEND CMAKE_PREFIX_PATH ${MONBUILDDIR})
list(APPEND CMAKE_PREFIX_PATH "${MONBUILDDIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/share")
list(APPEND CMAKE_FIND_ROOT_PATH ${MONBUILDDIR})
list(APPEND CMAKE_FIND_ROOT_PATH "${MONBUILDDIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/share")
message(STATUS "${MONOREPO_DEPENDENCY}_DIR: ${${MONOREPO_DEPENDENCY}_DIR}")
endforeach()
endif()
else()
set(MONOREPO_DEPENDENCIES "")
endif()
endif()
else()
# if not in monorepo, fetch also monorepo deps with vcpkg
list(APPEND VCPKG_MANIFEST_FEATURES "monorepo")
endif()
10 changes: 10 additions & 0 deletions install-prerequisities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
brew uninstall llvm || true
brew install llvm@17 || true
brew install cmake || true
brew install ninja || true
brew install pkg-config || true

brew link --overwrite --force llvm@17
Expand All @@ -45,6 +46,15 @@ else
fi
fi

# Use the Ninja generator for all CMake builds. Ninja is faster than
# Makefiles and is required by CMake's C++ modules support (upcoming
# modules migration). NOTE: build dirs configured with the old Makefile
# generator must be cleaned once after this change (./clean.sh).
export CMAKE_GENERATOR=Ninja
if [[ -n "$GITHUB_ENV" ]]; then
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
fi
TEMP_PROFILE_CONTENTS+="export CMAKE_GENERATOR=Ninja\n"

cd clangd-tidy
rm -f clang-tidy
Expand Down
21 changes: 20 additions & 1 deletion lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@

set -e

# Verify that the per-package copies of the CMake helper files match the
# canonical versions in cmake/ (see sync-cmake-files.sh).
if ! ./sync-cmake-files.sh --check; then
echo "::error title=cmake helper files out of sync::Run ./sync-cmake-files.sh and commit the result."
exit 1
fi

# Parse MonorepoPackages.cmake and loop through them
for package in $(cat MonorepoPackages.cmake | grep -v "set(MonorepoPackages" | grep -v ")"); do
echo ""
echo "Running lint.sh for $package"
cd packages/$package && ./lint.sh && cd ../..
LOG_FILE=$(mktemp)
if (cd packages/$package && ./lint.sh) > "$LOG_FILE" 2>&1; then
cat "$LOG_FILE"
rm -f "$LOG_FILE"
else
cat "$LOG_FILE"
# Emit the failure tail as a GitHub Actions error annotation so the
# cause is visible in the Checks UI without opening the raw logs.
MSG=$(tail -40 "$LOG_FILE" | sed 's/%/%25/g' | awk '{printf "%s%%0A", $0}')
echo "::error title=lint failed for ${package}::${MSG}"
rm -f "$LOG_FILE"
exit 1
fi
done
8 changes: 7 additions & 1 deletion packages/streamr-dht/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.28...4.3)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

include(homebrewClang.cmake)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# No C++ modules in the codebase yet: CMake >= 3.28 (CMP0155) would otherwise
# scan all C++20+ sources for module imports, injecting GCC scanning flags
# (-fmodules-ts, -fmodule-mapper, -fdeps-format) into compile_commands.json,
# which clangd rejects. The modules migration will turn scanning back on.
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# makes the current package a monorepo package
Expand Down
6 changes: 6 additions & 0 deletions packages/streamr-dht/homebrewClang.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# CANONICAL COPY — the per-package copies in packages/*/homebrewClang.cmake
# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and
# run the sync script; do not edit the package copies directly.
# (Each package carries its own copy so that it can be published as a
# standalone vcpkg package later.)

if (APPLE AND NOT (VCPKG_TARGET_TRIPLET MATCHES "android" OR VCPKG_TARGET_TRIPLET MATCHES "linux"))
message(STATUS "APPLE is defined")
set(HOMEBREW_PREFIX $ENV{HOMEBREW_PREFIX})
Expand Down
17 changes: 14 additions & 3 deletions packages/streamr-dht/monorepoPackage.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# CANONICAL COPY — the per-package copies in packages/*/monorepoPackage.cmake
# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and
# run the sync script; do not edit the package copies directly.
# (Each package carries its own copy so that it can be published as a
# standalone vcpkg package later.)

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../MonorepoPackages.cmake)
message(STATUS "In monorepo sub-package ${CMAKE_CURRENT_SOURCE_DIR}")

# if in monorepo, do not install vcpkg dependencies
set(VCPKG_MANIFEST_INSTALL OFF)

# if in monorepo, use the vcpkg dependencies from the monorepo root
set(OWNPATH ../../build/vcpkg_installed)
file(REAL_PATH ${OWNPATH} OWNPATH)
Expand All @@ -15,23 +21,28 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../MonorepoPackages.cmake)
# if in monorepo, use the monorepo deps from filesystem
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json VCPKG_JSON)

string(JSON VCPKG_JSON_DECODED ERROR_VARIABLE parse_error GET ${VCPKG_JSON} "features")
if(VCPKG_JSON_DECODED)
string(JSON MONOREPO_EXISTS ERROR_VARIABLE parse_error GET ${VCPKG_JSON_DECODED} "monorepo")
if(MONOREPO_EXISTS)
string(JSON MONOREPO_DEPENDENCIES ERROR_VARIABLE parse_error GET ${MONOREPO_EXISTS} "dependencies")
set(MONOREPO_DEPENDENCIES ${MONOREPO_DEPENDENCIES})

string(JSON MONOREPO_DEPENDENCIES_LENGTH ERROR_VARIABLE parse_error LENGTH ${MONOREPO_DEPENDENCIES})
math(EXPR END_INDEX "${MONOREPO_DEPENDENCIES_LENGTH}-1")
message(STATUS "END_INDEX: ${END_INDEX}")
foreach(idx RANGE "${END_INDEX}")
string(JSON MONOREPO_DEPENDENCY ERROR_VARIABLE parse_error GET ${MONOREPO_DEPENDENCIES} "${idx}")
file(REAL_PATH "../${MONOREPO_DEPENDENCY}/build" MONBUILDDIR)
set(${MONOREPO_DEPENDENCY}_DIR ${MONBUILDDIR})
# Append to both search variables: CMAKE_PREFIX_PATH covers
# native builds, CMAKE_FIND_ROOT_PATH is needed when a
# cross-compiling toolchain (iOS/Android) re-roots find_*.
list(APPEND CMAKE_PREFIX_PATH ${MONBUILDDIR})
list(APPEND CMAKE_PREFIX_PATH "${MONBUILDDIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/share")
list(APPEND CMAKE_FIND_ROOT_PATH ${MONBUILDDIR})
list(APPEND CMAKE_FIND_ROOT_PATH "${MONBUILDDIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/share")
message(STATUS "${MONOREPO_DEPENDENCY}_DIR: ${${MONOREPO_DEPENDENCY}_DIR}")
endforeach()
endif()
Expand Down
9 changes: 5 additions & 4 deletions packages/streamr-dht/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash

cd build
cmake ..
make
export LOG_LEVEL=trace
export GTEST_COLOR=1
export GTEST_BREAK_ON_FAILURE=1
export LOG_LEVEL=trace

cmake --build build || exit 1

cd build

if [ "$#" -gt 0 ]; then
ctest -V -R "$@"
Expand Down
8 changes: 7 additions & 1 deletion packages/streamr-eventemitter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.28...4.3)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# No C++ modules in the codebase yet: CMake >= 3.28 (CMP0155) would otherwise
# scan all C++20+ sources for module imports, injecting GCC scanning flags
# (-fmodules-ts, -fmodule-mapper, -fdeps-format) into compile_commands.json,
# which clangd rejects. The modules migration will turn scanning back on.
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
include(homebrewClang.cmake)

set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES Off)
Expand Down
6 changes: 6 additions & 0 deletions packages/streamr-eventemitter/homebrewClang.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# CANONICAL COPY — the per-package copies in packages/*/homebrewClang.cmake
# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and
# run the sync script; do not edit the package copies directly.
# (Each package carries its own copy so that it can be published as a
# standalone vcpkg package later.)

if (APPLE AND NOT (VCPKG_TARGET_TRIPLET MATCHES "android" OR VCPKG_TARGET_TRIPLET MATCHES "linux"))
message(STATUS "APPLE is defined")
set(HOMEBREW_PREFIX $ENV{HOMEBREW_PREFIX})
Expand Down
Loading
Loading