You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Checkin changes
* Checkin changes
* Change default target to `aarch64-unknown-linux-gnu`
* Build with `cargo zigbuild` instead of `cross`
* Remove logic to run `cargo check`, as it appears `zigbuild` already does this 👍
* Remove `checkCode` function as its not needed now
* Rename `cross` to `cargo-zigbuild`
* Update docs
* Update docs
* Update docs
* Fix letter
* Fix letter
* Update docs
* Update docs
* Update docs
* Update docs
* Update docs
* Update docs
* Update docs
* Update stuff
* Update CHANGELOG.md
* Update docs to mention how to install with `cross`
* Update links
* Bump version
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,17 @@ Possible header types:
11
11
12
12
## [Unreleased]
13
13
14
+
## v1.0.0 (2022-03-21)
15
+
16
+
## Breaking Changes
17
+
18
+
- Switch to use [`cargo-zigbuild`] -- instead of `cross` -- for building Rust code.
19
+
- Switch the default build architecture from `x86_64` to `arm64`; this package now uses **aarch64-unknown-linux-gnu** as the default build target for AWS Lambda functions, mainly as I've found this architecture to be slightly more performant in general use cases.
20
+
- Do not run `cargo check`, as it appears _cargo-zigbuild_ automatically runs this check.
21
+
- Update `cdk-examples/` with an example of how to conditionally run a code block (more than one statement) when a feature is enabled.
@@ -105,15 +120,26 @@ All other properties of `lambda.Function` are supported, see also the [AWS Lambd
105
120
106
121
When bundling the code, the `RustFunction` runs the following steps in order:
107
122
108
-
- First it runs `cargo check` to confirm that the Rust code can compile.
109
-
Note that this is an optional step, and [can be disabled](#settings) as mentioned below.
123
+
- First it runs `cargo zigbuild`, and passes in the `--release` and `--target` flags, so it compiles for a Lambda environment - which defaults to the **aarch64-unknown-linux-gnu** target, as mentioned above. Note that _zigbuild_ does initially confirm that the Rust code can compile.
110
124
111
-
- Next it calls `cross build`, and passes in the `--release` and `--target` flags, so it compiles for a Lambda environment - which defaults to the **x86_64-unknown-linux-gnu** target, as mentioned above.
112
-
113
-
- Finally, it copies the release app binary from the `target/` folder to a file named `bootstrap`, which the Lambda custom runtime environment looks for. It adds this new file under the _build directory_, which defaults to a `.build/` folder under the directory where `cdk` was invoked.
125
+
- Next, it copies the release app binary from the `target/` folder to a file named `bootstrap`, which the Lambda custom runtime environment looks for. It adds this new file under the _build directory_, which defaults to a `.build/` folder under the directory where `cdk` was invoked.
114
126
115
127
- The directory path to the executable is then passed in to `lambda.Code.fromAsset`, which creates a _zip file_ from the release binary asset.
116
128
129
+
## Use `cross` for Deployment
130
+
131
+
If you instead prefer to use [Docker] and [`cross`] for deployment, as outlined
132
+
in the [official AWS docs], you can install and use the [latest `v0.x`] release instead:
| `target` | Build target to cross-compile to. Defaults to the target for the **x86_64** architecture, `x86_64-unknown-linux-gnu`. |
289
+
| `target` | Build target to cross-compile to. Defaults to the target for the **arm64** architecture, `aarch64-unknown-linux-gnu`. |
264
290
| `directory` | Entry point where the project's main `Cargo.toml` is located. By default, the construct will use directory where `cdk` was invoked as the directory where Cargo files are located. |
265
291
|`buildDir`| Default Build directory, which defaults to a `.build` folder under the project's root directory. |
266
292
| `bin` | Executable name to pass to `--bin` |
267
293
| `package` | Workspace package name to pass to `--package` |
268
294
| `setupLogging` | Determines whether we want to set up [library logging](https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html) - i.e. set the `RUST_LOG` environment variable - for the lambda function.<br><br>The format defaults to `warn,module_name=debug`, which means that the default log level is `warn`, and the executable or library's log level is `debug`. |
269
295
||
270
296
|`features`| A list of features to activate when compiling Rust code. These must also be added to the `Cargo.toml` file. |
271
-
|`buildEnvironment`| Key-value pairs that are passed in at compile time, i.e. to `cargo build` or `cross build`. This differs from `environment`, which determines the environment variables which are set on the AWS Lambda functionitself.|
272
-
|`extraBuildArgs`| Additional arguments that are passed in at build time to both `cargo check` and `cross build`. For example, [`--all-features`]. |
297
+
|`buildEnvironment`| Key-value pairs that are passed in at compile time, i.e. to `cargo build` or `cargo zigbuild`. This differs from `environment`, which determines the environment variables which are set on the AWS Lambda functionitself.|
298
+
|`extraBuildArgs`| Additional arguments that are passed in at build time to `cargo zigbuild`. For example, [`--all-features`].|
273
299
274
300
## Settings
275
301
@@ -284,10 +310,9 @@ Below are some useful _global_ defaults which can be set for all Rust Lambda Fun
|`BUILD_INDIVIDUALLY`| Whether to build each executable individually, either via `--bin` or `--package`. |
287
-
|`RUN_CARGO_CHECK`| Whether to run `cargo check` to validate Rust code before building it with `cross`. Defaults to _true_. |
288
313
|`DEFAULT_LOG_LEVEL`| Log Level for non-module libraries. Note that this value is only used when `RustFunctionProps.setupLogging` is enabled. Defaults to `warn`. |
289
314
|`MODULE_LOG_LEVEL`| Log Level for a module (i.e. the executable). Note that this value is only used when `RustFunctionProps.setupLogging` is enabled. Defaults to `debug`. |
290
315
|`WORKSPACE_DIR`| Sets the root workspace directory. By default, the workspace directory is assumed to be the directory where `cdk` was invoked.<br><br>This directory should contain at the minimum a `Cargo.toml` file which defines the workspace members. |
291
316
|`FEATURES`| A list of features to activate when compiling Rust code. These must also be added to the `Cargo.toml` file. |
292
-
|`BUILD_ENVIRONMENT`| Key-value pairs that are passed in at compile time, i.e. to `cargo build` or `cross build`. This differs from `environment`, which determines the environment variables which are set on the AWS Lambda functionitself.|
293
-
|`EXTRA_BUILD_ARGS`| Additional arguments that are passed in at build time to both `cargo check` and `cross build`. For example, [`--all-features`]. |
317
+
|`BUILD_ENVIRONMENT`| Key-value pairs that are passed in at compile time, i.e. to `cargo build` or `cargo zigbuild`. This differs from `environment`, which determines the environment variables which are set on the AWS Lambda functionitself.|
318
+
|`EXTRA_BUILD_ARGS`| Additional arguments that are passed in at build time to both `cargo zigbuild`. For example, [`--all-features`].|
Copy file name to clipboardExpand all lines: cdk-examples/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,12 +17,12 @@ cd my-app
17
17
npm i
18
18
```
19
19
20
-
Next, ensure that you have [Docker](https://www.docker.com/get-started) running. You will need this to deploy with [`cross`](https://github.com/cross-rs/cross).
21
-
If you don't have `cross` installed, refer to the [Getting Started](https://github.com/rnag/rust.aws-cdk-lambda#getting-started) section in docs for more info on getting set up.
20
+
Next, ensure that you have [`cargo-zigbuild`](https://github.com/messense/cargo-zigbuild) installed. You will need this to cross-compile Rust code for deployment via `cdk`.
21
+
If you don't have `cargo-zigbuild` installed, refer to the [Getting Started](https://github.com/rnag/rust.aws-cdk-lambda#getting-started) section in docs for more info on getting set up.
22
22
23
23
Now you can deploy the app with `cdk`:
24
24
25
-
> Note: on an initial run, it may take a _really_ long time on the compilation step with `cross`. In my case, it sometimes took up to _12 minutes_! But don't worry, any subsequent deployments should be overall faster.
25
+
> Note: on an initial run, it may take a _really_ long time on the compilation step with `cargo-zigbuild`. In my case, it sometimes took up to _12 minutes_! But don't worry, any subsequent deployments should be overall faster.
0 commit comments