@@ -45,6 +45,13 @@ fn main() {
4545 vec ! [ "-std=c++20" ]
4646 } ;
4747
48+ // Allow overriding FetchContent source directories via environment variables.
49+ // This is used by Nix (and other sandboxed build systems) where network access
50+ // is blocked and dependencies must be pre-fetched.
51+ let slang_src_dir = std:: env:: var ( "SLANG_SRC_DIR" ) . ok ( ) ;
52+ let fmt_src_dir = std:: env:: var ( "FMT_SRC_DIR" ) . ok ( ) ;
53+ let mimalloc_src_dir = std:: env:: var ( "MIMALLOC_SRC_DIR" ) . ok ( ) ;
54+
4855 // Apply cmake configuration for Slang library
4956 slang_lib
5057 . define ( "SLANG_INCLUDE_TESTS" , "OFF" )
@@ -57,6 +64,16 @@ fn main() {
5764 . define ( "CMAKE_DISABLE_FIND_PACKAGE_Boost" , "ON" )
5865 . profile ( cmake_profile) ;
5966
67+ if let Some ( ref dir) = slang_src_dir {
68+ slang_lib. define ( "FETCHCONTENT_SOURCE_DIR_SLANG" , dir) ;
69+ }
70+ if let Some ( ref dir) = fmt_src_dir {
71+ slang_lib. define ( "FETCHCONTENT_SOURCE_DIR_FMT" , dir) ;
72+ }
73+ if let Some ( ref dir) = mimalloc_src_dir {
74+ slang_lib. define ( "FETCHCONTENT_SOURCE_DIR_MIMALLOC" , dir) ;
75+ }
76+
6077 // Apply common defines and flags
6178 for ( def, value) in common_cxx_defines. iter ( ) {
6279 slang_lib. define ( def, * value) ;
@@ -70,10 +87,17 @@ fn main() {
7087 let dst = slang_lib. build ( ) ;
7188 // With FetchContent, cmake builds slang in a _deps subdirectory rather than
7289 // installing it. Point directly at the FetchContent build/source directories.
90+ // When source dirs are overridden, include paths come from those instead.
7391 let slang_lib_dir = dst. join ( "build/_deps/slang-build/lib" ) ;
74- let slang_include_dir = dst. join ( "build/_deps/slang-src/include" ) ;
92+ let slang_include_dir = match slang_src_dir {
93+ Some ( dir) => std:: path:: PathBuf :: from ( dir) . join ( "include" ) ,
94+ None => dst. join ( "build/_deps/slang-src/include" ) ,
95+ } ;
7596 let slang_generated_include_dir = dst. join ( "build/_deps/slang-build/source" ) ;
76- let fmt_include_dir = dst. join ( "build/_deps/fmt-src/include" ) ;
97+ let fmt_include_dir = match fmt_src_dir {
98+ Some ( dir) => std:: path:: PathBuf :: from ( dir) . join ( "include" ) ,
99+ None => dst. join ( "build/_deps/fmt-src/include" ) ,
100+ } ;
77101
78102 // Generate cpp/compile_flags.txt for clangd IDE support
79103 if !in_publish {
@@ -138,6 +162,9 @@ fn main() {
138162 println ! ( "cargo:rerun-if-changed=cpp/rewriter.cpp" ) ;
139163 println ! ( "cargo:rerun-if-changed=cpp/print.cpp" ) ;
140164 println ! ( "cargo:rerun-if-changed=cpp/analysis.cpp" ) ;
165+ println ! ( "cargo:rerun-if-env-changed=SLANG_SRC_DIR" ) ;
166+ println ! ( "cargo:rerun-if-env-changed=FMT_SRC_DIR" ) ;
167+ println ! ( "cargo:rerun-if-env-changed=MIMALLOC_SRC_DIR" ) ;
141168}
142169
143170// Generates cpp/compile_flags.txt so that clangd gets the correct include paths
0 commit comments