|
| 1 | +# check the packages MSRV first |
| 2 | +source("tools/msrv.R") |
| 3 | + |
| 4 | +# check DEBUG and NOT_CRAN environment variables |
| 5 | +env_debug <- Sys.getenv("DEBUG") |
| 6 | +env_not_cran <- Sys.getenv("NOT_CRAN") |
| 7 | + |
| 8 | +# check if the vendored zip file exists |
| 9 | +vendor_exists <- file.exists("src/rust/vendor.tar.xz") |
| 10 | + |
| 11 | +is_not_cran <- env_not_cran != "" |
| 12 | +is_debug <- env_debug != "" |
| 13 | + |
| 14 | +if (is_debug) { |
| 15 | + # if we have DEBUG then we set not cran to true |
| 16 | + # CRAN is always release build |
| 17 | + is_not_cran <- TRUE |
| 18 | + message("Creating DEBUG build.") |
| 19 | +} |
| 20 | + |
| 21 | +if (!is_not_cran) { |
| 22 | + message("Building for CRAN.") |
| 23 | +} |
| 24 | + |
| 25 | +# we set cran flags only if NOT_CRAN is empty and if |
| 26 | +# the vendored crates are present. |
| 27 | +.cran_flags <- ifelse( |
| 28 | + !is_not_cran && vendor_exists, |
| 29 | + "-j 2 --offline", |
| 30 | + "" |
| 31 | +) |
| 32 | + |
| 33 | +# when DEBUG env var is present we use `--debug` build |
| 34 | +.profile <- ifelse(is_debug, "", "--release") |
| 35 | +.clean_targets <- ifelse(is_debug, "", "$(TARGET_DIR)") |
| 36 | + |
| 37 | +# when we are using a debug build we need to use target/debug instead of target/release |
| 38 | +.libdir <- ifelse(is_debug, "debug", "release") |
| 39 | + |
| 40 | +# read in the Makevars.in file |
| 41 | +is_windows <- .Platform[["OS.type"]] == "windows" |
| 42 | + |
| 43 | +# if windows we replace in the Makevars.win.in |
| 44 | +mv_fp <- ifelse( |
| 45 | + is_windows, |
| 46 | + "src/Makevars.win.in", |
| 47 | + "src/Makevars.in" |
| 48 | +) |
| 49 | + |
| 50 | +# set the output file |
| 51 | +mv_ofp <- ifelse( |
| 52 | + is_windows, |
| 53 | + "src/Makevars.win", |
| 54 | + "src/Makevars" |
| 55 | +) |
| 56 | + |
| 57 | +# delete the existing Makevars{.win} |
| 58 | +if (file.exists(mv_ofp)) { |
| 59 | + message("Cleaning previous `", mv_ofp, "`.") |
| 60 | + invisible(file.remove(mv_ofp)) |
| 61 | +} |
| 62 | + |
| 63 | +# read as a single string |
| 64 | +mv_txt <- readLines(mv_fp) |
| 65 | + |
| 66 | +# replace placeholder values |
| 67 | +new_txt <- gsub("@CRAN_FLAGS@", .cran_flags, mv_txt) |> |
| 68 | + gsub("@PROFILE@", .profile, x = _) |> |
| 69 | + gsub("@CLEAN_TARGET@", .clean_targets, x = _) |> |
| 70 | + gsub("@LIBDIR@", .libdir, x = _) |
| 71 | + |
| 72 | +message("Writing `", mv_ofp, "`.") |
| 73 | +con <- file(mv_ofp, open = "wb") |
| 74 | +writeLines(new_txt, con, sep = "\n") |
| 75 | +close(con) |
| 76 | + |
| 77 | +message("`tools/config.R` has finished.") |
0 commit comments