1
1
use crate :: config:: {
2
- AnchorPackage , BootstrapMode , BuildConfig , Config , ConfigOverride , Manifest , ProgramDeployment ,
3
- ProgramWorkspace , ScriptsConfig , TestValidator , WithPath , SHUTDOWN_WAIT , STARTUP_WAIT ,
2
+ AnchorPackage , BootstrapMode , BuildConfig , Config , ConfigOverride , Manifest , ProgramArch ,
3
+ ProgramDeployment , ProgramWorkspace , ScriptsConfig , TestValidator , WithPath , SHUTDOWN_WAIT ,
4
+ STARTUP_WAIT ,
4
5
} ;
5
6
use anchor_client:: Cluster ;
6
7
use anchor_lang:: idl:: { IdlAccount , IdlInstruction , ERASED_AUTHORITY } ;
@@ -110,6 +111,9 @@ pub enum Command {
110
111
/// Suppress doc strings in IDL output
111
112
#[ clap( long) ]
112
113
no_docs : bool ,
114
+ /// Architecture to use when building the program
115
+ #[ clap( value_enum, long, default_value = "bpf" ) ]
116
+ arch : ProgramArch ,
113
117
} ,
114
118
/// Expands macros (wrapper around cargo expand)
115
119
///
@@ -144,6 +148,9 @@ pub enum Command {
144
148
/// verifiable builds. Only works for debian-based images.
145
149
#[ clap( value_enum, short, long, default_value = "none" ) ]
146
150
bootstrap : BootstrapMode ,
151
+ /// Architecture to use when building the program
152
+ #[ clap( value_enum, long, default_value = "bpf" ) ]
153
+ arch : ProgramArch ,
147
154
/// Environment variables to pass into the docker container
148
155
#[ clap( short, long, required = false ) ]
149
156
env : Vec < String > ,
@@ -174,6 +181,9 @@ pub enum Command {
174
181
/// use this to save time when running test and the program code is not altered.
175
182
#[ clap( long) ]
176
183
skip_build : bool ,
184
+ /// Architecture to use when building the program
185
+ #[ clap( value_enum, long, default_value = "bpf" ) ]
186
+ arch : ProgramArch ,
177
187
/// Flag to keep the local validator running after tests
178
188
/// to be able to check the transactions.
179
189
#[ clap( long) ]
@@ -260,6 +270,9 @@ pub enum Command {
260
270
/// use this to save time when publishing the program
261
271
#[ clap( long) ]
262
272
skip_build : bool ,
273
+ /// Architecture to use when building the program
274
+ #[ clap( value_enum, long, default_value = "bpf" ) ]
275
+ arch : ProgramArch ,
263
276
} ,
264
277
/// Keypair commands.
265
278
Keys {
@@ -280,6 +293,9 @@ pub enum Command {
280
293
/// no "CHECK" comments where normally required
281
294
#[ clap( long) ]
282
295
skip_lint : bool ,
296
+ /// Architecture to use when building the program
297
+ #[ clap( value_enum, long, default_value = "bpf" ) ]
298
+ arch : ProgramArch ,
283
299
/// Environment variables to pass into the docker container
284
300
#[ clap( short, long, required = false ) ]
285
301
env : Vec < String > ,
@@ -412,6 +428,7 @@ pub fn entry(opts: Opts) -> Result<()> {
412
428
env,
413
429
skip_lint,
414
430
no_docs,
431
+ arch,
415
432
} => build (
416
433
& opts. cfg_override ,
417
434
idl,
@@ -427,6 +444,7 @@ pub fn entry(opts: Opts) -> Result<()> {
427
444
env,
428
445
cargo_args,
429
446
no_docs,
447
+ arch,
430
448
) ,
431
449
Command :: Verify {
432
450
program_id,
@@ -437,6 +455,7 @@ pub fn entry(opts: Opts) -> Result<()> {
437
455
env,
438
456
cargo_args,
439
457
skip_build,
458
+ arch,
440
459
} => verify (
441
460
& opts. cfg_override ,
442
461
program_id,
@@ -447,6 +466,7 @@ pub fn entry(opts: Opts) -> Result<()> {
447
466
env,
448
467
cargo_args,
449
468
skip_build,
469
+ arch,
450
470
) ,
451
471
Command :: Clean => clean ( & opts. cfg_override ) ,
452
472
Command :: Deploy {
@@ -473,6 +493,7 @@ pub fn entry(opts: Opts) -> Result<()> {
473
493
env,
474
494
cargo_args,
475
495
skip_lint,
496
+ arch,
476
497
} => test (
477
498
& opts. cfg_override ,
478
499
skip_deploy,
@@ -484,6 +505,7 @@ pub fn entry(opts: Opts) -> Result<()> {
484
505
args,
485
506
env,
486
507
cargo_args,
508
+ arch,
487
509
) ,
488
510
#[ cfg( feature = "dev" ) ]
489
511
Command :: Airdrop { .. } => airdrop ( & opts. cfg_override ) ,
@@ -499,21 +521,31 @@ pub fn entry(opts: Opts) -> Result<()> {
499
521
env,
500
522
cargo_args,
501
523
skip_build,
502
- } => publish ( & opts. cfg_override , program, env, cargo_args, skip_build) ,
524
+ arch,
525
+ } => publish (
526
+ & opts. cfg_override ,
527
+ program,
528
+ env,
529
+ cargo_args,
530
+ skip_build,
531
+ arch,
532
+ ) ,
503
533
Command :: Keys { subcmd } => keys ( & opts. cfg_override , subcmd) ,
504
534
Command :: Localnet {
505
535
skip_build,
506
536
skip_deploy,
507
537
skip_lint,
508
538
env,
509
539
cargo_args,
540
+ arch,
510
541
} => localnet (
511
542
& opts. cfg_override ,
512
543
skip_build,
513
544
skip_deploy,
514
545
skip_lint,
515
546
env,
516
547
cargo_args,
548
+ arch,
517
549
) ,
518
550
Command :: Account {
519
551
account_type,
@@ -825,6 +857,7 @@ pub fn build(
825
857
env_vars : Vec < String > ,
826
858
cargo_args : Vec < String > ,
827
859
no_docs : bool ,
860
+ arch : ProgramArch ,
828
861
) -> Result < ( ) > {
829
862
// Change to the workspace member directory, if needed.
830
863
if let Some ( program_name) = program_name. as_ref ( ) {
@@ -872,6 +905,7 @@ pub fn build(
872
905
cargo_args,
873
906
skip_lint,
874
907
no_docs,
908
+ arch,
875
909
) ?,
876
910
// If the Cargo.toml is at the root, build the entire workspace.
877
911
Some ( cargo) if cargo. path ( ) . parent ( ) == cfg. path ( ) . parent ( ) => build_all (
@@ -886,6 +920,7 @@ pub fn build(
886
920
cargo_args,
887
921
skip_lint,
888
922
no_docs,
923
+ arch,
889
924
) ?,
890
925
// Cargo.toml represents a single package. Build it.
891
926
Some ( cargo) => build_cwd (
@@ -900,6 +935,7 @@ pub fn build(
900
935
cargo_args,
901
936
skip_lint,
902
937
no_docs,
938
+ & arch,
903
939
) ?,
904
940
}
905
941
@@ -921,6 +957,7 @@ fn build_all(
921
957
cargo_args : Vec < String > ,
922
958
skip_lint : bool ,
923
959
no_docs : bool ,
960
+ arch : ProgramArch ,
924
961
) -> Result < ( ) > {
925
962
let cur_dir = std:: env:: current_dir ( ) ?;
926
963
let r = match cfg_path. parent ( ) {
@@ -939,6 +976,7 @@ fn build_all(
939
976
cargo_args. clone ( ) ,
940
977
skip_lint,
941
978
no_docs,
979
+ & arch,
942
980
) ?;
943
981
}
944
982
Ok ( ( ) )
@@ -962,13 +1000,14 @@ fn build_cwd(
962
1000
cargo_args : Vec < String > ,
963
1001
skip_lint : bool ,
964
1002
no_docs : bool ,
1003
+ arch : & ProgramArch ,
965
1004
) -> Result < ( ) > {
966
1005
match cargo_toml. parent ( ) {
967
1006
None => return Err ( anyhow ! ( "Unable to find parent" ) ) ,
968
1007
Some ( p) => std:: env:: set_current_dir ( p) ?,
969
1008
} ;
970
1009
match build_config. verifiable {
971
- false => _build_cwd ( cfg, idl_out, idl_ts_out, skip_lint, cargo_args) ,
1010
+ false => _build_cwd ( cfg, idl_out, idl_ts_out, skip_lint, arch , cargo_args) ,
972
1011
true => build_cwd_verifiable (
973
1012
cfg,
974
1013
cargo_toml,
@@ -979,6 +1018,7 @@ fn build_cwd(
979
1018
env_vars,
980
1019
cargo_args,
981
1020
no_docs,
1021
+ arch,
982
1022
) ,
983
1023
}
984
1024
}
@@ -996,6 +1036,7 @@ fn build_cwd_verifiable(
996
1036
env_vars : Vec < String > ,
997
1037
cargo_args : Vec < String > ,
998
1038
no_docs : bool ,
1039
+ arch : & ProgramArch ,
999
1040
) -> Result < ( ) > {
1000
1041
// Create output dirs.
1001
1042
let workspace_dir = cfg. path ( ) . parent ( ) . unwrap ( ) . canonicalize ( ) ?;
@@ -1018,6 +1059,7 @@ fn build_cwd_verifiable(
1018
1059
stderr,
1019
1060
env_vars,
1020
1061
cargo_args,
1062
+ arch,
1021
1063
) ;
1022
1064
1023
1065
match & result {
@@ -1066,6 +1108,7 @@ fn docker_build(
1066
1108
stderr : Option < File > ,
1067
1109
env_vars : Vec < String > ,
1068
1110
cargo_args : Vec < String > ,
1111
+ arch : & ProgramArch ,
1069
1112
) -> Result < ( ) > {
1070
1113
let binary_name = Manifest :: from_path ( & cargo_toml) ?. lib_name ( ) ?;
1071
1114
@@ -1120,6 +1163,7 @@ fn docker_build(
1120
1163
stderr,
1121
1164
env_vars,
1122
1165
cargo_args,
1166
+ arch,
1123
1167
)
1124
1168
} ) ;
1125
1169
@@ -1184,6 +1228,7 @@ fn docker_build_bpf(
1184
1228
stderr : Option < File > ,
1185
1229
env_vars : Vec < String > ,
1186
1230
cargo_args : Vec < String > ,
1231
+ arch : & ProgramArch ,
1187
1232
) -> Result < ( ) > {
1188
1233
let manifest_path =
1189
1234
pathdiff:: diff_paths ( cargo_toml. canonicalize ( ) ?, cfg_parent. canonicalize ( ) ?)
@@ -1194,6 +1239,8 @@ fn docker_build_bpf(
1194
1239
manifest_path. display( )
1195
1240
) ;
1196
1241
1242
+ let subcommand = arch. build_subcommand ( ) ;
1243
+
1197
1244
// Execute the build.
1198
1245
let exit = std:: process:: Command :: new ( "docker" )
1199
1246
. args ( [
@@ -1209,7 +1256,7 @@ fn docker_build_bpf(
1209
1256
. args ( [
1210
1257
container_name,
1211
1258
"cargo" ,
1212
- "build-bpf" ,
1259
+ subcommand ,
1213
1260
"--manifest-path" ,
1214
1261
& manifest_path. display ( ) . to_string ( ) ,
1215
1262
] )
@@ -1299,10 +1346,12 @@ fn _build_cwd(
1299
1346
idl_out : Option < PathBuf > ,
1300
1347
idl_ts_out : Option < PathBuf > ,
1301
1348
skip_lint : bool ,
1349
+ arch : & ProgramArch ,
1302
1350
cargo_args : Vec < String > ,
1303
1351
) -> Result < ( ) > {
1352
+ let subcommand = arch. build_subcommand ( ) ;
1304
1353
let exit = std:: process:: Command :: new ( "cargo" )
1305
- . arg ( "build-bpf" )
1354
+ . arg ( subcommand )
1306
1355
. args ( cargo_args)
1307
1356
. stdout ( Stdio :: inherit ( ) )
1308
1357
. stderr ( Stdio :: inherit ( ) )
@@ -1356,6 +1405,7 @@ fn verify(
1356
1405
env_vars : Vec < String > ,
1357
1406
cargo_args : Vec < String > ,
1358
1407
skip_build : bool ,
1408
+ arch : ProgramArch ,
1359
1409
) -> Result < ( ) > {
1360
1410
// Change to the workspace member directory, if needed.
1361
1411
if let Some ( program_name) = program_name. as_ref ( ) {
@@ -1384,6 +1434,7 @@ fn verify(
1384
1434
env_vars,
1385
1435
cargo_args,
1386
1436
false ,
1437
+ arch,
1387
1438
) ?;
1388
1439
}
1389
1440
std:: env:: set_current_dir ( cur_dir) ?;
@@ -2229,6 +2280,7 @@ fn test(
2229
2280
extra_args : Vec < String > ,
2230
2281
env_vars : Vec < String > ,
2231
2282
cargo_args : Vec < String > ,
2283
+ arch : ProgramArch ,
2232
2284
) -> Result < ( ) > {
2233
2285
let test_paths = tests_to_run
2234
2286
. iter ( )
@@ -2257,6 +2309,7 @@ fn test(
2257
2309
env_vars,
2258
2310
cargo_args,
2259
2311
false ,
2312
+ arch,
2260
2313
) ?;
2261
2314
}
2262
2315
@@ -3261,6 +3314,7 @@ fn publish(
3261
3314
env_vars : Vec < String > ,
3262
3315
cargo_args : Vec < String > ,
3263
3316
skip_build : bool ,
3317
+ arch : ProgramArch ,
3264
3318
) -> Result < ( ) > {
3265
3319
// Discover the various workspace configs.
3266
3320
let cfg = Config :: discover ( cfg_override) ?. expect ( "Not in workspace." ) ;
@@ -3392,6 +3446,7 @@ fn publish(
3392
3446
env_vars,
3393
3447
cargo_args,
3394
3448
true ,
3449
+ arch,
3395
3450
) ?;
3396
3451
}
3397
3452
@@ -3474,6 +3529,7 @@ fn localnet(
3474
3529
skip_lint : bool ,
3475
3530
env_vars : Vec < String > ,
3476
3531
cargo_args : Vec < String > ,
3532
+ arch : ProgramArch ,
3477
3533
) -> Result < ( ) > {
3478
3534
with_workspace ( cfg_override, |cfg| {
3479
3535
// Build if needed.
@@ -3493,6 +3549,7 @@ fn localnet(
3493
3549
env_vars,
3494
3550
cargo_args,
3495
3551
false ,
3552
+ arch,
3496
3553
) ?;
3497
3554
}
3498
3555
0 commit comments