Skip to content

Commit 292e329

Browse files
authored
Merge pull request #939 from particle-iot/feature/sc-141302/implement-local-compile-in-particle-cli
Feature/sc 141302/implement local compile in particle cli
2 parents a144374 + 8d5b3b9 commit 292e329

25 files changed

Lines changed: 2330 additions & 31 deletions

‎README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,34 @@ You can specify a version with the `--target` argument.
103103
1. Connect your device via USB
104104
1. Run `particle update`.
105105

106+
### particle compile --compiler local
107+
108+
`particle compile` and `particle flash` build your project in the cloud by default. Pass
109+
`--compiler local` to build on your own machine with the same toolchain Particle Workbench
110+
uses: the Device OS source, the `gcc-arm` cross compiler, `buildtools` and the build scripts.
111+
112+
```sh
113+
$ particle compile argon my-project --compiler local
114+
$ particle flash --local --compiler local
115+
$ particle flash my-device my-project --compiler local
116+
```
117+
118+
* The toolchain is installed under `~/.particle/toolchains`, the directory Workbench uses, so
119+
anything Workbench already installed is reused and nothing is downloaded twice. The first
120+
local compile on a machine without Workbench downloads about 1 GB for one Device OS version;
121+
the CLI prints what it fetches and shows a progress bar.
122+
* `--target <version>` picks the Device OS version to build against, resolved from the public
123+
toolchain manifest. Without it the CLI uses the default version for the platform and prints it.
124+
On `flash --local` the same version is flashed to the device.
125+
* A local compile needs no login once the toolchain and the project's libraries are on disk.
126+
Libraries listed as `dependencies.*` in `project.properties` are copied into `lib/` the first
127+
time, which does need a login (`particle login`).
128+
* The project directory is built in place, as in Workbench: output goes to
129+
`<project>/target/<version>/<platform>/`, `.ino` files are preprocessed next to their
130+
sources, and `particle.include` / `particle.ignore` are not applied.
131+
* Supported on macOS, Linux and Windows on x64, and on Apple Silicon through Rosetta. Not
132+
available on Linux arm64, and project paths must not contain spaces.
133+
106134

107135
## Command Reference
108136

‎npm-shrinkwrap.json‎

Lines changed: 244 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"dependencies": {
4848
"@particle/device-constants": "^4.2.1",
4949
"@particle/softap-setup": "^4.1.2",
50+
"@particle/unpack-file": "^3.0.3",
5051
"archiver": "^7.0.1",
5152
"binary-version-reader": "^4.0.2",
5253
"chalk": "^2.4.2",

‎src/app/command-processor.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ function findAuthenticationError(err) {
4545

4646
async function runWithAuthMiddleware(options, argv){
4747
try {
48-
if (options.tokenExpiryThresholdMs) {
48+
// a command may decide per invocation whether it needs a fresh token,
49+
// e.g. `compile --compiler local` needs no login at all
50+
const thresholdMs = typeof options.tokenExpiryThresholdMs === 'function'
51+
? options.tokenExpiryThresholdMs(argv)
52+
: options.tokenExpiryThresholdMs;
53+
if (thresholdMs) {
4954
await verifyFreshTokenMiddleware({
50-
thresholdMs: options.tokenExpiryThresholdMs,
55+
thresholdMs,
5156
relogin: options.relogin
5257
});
5358
}

0 commit comments

Comments
 (0)