Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .github/workflows/c-cpp-cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: C/C++ CI

on:
workflow_dispatch:
# allow manual launch

push:
branches: [ "main" ]
pull_request:
Expand All @@ -14,4 +17,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: build.sh
run: ./build.sh
run: ./build.sh
5 changes: 4 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -51,4 +54,4 @@ jobs:
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: ${{ env.COVERAGE_DATA_PATH }}
# fail_ci_if_error: true
# fail_ci_if_error: true
79 changes: 79 additions & 0 deletions ArduinoCore-Linux/cores/arduino/Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,82 @@ void yield(){
}


#if defined(_MSC_VER)

// For some reason bodies is not available under MSVC

#include <cstdlib>

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
<string.h> or <String.h> will include file that is found first on include path.

SOLUTION:
To partially solve this problem, system <string.h> 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 <string.h> 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 :)
*/
Loading