Skip to content

Commit 5ae396f

Browse files
committed
Make sysroot location configurable
1 parent 39b107f commit 5ae396f

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
7+
- Add config option `sysroot_path` that defines where the sysroot should be placed. Defaults to the `target/sysroot`.
78

89
## [0.4.3] - 2018-05-31
910
- Make behavior configurable through a `package.metadata.cargo-xbuild` table in the `Cargo.toml`

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ To configure `cargo-xbuild` create a `package.metadata.cargo-xbuild` table in yo
3434
```toml
3535
[package.metadata.cargo-xbuild]
3636
memcpy = true
37+
sysroot_path = "target/sysroot"
3738
```
3839

3940
- The `memcpy` flag defines whether the `mem` feature of the `compiler_builtins` crate should be activated. Turning this flag off allows to specify own versions of the `memcpy`, `memset` etc. functions.
41+
- The `sysroot_path` flag specifies the directory where the sysroot should be placed.
4042

4143
## Dev channel
4244

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ use cargo_metadata;
44
#[derive(Debug, Deserialize, Hash)]
55
pub struct Config {
66
pub memcpy: bool,
7+
pub sysroot_path: Option<String>,
78
}
89

910
impl Default for Config {
1011
fn default() -> Self {
1112
Config {
1213
memcpy: true,
14+
sysroot_path: None,
1315
}
1416
}
1517
}

src/help.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ OPTIONS:
99

1010
Any additional options are directly passed to `cargo build` (see
1111
`cargo build --help` for possible options).
12+
13+
CONFIGURATION:
14+
Configuration is possible through a `package.metadata.cargo-xbuild` table
15+
in your `Cargo.toml`:
16+
17+
[package.metadata.cargo-xbuild]
18+
memcpy = true
19+
sysroot_path = "target/sysroot"
20+
21+
See README.md for a description of these flags.

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
193193
};
194194

195195
if let Some(cmode) = cmode {
196-
let home = xargo::home(target_directory)?;
196+
let home = xargo::home(target_directory, &crate_config)?;
197197
let rustflags = cargo::rustflags(config.as_ref(), cmode.triple())?;
198198

199199
sysroot::update(

src/xargo.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::{Display, PathBuf};
22
use std::process::{Command, ExitStatus};
3-
use std::mem;
3+
use std::{fs, mem};
44
use std::io::{self, Write};
55
use std::path::Path;
66

@@ -12,6 +12,7 @@ use cli::Args;
1212
use errors::*;
1313
use extensions::CommandExt;
1414
use flock::{FileLock, Filesystem};
15+
use config::Config;
1516

1617
pub fn run(
1718
args: &Args,
@@ -68,11 +69,18 @@ impl Home {
6869
}
6970
}
7071

71-
pub fn home(target_directory: &Path) -> Result<Home> {
72-
let mut p = PathBuf::from(target_directory);
73-
p.push("sysroot");
72+
pub fn home(target_directory: &Path, config: &Config) -> Result<Home> {
73+
let path = if let Some(ref p) = config.sysroot_path {
74+
let path = Path::new(p);
75+
fs::create_dir_all(&path).map_err(|_| String::from("Could not create sysroot folder"))?;
76+
path.canonicalize().map_err(|_| String::from("Invalid sysroot path"))?
77+
} else {
78+
let mut p = PathBuf::from(target_directory);
79+
p.push("sysroot");
80+
p
81+
};
7482

7583
Ok(Home {
76-
path: Filesystem::new(p),
84+
path: Filesystem::new(path),
7785
})
7886
}

0 commit comments

Comments
 (0)