@@ -9,14 +9,39 @@ is_windows <- .Platform[["OS.type"]] == "windows"
99
1010# Generate a short target directory for Windows to avoid MAX_PATH issues
1111# aws-lc-sys builds fail when paths exceed ~250 characters
12+ # IMPORTANT: Both CARGO_HOME and TARGET_DIR must be in the same short path
13+ # so that relative paths in aws-lc-sys CMake builds resolve correctly
1214if (is_windows ) {
13- # Use R's temp directory but with a short subdirectory name
14- # This is CRAN-compliant as it uses the session temp directory
15- short_tmp <- file.path(tempdir(), " dR" )
15+ # For CI builds (NOT_CRAN set), we can use a fixed short path
16+
17+ # For CRAN builds, we use tempdir but write the path to a file so that
18+
19+ # subsequent R sessions (configure vs build) use the same directory
20+
21+ env_not_cran_check <- Sys.getenv(" NOT_CRAN" )
22+
23+ if (env_not_cran_check != " " ) {
24+ # CI build - use fixed short path (no CRAN policy concerns)
25+ short_base <- " C:/tmp/dR"
26+ } else {
27+ # CRAN build - use tempdir but persist the path choice
28+ # Create a marker file in the source directory to ensure consistency
29+ marker_file <- " src/.short_build_path"
30+ if (file.exists(marker_file )) {
31+ short_base <- readLines(marker_file , n = 1 )
32+ } else {
33+ short_base <- gsub(" \\\\ " , " /" , file.path(tempdir(), " dR" ))
34+ writeLines(short_base , marker_file )
35+ }
36+ }
37+
1638 # Normalize to forward slashes for Make compatibility
17- .target_dir <- gsub(" \\\\ " , " /" , short_tmp )
39+ .target_dir <- paste0(short_base , " /target" )
40+ .cargo_home <- paste0(short_base , " /.cargo" )
41+ message(" Using short build path: " , short_base )
1842} else {
1943 .target_dir <- " ./rust/target"
44+ .cargo_home <- " $(CURDIR)/.cargo"
2045}
2146
2247# check DEBUG and NOT_CRAN environment variables
@@ -117,7 +142,8 @@ new_txt <- gsub("@CRAN_FLAGS@", .cran_flags, mv_txt) |>
117142 gsub(" @LIBDIR@" , .libdir , x = _) | >
118143 gsub(" @TARGET@" , .target , x = _) | >
119144 gsub(" @PANIC_EXPORTS@" , .panic_exports , x = _) | >
120- gsub(" @TARGET_DIR@" , .target_dir , x = _)
145+ gsub(" @TARGET_DIR@" , .target_dir , x = _) | >
146+ gsub(" @CARGO_HOME@" , .cargo_home , x = _)
121147
122148message(" Writing `" , mv_ofp , " `." )
123149con <- file(mv_ofp , open = " wb" )
0 commit comments