@@ -62,6 +62,9 @@ pub struct CompileParameters {
62
62
) ]
63
63
pub output_bit_code : bool ,
64
64
65
+ #[ structopt( short = "c" , help = "Do not link after compiling object code" ) ]
66
+ pub skip_linking : bool ,
67
+
65
68
#[ structopt(
66
69
long,
67
70
name = "target-triple" ,
@@ -85,6 +88,17 @@ pub struct CompileParameters {
85
88
) ]
86
89
// having a vec allows bash to resolve *.st itself
87
90
pub input : Vec < String > ,
91
+
92
+ #[ structopt(
93
+ name = "library-path" ,
94
+ long,
95
+ short = "L" ,
96
+ help = "Search path for libraries, used for linking"
97
+ ) ]
98
+ pub library_pathes : Vec < String > ,
99
+
100
+ #[ structopt( name = "library" , long, short = "l" , help = "Library name to link" ) ]
101
+ pub libraries : Vec < String > ,
88
102
}
89
103
90
104
fn parse_encoding ( encoding : & str ) -> Result < & ' static Encoding , String > {
@@ -122,20 +136,21 @@ impl CompileParameters {
122
136
123
137
/// return the output filename with the correct ending
124
138
pub fn output_name ( & self ) -> Option < String > {
139
+ let out_format = self . output_format_or_default ( ) ;
125
140
if let Some ( n) = & self . output {
126
141
Some ( n. to_string ( ) )
127
142
} else {
128
- let ending = match self . output_format_or_default ( ) {
129
- FormatOption :: Bitcode => "bc" ,
130
- FormatOption :: Static => "o" ,
131
- FormatOption :: Shared => "so " ,
132
- FormatOption :: PIC => "so" ,
133
- FormatOption :: IR => "ir" ,
143
+ let ending = match out_format {
144
+ FormatOption :: Bitcode => ". bc" ,
145
+ FormatOption :: Static if self . skip_linking => ". o" ,
146
+ FormatOption :: Static => "" ,
147
+ FormatOption :: Shared | FormatOption :: PIC => ". so" ,
148
+ FormatOption :: IR => ". ir" ,
134
149
} ;
135
150
136
151
let output_name = self . input . first ( ) . unwrap ( ) ;
137
152
let basename = Path :: new ( output_name) . file_stem ( ) ?. to_str ( ) ?;
138
- Some ( format ! ( "{}. {}" , basename, ending) )
153
+ Some ( format ! ( "{}{}" , basename, ending) )
139
154
}
140
155
}
141
156
}
@@ -234,13 +249,17 @@ mod cli_tests {
234
249
assert_eq ! ( parameters. output_name( ) . unwrap( ) , "charlie.so" . to_string( ) ) ;
235
250
236
251
let parameters =
237
- CompileParameters :: parse ( vec_of_strings ! ( "examples/test/delta.st" , "--static" ) )
252
+ CompileParameters :: parse ( vec_of_strings ! ( "examples/test/delta.st" , "--static" , "-c" ) )
238
253
. unwrap ( ) ;
239
254
assert_eq ! ( parameters. output_name( ) . unwrap( ) , "delta.o" . to_string( ) ) ;
240
255
241
256
let parameters =
242
257
CompileParameters :: parse ( vec_of_strings ! ( "examples/test/echo" , "--bc" ) ) . unwrap ( ) ;
243
258
assert_eq ! ( parameters. output_name( ) . unwrap( ) , "echo.bc" . to_string( ) ) ;
259
+
260
+ let parameters =
261
+ CompileParameters :: parse ( vec_of_strings ! ( "examples/test/echo.st" ) ) . unwrap ( ) ;
262
+ assert_eq ! ( parameters. output_name( ) . unwrap( ) , "echo" . to_string( ) ) ;
244
263
}
245
264
246
265
#[ test]
@@ -338,6 +357,35 @@ mod cli_tests {
338
357
assert_eq ! ( parameters. output_shared_obj, false ) ;
339
358
}
340
359
360
+ #[ test]
361
+ fn library_path_added ( ) {
362
+ let parameters = CompileParameters :: parse ( vec_of_strings ! (
363
+ "input.st" ,
364
+ "--library-path" ,
365
+ "xxx" ,
366
+ "-L" ,
367
+ "test" ,
368
+ "-L." ,
369
+ "-L/tmp"
370
+ ) )
371
+ . unwrap ( ) ;
372
+ assert_eq ! ( parameters. library_pathes, vec![ "xxx" , "test" , "." , "/tmp" ] ) ;
373
+ }
374
+
375
+ #[ test]
376
+ fn libraries_added ( ) {
377
+ let parameters = CompileParameters :: parse ( vec_of_strings ! (
378
+ "input.st" ,
379
+ "-l" ,
380
+ "test" ,
381
+ "-lc" ,
382
+ "--library" ,
383
+ "xx"
384
+ ) )
385
+ . unwrap ( ) ;
386
+ assert_eq ! ( parameters. libraries, vec![ "test" , "c" , "xx" ] ) ;
387
+ }
388
+
341
389
#[ test]
342
390
fn cli_supports_version ( ) {
343
391
match CompileParameters :: parse ( vec_of_strings ! ( "input.st" , "--version" ) ) {
0 commit comments