Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 19b4fd8

Browse files
authored
Merge pull request #1584 from microsoft/dev/bemcmorr/bundle-arduino-cli
Bundle arduino-cli with extension
2 parents fffcbf2 + b2d5a76 commit 19b4fd8

14 files changed

+369
-32
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules
66
src/views/app/sprites-generated
77
test/**/c_cpp_properties.json
88
*.vsix
9+
assets/platform/*/arduino-cli

NOTICE_arduino-cli.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
NOTICES AND INFORMATION
2+
Do Not Translate or Localize
3+
4+
Microsoft makes the arduino-cli open source code available at
5+
https://3rdpartysource.microsoft.com, or you may send a check or money order for
6+
US $5.00, including the product name, the open source component name, platform,
7+
and version number, to:
8+
9+
Source Code Compliance Team
10+
Microsoft Corporation
11+
One Microsoft Way
12+
Redmond, WA 98052
13+
USA
14+
15+
Notwithstanding any other terms, you may reverse engineer this software to the extent
16+
required to debug changes to any libraries licensed under the GNU Lesser General Public License.

README.md

+26-16
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,31 @@ Welcome to the Visual Studio Code extension for **Arduino** <sup>preview</sup> !
1515
* Integrated Arduino Debugging <sup>New</sup>
1616

1717
## Prerequisites
18-
Either the Arduino IDE or Arduino CLI are required.
18+
Either the legacy Arduino IDE or Arduino CLI are required. The recommended
19+
approach is to use the version of Arduino CLI that comes bundled with the
20+
extension, which works out of the box. Support for the legacy Arduino IDE will
21+
be removed in a future version of the extension.
1922

20-
### Arduino IDE
21-
The Arduino IDE can be installed the Arduino [download page](https://www.arduino.cc/en/main/software#download).
22-
- The supported Arduino IDE versions are `1.6.x` and up to, but not including, 2.0.0.
23+
### Arduino CLI
24+
To use the bundled version of Arduino CLI, `arduino.useArduinoCli` should be `true`,
25+
and `arduino.path` and `arduino.commandPath` should be empty or unset.
26+
`arduino.useArduinoCli` defaults to `false` while we deprecate support for the
27+
Arduino IDE, but there will be a prompt when the extension first activates to
28+
switch to the Arduino CLI.
29+
30+
If you want to use a custom version of Arduino CLI, it can be downloaded from
31+
the repository's [release page](https://github.com/arduino/arduino-cli/releases/).
32+
For custom versions, `arduino.path` must be set to the directory containing the
33+
Arduino CLI executable.
34+
35+
### Legacy Arduino IDE
36+
Use of the legacy Arduino IDE is not recommended, and support for the legacy
37+
Arduino IDE will be removed in a future version of the extension. The legacy
38+
Arduino IDE can be installed from the Arduino [download page](https://www.arduino.cc/en/main/software#download).
39+
- The supported legacy Arduino IDE versions are `1.6.x` and up to, but not including, `2.0.0`.
2340
- The Windows Store's version of the Arduino IDE is not supported because of the sandbox environment that the application runs in.
2441
- *Note:* Arduino IDE `1.8.7` had some breaking changes, causing board package and library installation failures. These failures were corrected in `1.8.8` and later.
25-
- *Note:* Arduino IDE `2.X.Y` is not supported at this time [issue 1477](https://github.com/microsoft/vscode-arduino/issues/1477)
26-
27-
### Arduino CLI
28-
The Arduino CLI can be downloaded from the repository's [release page](https://github.com/arduino/arduino-cli/releases/tag/0.13.0)
29-
- The extension has only been tested with v0.13.0.
30-
- If you use the CLI you will have to set `arduino.path` since the CLI does not have a default path.
42+
- *Note:* Arduino IDE `2.X.Y` is not supported and there are no plans for support in the future ([issue 1477](https://github.com/microsoft/vscode-arduino/issues/1477)).
3143

3244
## Installation
3345
Open VS Code and press <kbd>F1</kbd> or <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> *or* <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> to open command palette, select **Install Extension** and type `vscode-arduino`.
@@ -71,9 +83,9 @@ This extension provides several commands in the Command Palette (<kbd>F1</kbd> o
7183
## Options
7284
| Option | Description |
7385
| --- | --- |
74-
| `arduino.useArduinoCli` | Whether to use the Arduino CLI (`true`) or the Arduino IDE (`false`) -- defaults to `false`. If using `true`, make sure to set the `arduino.path` and `arduino.commandPath` values correctly. |
75-
| `arduino.path` | Path to the Arduino installation. You can use a custom version of Arduino by modifying this setting to include the full path. Example: `C:\\Program Files\\Arduino` for Windows, `/Applications` for Mac, `/home/<username>/Downloads/arduino-1.8.1` for Linux. (Requires a restart after change). The default value is automatically detected from your Arduino IDE installation path. To use the Arduino CLI, use the path that contains the `arduino-cli` executable (e.g. `/usr/local/bin`). |
76-
| `arduino.commandPath` | Path to an executable (or script) relative to `arduino.path`. The default value is `arduino_debug.exe` for Windows, `Contents/MacOS/Arduino` for Mac and `arduino` for Linux, You also can use a custom launch script to run Arduino by modifying this setting. (Requires a restart after change) Example: `run-arduino.bat` for Windows, `Contents/MacOS/run-arduino.sh` for Mac and `bin/run-arduino.sh` for Linux. To use the Arduino CLI, use `arduino-cli`. |
86+
| `arduino.useArduinoCli` | Whether to use the Arduino CLI (`true`) or the legacy Arduino IDE (`false`) -- defaults to `false`. If using `true`, either leave the `arduino.path` and `arduino.commandPath` values unset to use the bundled version of Arduino CLI, or point them at a custom version of Arduino CLI. Note that a future version of the extension will change this default to `true` and remove support for legacy Arduino IDE. |
87+
| `arduino.path` | Path to the Arduino installation. You can use a custom version of Arduino by modifying this setting to include the full path. Example: `C:\\Program Files\\Arduino` for Windows, `/Applications` for Mac, `/home/<username>/Downloads/arduino-1.8.1` for Linux. (Requires a restart after change). The default value is automatically detected from your legacy Arduino IDE installation path. To use the Arduino CLI, use the path that contains the `arduino-cli` executable (e.g. `/usr/local/bin`), or leave it unset to use the bundled version of Arduino CLI. |
88+
| `arduino.commandPath` | Path to an executable (or script) relative to `arduino.path`. The default value is `arduino_debug.exe` for Windows, `Contents/MacOS/Arduino` for Mac and `arduino` for Linux, You also can use a custom launch script to run Arduino by modifying this setting. (Requires a restart after change) Example: `run-arduino.bat` for Windows, `Contents/MacOS/run-arduino.sh` for Mac and `bin/run-arduino.sh` for Linux. To use the bundled version of Arduino CLI, leave this option unset. To use a custom version of Arduino CLI, use `arduino-cli`. |
7789
| `arduino.additionalUrls` | Additional Boards Manager URLs for 3rd party packages as a string array. The default value is empty. |
7890
| `arduino.logLevel` | CLI output log level. Could be info or verbose. The default value is `"info"`. |
7991
| `arduino.clearOutputOnBuild` | Clear the output logs before uploading or verifying. Default value is `false`. |
@@ -91,8 +103,7 @@ The following Visual Studio Code settings are available for the Arduino extensio
91103

92104
```json
93105
{
94-
"arduino.path": "C:/Program Files (x86)/Arduino",
95-
"arduino.commandPath": "arduino_debug.exe",
106+
"arduino.useArduinoCli": true,
96107
"arduino.logLevel": "info",
97108
"arduino.allowPDEFiletype": false,
98109
"arduino.enableUSBDetection": true,
@@ -105,7 +116,6 @@ The following Visual Studio Code settings are available for the Arduino extensio
105116
"arduino.defaultBaudRate": 115200
106117
}
107118
```
108-
*Note:* You only need to set `arduino.path` in Visual Studio Code settings, other options are not required.
109119

110120
The following settings are as per sketch settings of the Arduino extension. You can find them in
111121
`.vscode/arduino.json` under the workspace.

build/assets.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "0.30.0",
3+
"assets": {
4+
"arduino-cli_0.30.0_Linux_64bit.tar.gz": {
5+
"hash": "f6b1cddf3459b1b6ca9dafe36315c2fa1f6f77386ab3795bbad6a117cbe4230b",
6+
"platforms": ["linux-x64"]
7+
},
8+
"arduino-cli_0.30.0_Linux_ARM64.tar.gz": {
9+
"hash": "20d2d036a5af4586b5a046f65d926ed012f7fd85469b484a5fc57ef9ef72fb4b",
10+
"platforms": ["linux-arm64"]
11+
},
12+
"arduino-cli_0.30.0_Linux_ARMv7.tar.gz": {
13+
"hash": "1d873f3cb2b939b2df5a7d25e998bded9a4f0c8ac1226d1d5f9abc2bd95a66c3",
14+
"platforms": ["linux-armhf"]
15+
},
16+
"arduino-cli_0.30.0_macOS_64bit.tar.gz": {
17+
"hash": "ece83e0bd15813e728d07ce584388a278d62e54529deb84ad07d1521bfe74748",
18+
"platforms": ["darwin-x64"]
19+
},
20+
"arduino-cli_0.30.0_macOS_ARM64.tar.gz": {
21+
"hash": "e6c1a35df995ecb464ffa85fe8a96b82bd06135ea5ae961cb34d9c9e99e6c2fa",
22+
"platforms": ["darwin-arm64"]
23+
},
24+
"arduino-cli_0.30.0_Windows_32bit.zip": {
25+
"hash": "cccd4b90524581783cf78a3e4942a5c6bf7508a2a5ec4e008bb9c43f1cdb5dbe",
26+
"platforms": ["win32-ia32"]
27+
},
28+
"arduino-cli_0.30.0_Windows_64bit.zip": {
29+
"hash": "1808d288382f16594ad73f4797303058b2074b1b375fbb19fca0978033a633af",
30+
"platforms": ["win32-x64"]
31+
}
32+
}
33+
}

build/downloadAssets.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
// This script downloads and verifies platform-specific arduino-cli binaries
5+
// from GitHub releases. The release is specified by the "version" field in
6+
// assets.json.
7+
8+
const { execSync } = require("child_process");
9+
const { createHash } = require("crypto");
10+
const { readFileSync, mkdirSync, rmSync, renameSync } = require("fs");
11+
const { resolve } = require("path");
12+
13+
function run(command) {
14+
console.log(command);
15+
execSync(command);
16+
}
17+
18+
const config = require('./assets.json');
19+
20+
for (const asset in config.assets) {
21+
if (Object.hasOwnProperty.call(config.assets, asset)) {
22+
const platforms = config.assets[asset].platforms;
23+
const hash = config.assets[asset].hash;
24+
for (const platform of platforms) {
25+
const directory = resolve(__dirname, "..", "assets", "platform", platform);
26+
const destination = resolve(directory, asset);
27+
28+
// Download the asset.
29+
run([
30+
"curl",
31+
`https://github.com/arduino/arduino-cli/releases/download/${config.version}/${asset}`,
32+
"--location",
33+
`--output-dir ${directory}`,
34+
`--remote-name`,
35+
"--silent",
36+
"--show-error",
37+
].join(" "));
38+
39+
// Verify the hash.
40+
const actualHash = createHash("sha256")
41+
.update(readFileSync(destination))
42+
.digest("hex");
43+
if (actualHash !== hash) {
44+
throw new Error(
45+
`Hash mismatch for ${asset} on ${platform}. Expected ${hash} but got ${actualHash}.`
46+
);
47+
}
48+
49+
// Extract to an "arduino-cli" directory.
50+
const extractDirectory = resolve(directory, "arduino-cli");
51+
mkdirSync(extractDirectory, { recursive: true });
52+
// tar on Linux doesn't understand zip files.
53+
if (asset.endsWith(".zip") && process.platform === 'linux') {
54+
run(`unzip ${destination} -d ${extractDirectory}`);
55+
} else {
56+
run(`tar -xf ${destination} -C ${extractDirectory}`);
57+
}
58+
59+
// Remove the downloaded archive. We don't need to ship it.
60+
rmSync(destination);
61+
62+
// VSIX signing will silently strip any extensionless files. Artificially
63+
// add a ".app" extension to extensionless executables.
64+
const executable = resolve(extractDirectory, "arduino-cli");
65+
try {
66+
renameSync(executable, `${executable}.app`);
67+
} catch {
68+
// The file might not exist. This is expected for Windows.
69+
}
70+
}
71+
}
72+
}

cgmanifest.json

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"$schema": "https://json.schemastore.org/component-detection-manifest.json",
3+
"version": 1,
4+
"registrations": [
5+
{
6+
"component": {
7+
"type": "other",
8+
"other": {
9+
"name": "arduino-cli (Linux x64)",
10+
"version": "0.30.0",
11+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_Linux_64bit.tar.gz",
12+
}
13+
}
14+
},
15+
{
16+
"component": {
17+
"type": "other",
18+
"other": {
19+
"name": "arduino-cli (Linux ARM64)",
20+
"version": "0.30.0",
21+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_Linux_ARM64.tar.gz",
22+
}
23+
}
24+
},
25+
{
26+
"component": {
27+
"type": "other",
28+
"other": {
29+
"name": "arduino-cli (Linux ARMv7)",
30+
"version": "0.30.0",
31+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_Linux_ARMv7.tar.gz",
32+
}
33+
}
34+
},
35+
{
36+
"component": {
37+
"type": "other",
38+
"other": {
39+
"name": "arduino-cli (macOS x64)",
40+
"version": "0.30.0",
41+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_macOS_64bit.tar.gz",
42+
}
43+
}
44+
},
45+
{
46+
"component": {
47+
"type": "other",
48+
"other": {
49+
"name": "arduino-cli (macOS ARM64)",
50+
"version": "0.30.0",
51+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_macOS_ARM64.tar.gz",
52+
}
53+
}
54+
},
55+
{
56+
"component": {
57+
"type": "other",
58+
"other": {
59+
"name": "arduino-cli (Windows x86)",
60+
"version": "0.30.0",
61+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_Windows_32bit.zip",
62+
}
63+
}
64+
},
65+
{
66+
"component": {
67+
"type": "other",
68+
"other": {
69+
"name": "arduino-cli (Windows x64)",
70+
"version": "0.30.0",
71+
"downloadUrl": "https://github.com/arduino/arduino-cli/releases/download/0.30.0/arduino-cli_0.30.0_Windows_64bit.zip",
72+
}
73+
}
74+
}
75+
]
76+
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@
473473
"arduino.useArduinoCli": {
474474
"type": "boolean",
475475
"default": false,
476-
"markdownDescription": "Use Arduino CLI installed instead of Arduino IDE. `#arduino.path#` must be set, as there is no default path for 'arduino-cli'. (Requires a restart after change)"
476+
"markdownDescription": "Use Arduino CLI installed instead of the legacy Arduino IDE. If `#arduino.path#` and `#arduino.commandPath#` are not set, the extension will use a version of Arduino CLI bundled with the extension. (Requires a restart after change)"
477477
},
478478
"arduino.path": {
479479
"type": "string",
@@ -596,7 +596,7 @@
596596
},
597597
"scripts": {
598598
"build": "gulp build --mode=production",
599-
"postinstall": "cd ./src/views && npm install",
599+
"postinstall": "node ./build/downloadAssets.js && cd ./src/views && npm install",
600600
"test": "gulp test"
601601
},
602602
"extensionDependencies": [

0 commit comments

Comments
 (0)