File tree Expand file tree Collapse file tree 5 files changed +47
-1
lines changed
Expand file tree Collapse file tree 5 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -11,3 +11,6 @@ rustc_plugin = { path = "../.." }
1111env_logger = { version = " 0.10" , default-features = false }
1212clap = { version = " 4.4" , features = [" derive" ] }
1313serde = { version = " 1" , features = [" derive" ] }
14+
15+ [build-dependencies ]
16+ rustc_plugin = { path = " ../.." }
Original file line number Diff line number Diff line change 1+ #![ feature( rustc_private) ]
2+
3+ fn main ( ) {
4+ rustc_plugin:: build_main ( ) ;
5+ }
Original file line number Diff line number Diff line change 1+ use std:: {
2+ path:: { Path , PathBuf } ,
3+ process:: Command ,
4+ } ;
5+
6+ fn rustc_path ( ) -> PathBuf {
7+ let output = Command :: new ( "rustup" )
8+ . args ( [ "which" , "--toolchain" , crate :: CHANNEL , "rustc" ] )
9+ . output ( )
10+ . expect ( "failed to run rustup which" ) ;
11+ let rustc_path = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
12+ PathBuf :: from ( rustc_path. trim ( ) )
13+ }
14+
15+ fn target_libdir ( rustc : & Path ) -> PathBuf {
16+ let output = Command :: new ( rustc)
17+ . args ( [ "--print" , "target-libdir" ] )
18+ . output ( )
19+ . expect ( "failed to run rustc --print target-libdir" ) ;
20+ let libdir = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
21+ PathBuf :: from ( libdir. trim ( ) )
22+ }
23+
24+ pub fn build_main ( ) {
25+ let rustc_path = rustc_path ( ) ;
26+ let target_libdir = target_libdir ( & rustc_path) ;
27+ println ! (
28+ "cargo::rustc-link-arg=-Wl,-rpath,{}" ,
29+ target_libdir. display( )
30+ ) ;
31+ }
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ pub fn cli_main<T: RustcPlugin>(plugin: T) {
2626 . other_options ( [ "--all-features" . to_string ( ) , "--offline" . to_string ( ) ] )
2727 . exec ( )
2828 . unwrap ( ) ;
29- let plugin_subdir = format ! ( "plugin-{}" , env! ( "RUSTC_CHANNEL" ) ) ;
29+ let plugin_subdir = format ! ( "plugin-{}" , crate :: CHANNEL ) ;
3030 let target_dir = metadata. target_directory . join ( plugin_subdir) ;
3131
3232 let args = plugin. args ( & target_dir) ;
Original file line number Diff line number Diff line change @@ -9,12 +9,19 @@ extern crate rustc_driver;
99extern crate rustc_interface;
1010extern crate rustc_session;
1111
12+ pub use build:: build_main;
1213#[ doc( hidden) ]
1314pub use cargo_metadata:: camino:: Utf8Path ;
1415pub use cli:: cli_main;
1516pub use driver:: driver_main;
1617pub use plugin:: { CrateFilter , RustcPlugin , RustcPluginArgs } ;
1718
19+ /// The toolchain channel that this version of rustc_plugin was built with.
20+ ///
21+ /// For example, `nightly-2025-08-20`
22+ pub const CHANNEL : & str = env ! ( "RUSTC_CHANNEL" ) ;
23+
24+ mod build;
1825mod cli;
1926mod driver;
2027mod plugin;
You can’t perform that action at this time.
0 commit comments