44#![ feature( box_patterns) ]
55#![ feature( let_else) ]
66#![ feature( iter_zip) ]
7+ // allow us to get file prefix
8+ #![ feature( path_file_prefix) ]
79extern crate rustc_ast;
810extern crate rustc_ast_pretty;
911extern crate rustc_attr;
@@ -19,13 +21,17 @@ extern crate rustc_session;
1921extern crate rustc_span;
2022
2123use dlopen;
24+ use itertools:: Itertools ;
2225use rustc_ast:: { visit, Impl , Item , ItemKind , VariantData } ;
2326use rustc_hir:: def:: { DefKind , Res } ;
2427use rustc_hir:: def_id:: DefId ;
2528use rustc_interface:: { interface:: Compiler , Config , Queries } ;
2629use rustc_middle:: hir:: exports:: Export ;
2730use rustc_middle:: ty:: Visibility ;
28- use rustc_session:: config:: { self , CrateType , ExternEntry , ExternLocation , Externs , Input } ;
31+ use rustc_session:: config:: {
32+ self , CrateType , ErrorOutputType , ExternEntry , ExternLocation , Externs , Input ,
33+ } ;
34+ use rustc_session:: search_paths:: SearchPath ;
2935use rustc_session:: utils:: CanonicalizedPath ;
3036use rustc_span:: source_map;
3137use std:: io:: Write ;
@@ -393,25 +399,36 @@ impl CompilerCallbacks {
393399 }
394400 fn analyze_metadata < ' tcx > ( & mut self , queries : & ' tcx Queries < ' tcx > ) {
395401 let mut class_map: HashMap < DefId , Class > = HashMap :: new ( ) ;
396- let crate_num = queries
402+ let krates = queries
397403 . expansion ( )
398404 . expect ( "Unable to get Expansion" )
399405 . peek_mut ( )
400406 . 1
401407 . borrow_mut ( )
402408 . access ( |resolver| {
403409 let c_store = resolver. cstore ( ) . clone ( ) ;
404- c_store
405- . crates_untracked ( )
406- . last ( )
407- . cloned ( )
408- . expect ( "Unable to get last element of crates." )
410+ c_store. crates_untracked ( )
409411 } ) ;
410412 queries
411413 . global_ctxt ( )
412414 . expect ( "Unable to get global ctxt" )
413415 . peek_mut ( )
414416 . enter ( |ctxt| {
417+ // since we are loading a package, input_path should be lib<crate_name>.rlib
418+ let crate_name = & self
419+ . source
420+ . input_path
421+ . file_prefix ( )
422+ . expect ( "Unable to get file prefix." )
423+ . to_str ( )
424+ . expect ( "Unable to cast OsStr to str" ) [ 3 ..] ;
425+ // find our krate
426+ let crate_num = krates
427+ . iter ( )
428+ . find_or_first ( |& & x| {
429+ ctxt. crate_name ( x) == rustc_span:: Symbol :: intern ( crate_name)
430+ } )
431+ . expect ( "unable to find crate" ) ;
415432 // parse public functions and structs
416433 for child in ctxt. item_children ( crate_num. as_def_id ( ) ) {
417434 let Export {
@@ -466,7 +483,7 @@ impl CompilerCallbacks {
466483 }
467484 }
468485 // after parsing all structs, parse tarit implementations.
469- for trait_impl in ctxt. all_trait_implementations ( crate_num) {
486+ for trait_impl in ctxt. all_trait_implementations ( * crate_num) {
470487 use rustc_middle:: ty:: fast_reject:: SimplifiedTypeGen :: AdtSimplifiedType ;
471488 if let Some ( AdtSimplifiedType ( def_id) ) = trait_impl. 1 {
472489 if let Some ( class) = class_map. get_mut ( & def_id) {
@@ -519,6 +536,19 @@ impl rustc_driver::Callbacks for CompilerCallbacks {
519536 }
520537
521538 config. opts . externs = Externs :: new ( externs) ;
539+ // we hardcode the dependency path for now.
540+ let dep_path = self
541+ . source
542+ . input_path
543+ . clone ( )
544+ . parent ( )
545+ . expect ( "Unable to get parent dir" )
546+ . join ( "deps" ) ;
547+ // println!("include dep: {}", dep_path.display());
548+ config. opts . search_paths . push ( SearchPath :: from_cli_opt (
549+ format ! ( "dependency={}" , dep_path. display( ) ) . as_str ( ) ,
550+ ErrorOutputType :: default ( ) ,
551+ ) ) ;
522552 // Set up inputs
523553 let wrapped_script_path = self
524554 . source
0 commit comments