From 2dced56d9dd29f1d67d5c8dd7f1ab2d6095bef4f Mon Sep 17 00:00:00 2001
From: Ivan Kravets <me@ikravets.com>
Date: Sat, 28 Jan 2017 00:15:25 +0200
Subject: [PATCH 1/2] Initial version of build script for @PlatformIO; CI
 integration for Linux, macOS and Windows

---
 README.md                 |   7 +-
 appveyor.yml              |  19 ++++++
 package.json              |   6 ++
 tools/platformio-build.py | 139 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 appveyor.yml
 create mode 100755 package.json
 create mode 100644 tools/platformio-build.py

diff --git a/README.md b/README.md
index aa3810d99f2..6d1a10135f7 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
 # Arduino core for ESP32 WiFi chip
 
+[![Linux and macOS build status](https://travis-ci.org/esp8266/arduino-esp32.svg)](https://travis-ci.org/esp8266/arduino-esp32) [![Windows build status](https://ci.appveyor.com/api/projects/status/%INSERT_ID_HERE%/branch/develop?svg=true)](https://ci.appveyor.com/project/esp8266/arduino-esp32)
+
 ## Need help or have a question? Join the chat at [![https://gitter.im/espressif/arduino-esp32](https://badges.gitter.im/espressif/arduino-esp32.svg)](https://gitter.im/espressif/arduino-esp32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 
 - [Development Status](#development-status)
@@ -11,7 +13,7 @@
     + [Decoding Exceptions](#decoding-exceptions)
   + [Using PlatformIO](#using-platformio)
   + [Using as ESP-IDF component](#using-as-esp-idf-component)
-- [ESP32Dev Board PINMAP](#esp32dev-board-pinmap)  
+- [ESP32Dev Board PINMAP](#esp32dev-board-pinmap)
 
 ## Development Status
 Most of the framework is implemented. Most noticable is the missing analogWrite. While analogWrite is on it's way, there are a few other options that you can use:
@@ -70,6 +72,7 @@ Linux 32/64, Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard).
 - [Integration with Cloud and Standalone IDEs](http://docs.platformio.org/page/ide.html) -
   Cloud9, Codeanywehre, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM and Visual Studio
 - [Project Examples](https://github.com/platformio/platform-espressif32/tree/develop/examples)
+- [Using "Stage" (Git) version of Arduino Core](http://docs.platformio.org/page/platforms/espressif32.html#using-arduino-framework-with-staging-version)
 
 ### Using as ESP-IDF component
 - Download and install [esp-idf](https://github.com/espressif/esp-idf)
@@ -100,7 +103,7 @@ Linux 32/64, Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard).
             delay(1000);
           }
           ```
-          
+
         - Else you need to implement ```app_main()``` and call ```initArduino();``` in it.
 
           Keep in mind that setup() and loop() will not be called in this case.
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 00000000000..62bdcce8883
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,19 @@
+build: off
+environment:
+
+  matrix:
+    - PLATFORMIO_CI_SRC: "libraries/WiFi/examples/WiFiClient"
+    - PLATFORMIO_CI_SRC: "libraries/WiFi/examples/WiFiClientBasic"
+    - PLATFORMIO_CI_SRC: "libraries/WiFi/examples/WiFiClientEvents"
+    - PLATFORMIO_CI_SRC: "libraries/WiFi/examples/WiFiIPv6"
+    - PLATFORMIO_CI_SRC: "libraries/WiFi/examples/WiFiScan"
+    - PLATFORMIO_CI_SRC: "libraries/WiFi/examples/WiFiSmartConfig"
+
+install:
+  - cmd: git submodule update --init --recursive
+  - cmd: SET PATH=%PATH%;C:\Python27\Scripts
+  - cmd: pip install -U https://github.com/platformio/platformio/archive/develop.zip
+  - cmd: platformio platform install https://github.com/platformio/platform-espressif32.git#feature/stage
+
+test_script:
+  - cmd: platformio ci -b esp32dev -b nano32 -b node32s
diff --git a/package.json b/package.json
new file mode 100755
index 00000000000..1a7f443f58a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,6 @@
+{
+    "name": "framework-arduinoespressif32",
+    "description": "Arduino Wiring-based Framework (ESP32 Core)",
+    "version": "0.0.0",
+    "url": "https://github.com/espressif/arduino-esp32"
+}
\ No newline at end of file
diff --git a/tools/platformio-build.py b/tools/platformio-build.py
new file mode 100644
index 00000000000..413843b9f0b
--- /dev/null
+++ b/tools/platformio-build.py
@@ -0,0 +1,139 @@
+# Copyright 2014-present PlatformIO <contact@platformio.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Arduino
+
+Arduino Wiring-based Framework allows writing cross-platform software to
+control devices attached to a wide range of Arduino boards to create all
+kinds of creative coding, interactive objects, spaces or physical experiences.
+
+http://arduino.cc/en/Reference/HomePage
+"""
+
+from os.path import isdir, join
+
+from SCons.Script import DefaultEnvironment
+
+env = DefaultEnvironment()
+platform = env.PioPlatform()
+
+FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
+assert isdir(FRAMEWORK_DIR)
+
+env.Prepend(
+    CPPDEFINES=[
+        ("ARDUINO", 10610),
+        "ARDUINO_ARCH_ESP32"
+    ],
+
+    CFLAGS=["-Wno-old-style-declaration"],
+
+    CCFLAGS=[
+        "-Wno-error=deprecated-declarations",
+        "-Wno-unused-parameter",
+        "-Wno-sign-compare"
+    ],
+
+    CPPPATH=[
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "config"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "bt"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "driver"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "esp32"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "ethernet"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "fatfs"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "freertos"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "log"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "mdns"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "vfs"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "ulp"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "newlib"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "nvs_flash"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "spi_flash"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "sdmmc"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "openssl"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "app_update"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "tcpip_adapter"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "xtensa-debug-module"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "coap"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "wpa_supplicant"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "expat"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "json"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "mbedtls"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "nghttp"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "include", "lwip"),
+        join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core"))
+    ],
+    LIBPATH=[
+        join(FRAMEWORK_DIR, "tools", "sdk", "lib"),
+        join(FRAMEWORK_DIR, "tools", "sdk", "ld"),
+    ],
+    LIBS=[
+        "app_update", "bootloader_support", "bt", "btdm_app", "c",
+        "c_nano", "coap", "coexist", "core", "cxx", "driver", "esp32",
+        "ethernet", "expat", "fatfs", "freertos", "hal", "json", "log",
+        "lwip", "m", "mbedtls", "mdns", "micro-ecc", "net80211", "newlib",
+        "nghttp", "nvs_flash", "openssl", "phy", "pp", "rtc", "sdmmc",
+        "smartconfig", "spi_flash", "tcpip_adapter", "ulp", "vfs", "wpa",
+        "wpa2", "wpa_supplicant", "wps", "xtensa-debug-module", "gcc", "stdc++"
+    ]
+)
+
+env.Append(
+    LIBSOURCE_DIRS=[
+        join(FRAMEWORK_DIR, "libraries")
+    ],
+
+    LINKFLAGS=[
+        "-Wl,-EL",
+        "-T", "esp32.common.ld",
+        "-T", "esp32.rom.ld",
+        "-T", "esp32.peripherals.ld"
+    ],
+
+    UPLOADERFLAGS=[
+        "0x1000", '"%s"' % join(FRAMEWORK_DIR, "tools",
+                                "sdk", "bin", "bootloader.bin"),
+        "0x8000", '"%s"' % join(FRAMEWORK_DIR, "tools",
+                                "sdk", "bin", "partitions_singleapp.bin"),
+        "0x10000"
+    ]
+)
+
+#
+# Target: Build Core Library
+#
+
+libs = []
+
+if "build.variant" in env.BoardConfig():
+    env.Append(
+        CPPPATH=[
+            join(FRAMEWORK_DIR, "variants",
+                 env.BoardConfig().get("build.variant"))
+        ]
+    )
+    libs.append(env.BuildLibrary(
+        join("$BUILD_DIR", "FrameworkArduinoVariant"),
+        join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant"))
+    ))
+
+envsafe = env.Clone()
+
+libs.append(envsafe.BuildLibrary(
+    join("$BUILD_DIR", "FrameworkArduino"),
+    join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core"))
+))
+
+env.Prepend(LIBS=libs)

From a83c3d486f2ec2c1e52294d1edb168e05e493d1d Mon Sep 17 00:00:00 2001
From: Ivan Kravets <me@ikravets.com>
Date: Sat, 28 Jan 2017 14:15:31 +0200
Subject: [PATCH 2/2] Remove CI badges

---
 README.md | 2 --
 1 file changed, 2 deletions(-)

diff --git a/README.md b/README.md
index 6d1a10135f7..e29967bdce6 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,5 @@
 # Arduino core for ESP32 WiFi chip
 
-[![Linux and macOS build status](https://travis-ci.org/esp8266/arduino-esp32.svg)](https://travis-ci.org/esp8266/arduino-esp32) [![Windows build status](https://ci.appveyor.com/api/projects/status/%INSERT_ID_HERE%/branch/develop?svg=true)](https://ci.appveyor.com/project/esp8266/arduino-esp32)
-
 ## Need help or have a question? Join the chat at [![https://gitter.im/espressif/arduino-esp32](https://badges.gitter.im/espressif/arduino-esp32.svg)](https://gitter.im/espressif/arduino-esp32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 
 - [Development Status](#development-status)