@@ -13,7 +13,16 @@ fn get_dep_modules(
1313    build_state :  & BuildState , 
1414)  -> AHashSet < String >  { 
1515    let  mut  deps = AHashSet :: new ( ) ; 
16-     let  ast_file = package. get_build_path ( ) . join ( ast_file) ; 
16+ 
17+     // FIX: Handle both absolute and relative paths for AST files 
18+     // This is needed because we now pass absolute paths from get_compiler_asset() 
19+     // but the function was originally designed for relative paths 
20+     let  ast_file = if  std:: path:: Path :: new ( ast_file) . is_absolute ( )  { 
21+         std:: path:: PathBuf :: from ( ast_file) 
22+     }  else  { 
23+         package. get_build_path ( ) . join ( ast_file) 
24+     } ; 
25+ 
1726    match  helpers:: read_lines ( & ast_file)  { 
1827        Ok ( lines)  => { 
1928            // we skip the first line with is some null characters 
@@ -107,7 +116,19 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
107116                let  package = build_state
108117                    . get_package ( & module. package_name ) 
109118                    . expect ( "Package not found" ) ; 
110-                 let  ast_path = helpers:: get_ast_path ( & source_file. implementation . path ) ; 
119+ 
120+                 // FIX: Use absolute paths for AST files to resolve cross-package dependencies correctly 
121+                 // The issue: get_ast_path() returns relative paths like "src/Types.ast" which work for 
122+                 // single-package builds but fail in workspace builds where BSC creates AST files in 
123+                 // lib/bs/ and they're later copied to lib/ocaml/. Using get_compiler_asset() ensures 
124+                 // we get absolute paths to the correct lib/ocaml/ location where AST files are stored. 
125+                 let  ast_path = helpers:: get_compiler_asset ( 
126+                     package, 
127+                     & packages:: Namespace :: NoNamespace , 
128+                     & source_file. implementation . path , 
129+                     "ast" , 
130+                 ) ; 
131+ 
111132                if  module. deps_dirty  || !build_state. deps_initialized  { 
112133                    let  mut  deps = get_dep_modules ( 
113134                        & ast_path. to_string_lossy ( ) , 
@@ -119,16 +140,23 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
119140                    ) ; 
120141
121142                    if  let  Some ( interface)  = & source_file. interface  { 
122-                         let  iast_path = helpers:: get_ast_path ( & interface. path ) ; 
143+                         // FIX: Use absolute paths for interface AST files (same issue as implementation files) 
144+                         let  iast_path = helpers:: get_compiler_asset ( 
145+                             package, 
146+                             & packages:: Namespace :: NoNamespace , 
147+                             & interface. path , 
148+                             "iast" , 
149+                         ) ; 
123150
124-                         deps . extend ( get_dep_modules ( 
151+                         let  interface_deps =  get_dep_modules ( 
125152                            & iast_path. to_string_lossy ( ) , 
126153                            package. namespace . to_suffix ( ) , 
127154                            package. modules . as_ref ( ) . unwrap ( ) , 
128155                            all_mod, 
129156                            package, 
130157                            build_state, 
131-                         ) ) 
158+                         ) ; 
159+                         deps. extend ( interface_deps) 
132160                    } 
133161                    match  & package. namespace  { 
134162                        packages:: Namespace :: NamespaceWithEntry  {  namespace :  _,  entry } 
0 commit comments