Skip to content

Commit f619b93

Browse files
committed
Add shared-build-cache feature
The default behavior is to place build products in `OUT_DIR`. This feature makes it possible to place the build products in the shared `~/.cargo` directory instead.
1 parent 11cc318 commit f619b93

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cblas = []
3737
lapacke = []
3838
static = []
3939
system = []
40+
shared-build-cache = []
4041

4142
[dev-dependencies]
4243
libc = "0.2"

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ The following Cargo features are supported:
88

99
* `cblas` to build CBLAS (enabled by default),
1010
* `lapacke` to build LAPACKE (enabled by default),
11-
* `static` to link to OpenBLAS statically, and
12-
* `system` to skip building the bundled OpenBLAS.
11+
* `static` to link to OpenBLAS statically,
12+
* `system` to skip building the bundled OpenBLAS, and
13+
* `shared-build-cache` to place most of the OpenBLAS build products in
14+
`~/.cargo` instead of the `target` directory. (This allows them to be reused
15+
between crates which have different `target` directories, in order to avoid
16+
rebuilding OpenBLAS unnecessarily. However, it prevents `cargo clean` from
17+
removing the OpenBLAS build products.)
1318

1419
## Cross Compilation
1520

build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ fn main() {
3232
_ => variable!("TARGET"),
3333
};
3434
env::remove_var("TARGET");
35-
let source = output.join(format!("source_{}", target.to_lowercase()));
35+
let source = if feature!("SHARED_BUILD_CACHE") {
36+
PathBuf::from(format!("source_{}", target.to_lowercase()))
37+
} else {
38+
output.join(format!("source_{}", target.to_lowercase()))
39+
};
3640
if !source.exists() {
3741
let source_tmp = PathBuf::from(format!("{}_tmp", source.display()));
3842
if source_tmp.exists() {

0 commit comments

Comments
 (0)