Commit 2bc8fee7 authored by Pelletier Antoine's avatar Pelletier Antoine
Browse files

Cargo compilation behaviour now complies with Brian Ripley

No related merge requests found
Showing with 56 additions and 39 deletions
+56 -39
Package: baseflow Package: baseflow
Type: Package Type: Package
Title: Computes Hydrograph Separation Title: Computes Hydrograph Separation
Version: 0.12.3 Version: 0.12.4
Date: 2021-01-13 Date: 2021-03-01
Authors@R: c( Authors@R: c(
person(given = "Antoine", family = "Pelletier", email = "antoine.pelletier@inrae.fr", role = c("cre", "aut"), person(given = "Antoine", family = "Pelletier", email = "antoine.pelletier@inrae.fr", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-1286-9147")), comment = c(ORCID = "0000-0002-1286-9147")),
......
...@@ -6,7 +6,7 @@ This package has been tested on Linux (openSUSE Leap 15.0 x64), Windows (7 and 1 ...@@ -6,7 +6,7 @@ This package has been tested on Linux (openSUSE Leap 15.0 x64), Windows (7 and 1
Software requirements for the binary installation are the following: Software requirements for the binary installation are the following:
* **R** (package is developed with version 3.6.0) * **R** (package is developed with version 4.0.2)
* **airGR** R package (available on CRAN or [here](https://webgr.irstea.fr/airGR-website)) * **airGR** R package (available on CRAN or [here](https://webgr.irstea.fr/airGR-website))
For the source compilation, in addition to the requirements above, the following are needed: For the source compilation, in addition to the requirements above, the following are needed:
...@@ -18,6 +18,13 @@ For the source compilation, in addition to the requirements above, the following ...@@ -18,6 +18,13 @@ For the source compilation, in addition to the requirements above, the following
General instructions to install the Rust compilation platform are given on the website [RustUp](https://rustup.rs/). It can be installed without administrator privileges - you do not need to ask your local computer technician that does not know Rust. General instructions to install the Rust compilation platform are given on the website [RustUp](https://rustup.rs/). It can be installed without administrator privileges - you do not need to ask your local computer technician that does not know Rust.
#### Prior notice: PATH environment variable modification
By default, the Rust compilation plaform is installed in `$HOME/.cargo` on Unix platforms and `%USERPROFILE%/.cargo` on Windows. This directory is then added to the PATH environment variable for the user to be able to use the toolchain without refering to the installation directory.
If you plan to use Rust for other purpose than installing `baseflow`, it is recommanded to set the *modify PATH variable* to *yes*. But if you only want to build and install *baseflow*, to avoid any side-effect of the installation, you should set this option to *no* as explained below.
CRAN policy prevents published R packages to alter the user environment or filespace apart from the R session. Therefore, you should only change your PATH global variable if you know what you are doing.
#### Windows #### Windows
On Windows, download and lauch the rustup-init.exe script (64 bits version is [here](https://win.rustup.rs/x86_64), 32 bits is [here](https://win.rustup.rs/i686)). In the command prompt window, choose the second option `Customize installation` and set configuration as below. On Windows, download and lauch the rustup-init.exe script (64 bits version is [here](https://win.rustup.rs/x86_64), 32 bits is [here](https://win.rustup.rs/i686)). In the command prompt window, choose the second option `Customize installation` and set configuration as below.
...@@ -25,7 +32,7 @@ On Windows, download and lauch the rustup-init.exe script (64 bits version is [h ...@@ -25,7 +32,7 @@ On Windows, download and lauch the rustup-init.exe script (64 bits version is [h
``` ```
default host triple: i686-pc-windows-gnu default host triple: i686-pc-windows-gnu
default toolchain: stable default toolchain: stable
modify PATH variable: yes modify PATH variable: no
``` ```
Then, choose the first option `Proceed with installation`. Then, choose the first option `Proceed with installation`.
...@@ -50,7 +57,7 @@ For 64 bits systems: ...@@ -50,7 +57,7 @@ For 64 bits systems:
``` ```
default host triple: x86_64-unknown-linux-gnu default host triple: x86_64-unknown-linux-gnu
default toolchain: stable default toolchain: stable
modify PATH variable: yes modify PATH variable: no
``` ```
For 32 bits systems: For 32 bits systems:
...@@ -58,10 +65,10 @@ For 32 bits systems: ...@@ -58,10 +65,10 @@ For 32 bits systems:
``` ```
default host triple: i686-unknown-linux-gnu default host triple: i686-unknown-linux-gnu
default toolchain: stable default toolchain: stable
modify PATH variable: yes modify PATH variable: no
``` ```
After modifying configuration, choose option 1 `Proceed with installation`. After the end of installation, close and re-open your user session, or restart your computer, to update your environment variables. After modifying configuration, choose option 1 `Proceed with installation`.
### Package compilation and installation ### Package compilation and installation
......
# Where is Cargo ? game # Where is Cargo ? game
ifneq "$(strip $(CARGO_HOME))" "" #ifneq "$(strip $(CARGO_HOME))" ""
CG=$(CARGO_HOME) # CG=$(CARGO_HOME)
else #else
CG=cargo # CG=cargo
endif #endif
.PHONY: all .PHONY: all
...@@ -17,13 +17,6 @@ $(SHLIB): $(STATLIB) ...@@ -17,13 +17,6 @@ $(SHLIB): $(STATLIB)
# to make things # to make things
all: $(SHLIB) all: $(SHLIB)
# run cargo
# rustlib/target/release/librustlib.rlib: rustlib/src/*.rs
# cd rustlib && $(CG) build --release
# -lws2_32 -luserenv -ladvapi32 is needed for linking on windows
# PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L. -Lrustlib/target/release/ -lrustlib
$(STATLIB): $(STATLIB):
"${R_HOME}/bin${R_ARCH_BIN}/Rscript" ../tools/staticlib.R "$(TARGET)" "${R_HOME}/bin${R_ARCH_BIN}/Rscript" ../tools/staticlib.R "$(TARGET)"
......
# Where is Cargo ? game # Where is Cargo ? game
ifneq "$(strip $(CARGO_HOME))" "" #ifneq "$(strip $(CARGO_HOME))" ""
CG=$(CARGO_HOME) # CG=$(CARGO_HOME)
else #else
CG=cargo # CG=cargo
endif #endif
# Rust architecture (x64 or i686) # Rust architecture (x64 or i686)
ifeq "$(WIN)" "64" ifeq "$(WIN)" "64"
...@@ -24,10 +24,6 @@ $(SHLIB): $(STATLIB) ...@@ -24,10 +24,6 @@ $(SHLIB): $(STATLIB)
# to make things # to make things
all: $(SHLIB) all: $(SHLIB)
# run cargo
#$(STATLIB): rustlib/src/*.rs
# cd rustlib && $(CG) build --release --target $(TARGET)
$(STATLIB): $(STATLIB):
"${R_HOME}/bin${R_ARCH_BIN}/Rscript" ../tools/staticlib.R "$(TARGET)" "${R_HOME}/bin${R_ARCH_BIN}/Rscript" ../tools/staticlib.R "$(TARGET)"
......
[package] [package]
name = "rustlib" name = "rustlib"
version = "0.12.3" version = "0.12.4"
[dependencies] [dependencies]
rustr = "*" rustr = "*"
......
...@@ -2,8 +2,19 @@ ...@@ -2,8 +2,19 @@
args <- commandArgs(TRUE) args <- commandArgs(TRUE)
target <- if ( length(args) > 0 ) args[1] else NULL target <- if ( length(args) > 0 ) args[1] else NULL
# Where is Cargo? game # Finding cargo
cargo_is_found <- (Sys.which("cargo") != "") if(Sys.which("cargo") != ""){ # Searching for CARGO in PATH
cargo_is_found <- TRUE
cargo <- "cargo"
} else if(file.exists(paste0(Sys.getenv("HOME"), "/.cargo/bin/cargo"))){ # Searching in ~/.cargo/bin on Unix
cargo_is_found <- TRUE
cargo <- paste0(Sys.getenv("HOME"), "/.cargo/bin/cargo")
} else if(file.exists(paste0(Sys.getenv("USERPROFILE"), "/.cargo/bin/cargo.exe"))){ # Searching on Windows
cargo_is_found <- TRUE
cargo <- paste0(Sys.getenv("USERPROFILE"), "/.cargo/bin/cargo.exe")
} else {
cargo_is_found <- FALSE
}
# Detecting OS type # Detecting OS type
osType <- function() { osType <- function() {
...@@ -22,7 +33,6 @@ if(!(osType %in% c('windows', 'macosx', 'linux', 'macosx-arm'))){ ...@@ -22,7 +33,6 @@ if(!(osType %in% c('windows', 'macosx', 'linux', 'macosx-arm'))){
cat(paste0(osType, ' is not a supported platform.\n', cat(paste0(osType, ' is not a supported platform.\n',
'Compilation and installation may be possible if the Rust compiler is available.\n', 'Compilation and installation may be possible if the Rust compiler is available.\n',
'It is recommended to use baseflow package with Windows, GNU/Linux or macOS.\n')) 'It is recommended to use baseflow package with Windows, GNU/Linux or macOS.\n'))
#quit(status = 1)
} }
# Detecting cargo installed version # Detecting cargo installed version
...@@ -34,15 +44,19 @@ if(!cargo_is_found && !(osType %in% c("windows", "macosx", "macosx-arm"))){ ...@@ -34,15 +44,19 @@ if(!cargo_is_found && !(osType %in% c("windows", "macosx", "macosx-arm"))){
quit(status = 1) quit(status = 1)
} }
if(cargo_is_found && (osType == 'windows')){ if(cargo_is_found && (osType == 'windows')){
installedCargoVersion <- gsub("cargo ([^ ]+).*", "\\1", system2("cargo","--version",stdout=TRUE)) installedCargoVersion <- gsub("cargo ([^ ]+).*", "\\1", system2(cargo,"--version",stdout=TRUE))
cat(paste0("Cargo version ", installedCargoVersion, " found.\n")) cat(paste0("Cargo version ", installedCargoVersion, " found.\n"))
installedCargoVersion <- strsplit(installedCargoVersion, '-')[[1]][1] installedCargoVersion <- strsplit(installedCargoVersion, '-')[[1]][1]
is_installed_newer <- (compareVersion(installedCargoVersion, requiredCargoVersion) >= 0) is_installed_newer <- (compareVersion(installedCargoVersion, requiredCargoVersion) >= 0)
# Compiling if cargo version is OK # Compiling if cargo version is OK
if(is_installed_newer){ if(is_installed_newer){
cargo_home_backup <- Sys.getenv("CARGO_HOME")
Sys.setenv(CARGO_HOME = paste0(getwd(), '/.cargo'))
cat("Compiling the Rust library.\n") cat("Compiling the Rust library.\n")
system2("cargo",c("build",paste0('--target ', target),"--release","--manifest-path=rustlib/Cargo.toml")) system2(cargo,c("build",paste0('--target ', target),"--release","--manifest-path=rustlib/Cargo.toml"))
unlink('./.cargo', recursive = TRUE, force = TRUE)
Sys.setenv(CARGO_HOME = cargo_home_backup)
quit(status = 0) quit(status = 0)
} else { } else {
cat("Cargo version too old. Run rustup update in a terminal.\n") cat("Cargo version too old. Run rustup update in a terminal.\n")
...@@ -50,20 +64,24 @@ if(cargo_is_found && (osType == 'windows')){ ...@@ -50,20 +64,24 @@ if(cargo_is_found && (osType == 'windows')){
} }
} }
if(cargo_is_found && (osType != 'windows')){ if(cargo_is_found && (osType != 'windows')){
installedCargoVersion <- gsub("cargo ([^ ]+).*", "\\1", system2("cargo","--version",stdout=TRUE)) installedCargoVersion <- gsub("cargo ([^ ]+).*", "\\1", system2(cargo,"--version",stdout=TRUE))
cat(paste0("Cargo version ", installedCargoVersion, " found.\n")) cat(paste0("Cargo version ", installedCargoVersion, " found.\n"))
installedCargoVersion <- strsplit(installedCargoVersion, '-')[[1]][1] installedCargoVersion <- strsplit(installedCargoVersion, '-')[[1]][1]
is_installed_newer <- (compareVersion(installedCargoVersion, requiredCargoVersion) >= 0) is_installed_newer <- (compareVersion(installedCargoVersion, requiredCargoVersion) >= 0)
# Compiling if cargo version is OK # Compiling if cargo version is OK
if(is_installed_newer){ if(is_installed_newer){
cargo_home_backup <- Sys.getenv("CARGO_HOME")
Sys.setenv(CARGO_HOME = paste0(getwd(), '/.cargo'))
cat("Compiling the Rust library.\n") cat("Compiling the Rust library.\n")
system2("cargo",c("build","--release","--manifest-path=rustlib/Cargo.toml")) system2(cargo,c("build","--release","--manifest-path=rustlib/Cargo.toml"))
if(osType == 'macosx'){ if(osType == 'macosx'){
system2("strip", c("-x", "rustlib/target/release/librustlib.a")) system2("strip", c("-x", "rustlib/target/release/librustlib.a"))
} else { } else {
system2("strip", c("--strip-unneeded", "rustlib/target/release/librustlib.a")) system2("strip", c("--strip-unneeded", "rustlib/target/release/librustlib.a"))
} }
unlink('./.cargo', recursive = TRUE, force = TRUE)
Sys.setenv(CARGO_HOME = cargo_home_backup)
quit(status = 0) quit(status = 0)
} else { } else {
cat("Cargo version too old. Run rustup update in a terminal.\n") cat("Cargo version too old. Run rustup update in a terminal.\n")
...@@ -87,8 +105,9 @@ if(!cargo_is_found && (osType == 'macosx')){ ...@@ -87,8 +105,9 @@ if(!cargo_is_found && (osType == 'macosx')){
for(f in files_list){ for(f in files_list){
file.copy(from = paste0('./ext_tools/', target, '/release/', f), file.copy(from = paste0('./ext_tools/', target, '/release/', f),
to = paste0(destDir, '/', f), overwrite = TRUE) to = paste0(destDir, '/', f), overwrite = TRUE)
file.remove(paste0('./ext_tools/', target, '/release/', f)) #file.remove(paste0('./ext_tools/', target, '/release/', f))
} }
unlink('./ext_tools', recursive = TRUE, force = TRUE)
} }
if(!cargo_is_found && (osType == 'macosx-arm')){ if(!cargo_is_found && (osType == 'macosx-arm')){
target <- "aarch64-apple-darwin" target <- "aarch64-apple-darwin"
...@@ -105,8 +124,9 @@ if(!cargo_is_found && (osType == 'macosx-arm')){ ...@@ -105,8 +124,9 @@ if(!cargo_is_found && (osType == 'macosx-arm')){
for(f in files_list){ for(f in files_list){
file.copy(from = paste0('./ext_tools/', target, '/release/', f), file.copy(from = paste0('./ext_tools/', target, '/release/', f),
to = paste0(destDir, '/', f), overwrite = TRUE) to = paste0(destDir, '/', f), overwrite = TRUE)
file.remove(paste0('./ext_tools/', target, '/release/', f)) #file.remove(paste0('./ext_tools/', target, '/release/', f))
} }
unlink('./ext_tools', recursive = TRUE, force = TRUE)
} }
if(!cargo_is_found && (osType == 'windows')){ if(!cargo_is_found && (osType == 'windows')){
cat("Downloading pre-compiled Rust library.\n") cat("Downloading pre-compiled Rust library.\n")
...@@ -122,6 +142,7 @@ if(!cargo_is_found && (osType == 'windows')){ ...@@ -122,6 +142,7 @@ if(!cargo_is_found && (osType == 'windows')){
for(f in files_list){ for(f in files_list){
file.copy(from = paste0('./ext_tools/', target, '/release/', f), file.copy(from = paste0('./ext_tools/', target, '/release/', f),
to = paste0(destDir, '/', f), overwrite = TRUE) to = paste0(destDir, '/', f), overwrite = TRUE)
file.remove(paste0('./ext_tools/', target, '/release/', f)) #file.remove(paste0('./ext_tools/', target, '/release/', f))
} }
unlink('./ext_tools', recursive = TRUE, force = TRUE)
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment