-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathextension.ts
More file actions
98 lines (89 loc) · 2.74 KB
/
extension.ts
File metadata and controls
98 lines (89 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
LayerVersion,
LayerVersionOptions,
Architecture,
} from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import { Bundling } from './bundling';
import { getManifestPath } from './cargo';
import { BundlingOptions } from './types';
/**
* Properties for a RustExtension
*/
export interface RustExtensionProps extends LayerVersionOptions {
/**
* Bundling options
*
* @default - use default bundling options
*/
readonly bundling?: BundlingOptions;
/**
* The name of the binary to build, in case that's different than the package's name.
*/
readonly binaryName?: string;
/**
* Path to a directory containing your Cargo.toml file, or to your Cargo.toml directly.
*
* This will accept a directory path containing a `Cargo.toml` file (i.e. `path/to/package`), or a filepath to your
* `Cargo.toml` file (i.e. `path/to/Cargo.toml`). When the `gitRemote` option is provided,
* the `manifestPath` is relative to the root of the git repository.
*
* @default - check the current directory for a `Cargo.toml` file, and throws
* an error if the file doesn't exist.
*/
readonly manifestPath?: string;
/**
* The git remote URL to clone (e.g `https://github.com/your_user/your_repo`).
*
* This repository will be cloned to a temporary directory using `git`.
* The `git` command must be available in the PATH.
*/
readonly gitRemote?: string;
/**
* The git reference to checkout. This can be a branch, tag, or commit hash.
*
* If this option is not provided, `git clone` will run with the flag `--depth 1`.
*
* @default - the default branch, i.e. HEAD.
*/
readonly gitReference?: string;
/**
* Always clone the repository if using the `gitRemote` option, even if it has already been
* cloned to the temporary directory.
*
* @default - clones only if the repository and reference don't already exist in the
* temporary directory.
*/
readonly gitForceClone?: boolean;
/**
* The system architecture of the lambda extension
*
* @default - Architecture.X86_64
*/
readonly architecture?: Architecture;
}
/**
* A Lambda extension written in Rust
*/
export class RustExtension extends LayerVersion {
constructor(
scope: Construct,
resourceName: string,
props?: RustExtensionProps,
) {
const manifestPath = getManifestPath(props || {});
const bundling = props?.bundling ?? {};
const architecture = props?.architecture ?? Architecture.X86_64;
super(scope, resourceName, {
...props,
compatibleArchitectures: [architecture],
code: Bundling.bundle({
...bundling,
manifestPath,
binaryName: props?.binaryName,
lambdaExtension: true,
architecture,
}),
});
}
}