@@ -156,8 +156,17 @@ fn generate_lib_rs(
156
156
is_tonic : bool ,
157
157
direct_dep_crate_names : Vec < String > ,
158
158
additional_content : String ,
159
+ is_no_std : bool ,
159
160
) -> String {
160
- let mut contents = vec ! [ "// @generated" . to_string( ) , "" . to_string( ) ] ;
161
+ let mut contents = vec ! [
162
+ if is_no_std {
163
+ "#![no_std]" . to_string( )
164
+ } else {
165
+ "" . to_string( )
166
+ } ,
167
+ "// @generated" . to_string( ) ,
168
+ "" . to_string( ) ,
169
+ ] ;
161
170
for crate_name in direct_dep_crate_names {
162
171
contents. push ( format ! ( "pub use {crate_name};" ) ) ;
163
172
}
@@ -457,6 +466,9 @@ struct Args {
457
466
/// Whether to generate tonic code.
458
467
is_tonic : bool ,
459
468
469
+ // Whether to put a no_std tag into the generated code.
470
+ is_no_std : bool ,
471
+
460
472
/// Extra arguments to pass to protoc.
461
473
extra_args : Vec < String > ,
462
474
}
@@ -479,6 +491,7 @@ impl Args {
479
491
let mut tonic_or_prost_opts = Vec :: new ( ) ;
480
492
let mut direct_dep_crate_names = Vec :: new ( ) ;
481
493
let mut is_tonic = false ;
494
+ let mut is_no_std = false ;
482
495
483
496
let mut extra_args = Vec :: new ( ) ;
484
497
@@ -501,6 +514,10 @@ impl Args {
501
514
is_tonic = true ;
502
515
return ;
503
516
}
517
+ if arg == "--is_no_std" {
518
+ is_no_std = true ;
519
+ return ;
520
+ }
504
521
505
522
if !arg. contains ( '=' ) {
506
523
extra_args. push ( arg) ;
@@ -644,6 +661,7 @@ impl Args {
644
661
proto_paths,
645
662
direct_dep_crate_names,
646
663
is_tonic,
664
+ is_no_std,
647
665
label : label. unwrap ( ) ,
648
666
extra_args,
649
667
} )
@@ -748,6 +766,7 @@ fn main() {
748
766
proto_paths,
749
767
direct_dep_crate_names,
750
768
is_tonic,
769
+ is_no_std,
751
770
extra_args,
752
771
} = Args :: parse ( ) . expect ( "Failed to parse args" ) ;
753
772
@@ -917,6 +936,7 @@ fn main() {
917
936
is_tonic,
918
937
direct_dep_crate_names,
919
938
additional_content,
939
+ is_no_std,
920
940
) ,
921
941
)
922
942
. expect ( "Failed to write file." ) ;
@@ -972,7 +992,6 @@ fn escape_keyword(s: String) -> String {
972
992
973
993
#[ cfg( test) ]
974
994
mod test {
975
-
976
995
use super :: * ;
977
996
978
997
use prost_types:: { FieldDescriptorProto , ServiceDescriptorProto } ;
0 commit comments