diff --git a/.github/workflows/c-cpp-cmake.yml b/.github/workflows/c-cpp-cmake.yml index 66a5cda..2e2a0f3 100644 --- a/.github/workflows/c-cpp-cmake.yml +++ b/.github/workflows/c-cpp-cmake.yml @@ -1,6 +1,9 @@ name: C/C++ CI on: + workflow_dispatch: + # allow manual launch + push: branches: [ "main" ] pull_request: @@ -14,4 +17,4 @@ jobs: steps: - uses: actions/checkout@v4 - name: build.sh - run: ./build.sh \ No newline at end of file + run: ./build.sh diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b7c9311..65bfa0f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,6 +1,9 @@ name: Unit Tests on: + workflow_dispatch: + # allow manual launch + pull_request: # Only run workflow if a file in these paths is modified paths: @@ -51,4 +54,4 @@ jobs: # with: # token: ${{ secrets.CODECOV_TOKEN }} # files: ${{ env.COVERAGE_DATA_PATH }} - # fail_ci_if_error: true \ No newline at end of file + # fail_ci_if_error: true diff --git a/ArduinoCore-Linux/cores/arduino/Arduino.cpp b/ArduinoCore-Linux/cores/arduino/Arduino.cpp index f93ceb0..b1967dd 100644 --- a/ArduinoCore-Linux/cores/arduino/Arduino.cpp +++ b/ArduinoCore-Linux/cores/arduino/Arduino.cpp @@ -148,3 +148,82 @@ void yield(){ } +#if defined(_MSC_VER) + +// For some reason bodies is not available under MSVC + +#include + +void randomSeed(unsigned long seed) +{ + if (seed != 0) { + srand(seed); + } +} + +long random(long howbig) +{ + if (howbig == 0) { + return 0; + } + return rand() % howbig; +} + +long random(long howsmall, long howbig) +{ + if (howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; +} + +#endif + +/* +Notes on how to build under Windows with MSVC +============================================= +Under windows there is well known conflict between Arduino String.h and system string.h. +If you read this, you probably seen a lot of problems with functiosn like strlen, strcmp, strcpy, memcpy etc. + +BACKROUND: +Main problem reason is that windows file system is case insensitive and when some module trying to include + or will include file that is found first on include path. + +SOLUTION: +To partially solve this problem, system always included in angle brackets, while Arduino "String.h" in quotes with correct path. +This way IF (and only if) system include paths are BEFORE Arduino include paths, THEN will always include system file. +Note: While you do not need to include String.h directly, it is included by Arduino.h, but you still have to setup path correctly. + +IMPLEMENTATION: HOW TO ENSURE THAT SYSTEM PATHS ARE BEFORE ARDUINO PATHS: +You have to ensure that system include paths are before any Arduino include paths. +On systems like VSCODE+MSVC system include paths are set via INCLUDE env var, while project-related path are in command line. +Unfortunately %INCLUDE% have lower priority than path in command line (and /I compiler option accept only one path), +you have to do some tricks to achive the goal. + +For VSCODE, you have to set paths in two places: +1. .vscode/c_cpp_properties.json +Here are paths for IntelliSense and (code completion) you have to add ${env:INCLUDE} as first entry in "includePath" array +"includePath": [ "${env:INCLUDE}", +2. .vscode/tasks.json +Here are paths for build (compilation), but since adding /I with multiple paths does not work, +you cannot add /I${env:INCLUDE} as first entry in "args" array +2.1 Option A: add add VS system paths one by one as separate /I entries BEFORE any Arduino related paths +"/I${env:VCINSTALLDIR}Tools\\MSVC\\${env:VCToolsVersion}\\ATLMFC\\include", +"/I${env:VCINSTALLDIR}Tools\\MSVC\\${env:VCToolsVersion}\\include", +"/I${env:NETFXSDKDir}include\\um", +"/I${env:WindowsSdkDir}include\\${env:UCRTVersion}\\ucrt", +"/I${env:WindowsSdkDir}include\\${env:UCRTVersion}\\shared", +"/I${env:WindowsSdkDir}include\\${env:UCRTVersion}\\um", +"/I${env:WindowsSdkDir}include\\${env:UCRTVersion}\\winrt", +"/I${env:WindowsSdkDir}include\\${env:UCRTVersion}\\cppwinrt", +2.2 Option B: appens your project Arduino-related path to INCLUDE env var after system paths +You have to add LIB, LIBPATH among with INCLUDE env vars to "env" section of "options" in tasks.json +Example: +"options": { +... +"env": { "LIB": "${env:LIB}", "LIBPATH": "${env:LIBPATH}", + "INCLUDE": "${env:INCLUDE};${workspaceFolder};${workspaceFolder}/tests;${workspaceFolder}/tests/sim;${workspaceFolder}/tests/sim/Arduino-Emulator/ArduinoCore-API/api;${workspaceFolder}/tests/sim/Arduino-Emulator/ArduinoCore-API/api/deprecated-avr-comp;${workspaceFolder}/tests/sim/Arduino-Emulator/ArduinoCore-Linux/cores/arduino", +} +2.3 Option C: invent something more elegant by yourself :) +*/