33use super :: ast;
44use super :: flatten;
55use super :: make;
6+ use super :: emitter_common;
67use super :: name:: Name ;
78use super :: parser:: { self , emit_error} ;
89use super :: project:: Project ;
10+ use super :: project;
911use std:: collections:: HashSet ;
1012use std:: fs;
1113use std:: io:: Write ;
@@ -21,12 +23,14 @@ pub struct Emitter {
2123}
2224
2325pub fn outname ( _project : & Project , stage : & make:: Stage , module : & flatten:: Module ) -> String {
24- format ! ( "target/rust/{}.rs" , module. name. 0 [ 1 ..] . join( "_" ) )
26+ let td = project:: target_dir ( ) ;
27+ td. join ( "rust" ) . join ( format ! ( "{}.rs" , module. name. 0 [ 1 ..] . join( "_" ) ) ) . to_string_lossy ( ) . to_string ( )
2528}
2629
2730pub fn make_module ( make : & super :: make:: Make ) {
28- let pdir_ = format ! ( "target/rust/{}/" , make. artifact. name) ;
29- let pdir = std:: path:: Path :: new ( & pdir_) ;
31+ let td = project:: target_dir ( ) ;
32+ let pdir_ = td. join ( "rust" ) . join ( & make. artifact . name ) ;
33+ let pdir = std:: path:: Path :: new ( & pdir_) ;
3034 std:: fs:: create_dir_all ( & pdir) . unwrap ( ) ;
3135
3236
@@ -39,7 +43,14 @@ pub fn make_module(make: &super::make::Make) {
3943 write ! ( f, " cc::Build::new()\n " ) . unwrap ( ) ;
4044
4145 for step in & make. steps {
42- write ! ( f, " .file(\" ../../../{}\" )\n " , step. source. to_string_lossy( ) ) . unwrap ( ) ;
46+ write ! ( f, " .file(\" {}\" )\n " ,
47+ emitter_common:: path_rel( & pdir, & step. source) . to_string_lossy( ) . to_string( )
48+ ) . unwrap ( ) ;
49+ }
50+ for flag in & make. cincludes {
51+ write ! ( f, " .include(\" {}\" )\n " ,
52+ emitter_common:: path_rel( & pdir, flag) . to_string_lossy( ) . to_string( )
53+ ) . unwrap ( ) ;
4354 }
4455 write ! ( f, " .compile(\" {}\" );\n " , make. artifact. name) . unwrap ( ) ;
4556 write ! ( f, "}}\n " ) . unwrap ( ) ;
@@ -365,6 +376,7 @@ impl Emitter {
365376 _ => unreachable ! ( ) ,
366377 } ;
367378 let shortname = Name :: from ( & ast. name ) . 0 . last ( ) . unwrap ( ) . clone ( ) ;
379+ write ! ( self . f, "#[derive(Clone)]\n " ) . unwrap ( ) ;
368380 write ! ( self . f, "#[repr(C)]\n " ) . unwrap ( ) ;
369381 write ! ( self . f, "pub enum {} {{\n " , shortname) . unwrap ( ) ;
370382 for ( name, literal) in names {
@@ -580,7 +592,7 @@ impl {name} {{
580592 }
581593 }
582594
583- write ! ( self . f, "\n \n #[repr(C)]\n pub struct {} {{\n " , shortname) . unwrap ( ) ;
595+ write ! ( self . f, "\n #[derive(Clone)] \n #[repr(C)]\n pub struct {} {{\n " , shortname) . unwrap ( ) ;
584596 for i in 0 ..fields. len ( ) {
585597 let field = & fields[ i] ;
586598
@@ -666,7 +678,7 @@ impl {name} {{
666678
667679 let shortname = Name :: from ( & ast. name ) . 0 . last ( ) . unwrap ( ) . clone ( ) ;
668680
669- write ! ( self . f, "#[repr(C)]\n pub struct {sn} {{\n pub ctx: *mut std::ffi::c_void,\n " ,
681+ write ! ( self . f, "#[derive(Clone)] \n #[ repr(C)]\n pub struct {sn} {{\n pub ctx: *mut std::ffi::c_void,\n " ,
670682 sn = shortname,
671683 ) . unwrap ( ) ;
672684
0 commit comments