@@ -6,16 +6,24 @@ import {
6
6
Code ,
7
7
Runtime ,
8
8
} from 'aws-cdk-lib/aws-lambda' ;
9
- import { dirname } from 'path' ;
9
+ import * as fs from 'fs' ;
10
+ import * as path from 'path' ;
11
+ import { build } from './build' ;
10
12
11
13
/**
12
14
* Options for bundling
13
15
*/
14
16
export interface BundlingProps extends DockerRunOptions {
15
17
/**
16
- * CDK output (staging) directory for the lambda function
18
+ * Path to the directory that contains the project to be built; i.e., the
19
+ * directory containing `Cargo.toml`.
17
20
*/
18
- readonly handlerDir : string ;
21
+ readonly entry : string ;
22
+
23
+ /**
24
+ * Executable name.
25
+ */
26
+ readonly bin ?: string ;
19
27
20
28
/**
21
29
* The runtime of the lambda function
@@ -26,6 +34,11 @@ export interface BundlingProps extends DockerRunOptions {
26
34
* The system architecture of the lambda function
27
35
*/
28
36
readonly architecture : Architecture ;
37
+
38
+ /**
39
+ * Target of `cargo build`.
40
+ */
41
+ readonly target : string ;
29
42
}
30
43
31
44
/**
@@ -35,7 +48,7 @@ export class Bundling implements cdk.BundlingOptions {
35
48
public static bundle ( options : BundlingProps ) : AssetCode {
36
49
const bundling = new Bundling ( options ) ;
37
50
38
- return Code . fromAsset ( dirname ( options . handlerDir ) , {
51
+ return Code . fromAsset ( options . entry , {
39
52
assetHashType : cdk . AssetHashType . OUTPUT ,
40
53
bundling : {
41
54
image : bundling . image ,
@@ -54,9 +67,22 @@ export class Bundling implements cdk.BundlingOptions {
54
67
this . image = cdk . DockerImage . fromRegistry ( 'dummy' ) ; // Do not build if we don't need to
55
68
56
69
this . local = {
57
- tryBundle ( outputDir : string ) {
58
- // TODO
59
- console . log ( `BUNDLING...: ${ outputDir } ` ) ;
70
+ tryBundle ( outDir : string ) {
71
+ console . log ( `BUNDLING...: ${ outDir } ` ) ;
72
+ build ( {
73
+ entry : props . entry ,
74
+ bin : props . bin ,
75
+ target : props . target ,
76
+ outDir,
77
+ } ) ;
78
+ // moves <bin>/bootstrap → ./bootstrap
79
+ // and cleans up the empty folder
80
+ const binDir = path . join ( outDir , props . bin ! ) ;
81
+ fs . renameSync (
82
+ path . join ( binDir , 'bootstrap' ) ,
83
+ path . join ( outDir , 'bootstrap' )
84
+ ) ;
85
+ fs . rmdirSync ( binDir ) ;
60
86
61
87
return true ;
62
88
} ,
0 commit comments