11pub mod build_types;
22pub mod clean;
33pub mod compile;
4+ pub mod compiler_info;
45pub mod deps;
56pub mod logs;
67pub mod namespaces;
@@ -10,6 +11,7 @@ pub mod read_compile_state;
1011
1112use self :: parse:: parser_args;
1213use crate :: build:: compile:: { mark_modules_with_deleted_deps_dirty, mark_modules_with_expired_deps_dirty} ;
14+ use crate :: build:: compiler_info:: { CompilerCheckResult , verify_compiler_info, write_compiler_info} ;
1315use crate :: helpers:: emojis:: * ;
1416use crate :: helpers:: { self } ;
1517use crate :: project_context:: ProjectContext ;
@@ -109,6 +111,20 @@ pub fn get_compiler_args(rescript_file_path: &Path) -> Result<String> {
109111 Ok ( result)
110112}
111113
114+ pub fn get_compiler_info ( project_context : & ProjectContext ) -> Result < CompilerInfo > {
115+ let bsc_path = helpers:: get_bsc ( ) ;
116+ let bsc_hash = helpers:: compute_file_hash ( & bsc_path) . ok_or ( anyhow ! (
117+ "Failed to compute bsc hash for {}" ,
118+ bsc_path. to_string_lossy( )
119+ ) ) ?;
120+ let runtime_path = compile:: get_runtime_path ( & project_context. current_config , project_context) ?;
121+ Ok ( CompilerInfo {
122+ bsc_path,
123+ bsc_hash,
124+ runtime_path,
125+ } )
126+ }
127+
112128pub fn initialize_build (
113129 default_timing : Option < Duration > ,
114130 filter : & Option < regex:: Regex > ,
@@ -117,8 +133,8 @@ pub fn initialize_build(
117133 build_dev_deps : bool ,
118134 snapshot_output : bool ,
119135) -> Result < BuildState > {
120- let bsc_path = helpers:: get_bsc ( ) ;
121136 let project_context = ProjectContext :: new ( path) ?;
137+ let compiler = get_compiler_info ( & project_context) ?;
122138
123139 if !snapshot_output && show_progress {
124140 print ! ( "{} {}Building package tree..." , style( "[1/7]" ) . bold( ) . dim( ) , TREE ) ;
@@ -129,6 +145,8 @@ pub fn initialize_build(
129145 let packages = packages:: make ( filter, & project_context, show_progress, build_dev_deps) ?;
130146 let timing_package_tree_elapsed = timing_package_tree. elapsed ( ) ;
131147
148+ let compiler_check = verify_compiler_info ( & packages, & compiler) ;
149+
132150 if !snapshot_output && show_progress {
133151 println ! (
134152 "{}{} {}Built package tree in {:.2}s" ,
@@ -139,6 +157,14 @@ pub fn initialize_build(
139157 . unwrap_or( timing_package_tree_elapsed)
140158 . as_secs_f64( )
141159 ) ;
160+ if let CompilerCheckResult :: CleanedPackagesDueToCompiler = compiler_check {
161+ println ! (
162+ "{}{} {}Cleaned previous build due to compiler update" ,
163+ LINE_CLEAR ,
164+ style( "[1/7]" ) . bold( ) . dim( ) ,
165+ SWEEP
166+ ) ;
167+ }
142168 }
143169
144170 if !packages:: validate_packages_dependencies ( & packages) {
@@ -156,7 +182,7 @@ pub fn initialize_build(
156182 let _ = stdout ( ) . flush ( ) ;
157183 }
158184
159- let mut build_state = BuildState :: new ( project_context, packages, bsc_path ) ;
185+ let mut build_state = BuildState :: new ( project_context, packages, compiler ) ;
160186 packages:: parse_packages ( & mut build_state) ;
161187 let timing_source_files_elapsed = timing_source_files. elapsed ( ) ;
162188
@@ -448,6 +474,9 @@ pub fn incremental_build(
448474 log_deprecations ( build_state) ;
449475 }
450476
477+ // Write per-package compiler metadata to `lib/bs/compiler-info.json` (idempotent)
478+ write_compiler_info ( build_state) ;
479+
451480 Ok ( ( ) )
452481 }
453482}
0 commit comments