Skip to content

Commit 65fc39c

Browse files
committed
Move all rustflags to .cargo/config
1 parent bdeb68a commit 65fc39c

File tree

5 files changed

+40
-27
lines changed

5 files changed

+40
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Possible log types:
1111
- `[fixed]` for any bug fixes.
1212
- `[security]` to invite users to upgrade in case of vulnerabilities.
1313

14+
### v0.13.1 (2020-12-05)
15+
16+
- [changed] `drone new` generates a more IDE-friendly project with all rustflags
17+
stored in `.cargo/config`
18+
1419
### v0.13.0 (2020-11-28)
1520

1621
- [added] Added mandatory option `linker.platform` to `Drone.toml`

src/cmd/new.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn run(cmd: NewCmd, color: Color) -> Result<()> {
5858
drone_toml(&path, device, flash_size, ram_size, &heap, probe, log, &registry, color)?;
5959
justfile(&path, device, &registry, color)?;
6060
rust_toolchain(&path, &toolchain, &registry, color)?;
61-
cargo_config(&path, &registry, color)?;
61+
cargo_config(&path, device, &registry, color)?;
6262
gitignore(&path, &registry, color)?;
6363

6464
Ok(())
@@ -240,12 +240,12 @@ fn rust_toolchain(
240240
Ok(())
241241
}
242242

243-
fn cargo_config(path: &Path, registry: &Registry<'_>, color: Color) -> Result<()> {
243+
fn cargo_config(path: &Path, device: &Device, registry: &Registry<'_>, color: Color) -> Result<()> {
244244
let path = path.join(".cargo");
245245
create_dir(&path)?;
246246
let path = path.join("config");
247247
let mut file = File::create(&path)?;
248-
file.write_all(registry.new_cargo_config()?.as_bytes())?;
248+
file.write_all(registry.new_cargo_config(device)?.as_bytes())?;
249249
print_created(".cargo/config", color);
250250
Ok(())
251251
}

src/templates/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,7 @@ impl Registry<'_> {
189189

190190
/// Renders `Justfile`.
191191
pub fn new_justfile(&self, device: &Device) -> Result<String> {
192-
let data = json!({
193-
"device_target": device.target,
194-
"platform_flag_name": device.platform_crate.krate.flag_name(),
195-
"bindings_flag_name": device.bindings_crate.krate.flag_name(),
196-
"platform_flag": device.platform_crate.flag,
197-
"bindings_flag": device.bindings_crate.flag,
198-
});
192+
let data = json!({ "device_target": device.target });
199193
helpers::clear_vars();
200194
Ok(self.0.render("new/Justfile", &data)?)
201195
}
@@ -208,9 +202,16 @@ impl Registry<'_> {
208202
}
209203

210204
/// Renders `.cargo/config`.
211-
pub fn new_cargo_config(&self) -> Result<String> {
205+
pub fn new_cargo_config(&self, device: &Device) -> Result<String> {
206+
let data = json!({
207+
"device_target": device.target,
208+
"platform_flag_name": device.platform_crate.krate.flag_name(),
209+
"bindings_flag_name": device.bindings_crate.krate.flag_name(),
210+
"platform_flag": device.platform_crate.flag,
211+
"bindings_flag": device.bindings_crate.flag,
212+
});
212213
helpers::clear_vars();
213-
Ok(self.0.render("new/_cargo/config", &())?)
214+
Ok(self.0.render("new/_cargo/config", &data)?)
214215
}
215216

216217
/// Renders `.gitignore`.

src/templates/new/Justfile.hbs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export DRONE_RUSTFLAGS := '--cfg {{platform_flag_name}}="{{platform_flag}}" --cfg {{bindings_flag_name}}="{{bindings_flag}}"'
21
target := '{{device_target}}'
32
features := ''
43
name := `basename "$(pwd)"`
@@ -20,39 +19,38 @@ fmt:
2019

2120
# Check the source code for mistakes
2221
lint:
23-
drone env \{{target}} -- cargo clippy --features "\{{features}}"
22+
cargo clippy --features "\{{features}}"
2423

2524
# Build the binary
2625
build:
27-
drone env \{{target}} -- cargo build --features "\{{features}}" --release
26+
cargo build --features "\{{features}}" --release
2827

2928
# Build the documentation
3029
doc:
31-
drone env \{{target}} -- cargo doc --features "\{{features}}"
30+
cargo doc --features "\{{features}}"
3231

3332
# Open the documentation in a browser
3433
doc-open: doc
35-
drone env \{{target}} -- cargo doc --features "\{{features}}" --open
34+
cargo doc --features "\{{features}}" --open
3635

3736
# Run the tests
3837
test:
39-
drone env -- cargo test --features "std \{{features}}"
38+
cargo test --features "std \{{features}}" \
39+
--target=$(rustc --version --verbose | sed -n '/host/{s/.*: //;p}')
4040

4141
# Display information from the binary
4242
dump: build
43-
drone env \{{target}} -- cargo objdump --target \{{target}} \
44-
--features "\{{features}}" --release --bin \{{name}} -- \
45-
--disassemble --demangle --full-contents -all-headers --syms | pager
43+
cargo objdump --features "\{{features}}" --release --bin \{{name}} -- \
44+
--disassemble --demangle --full-contents --all-headers --syms \
45+
| pager
4646

4747
# Display the sizes of sections inside the binary
4848
size +args='': build
49-
drone env \{{target}} -- cargo size --target \{{target}} \
50-
--features "\{{features}}" --release --bin \{{name}} -- \{{args}}
49+
cargo size --features "\{{features}}" --release --bin \{{name}} -- \{{args}}
5150

5251
# Display the result of macro expansion
5352
expand:
54-
drone env \{{target}} -- cargo rustc --target \{{target}} \
55-
--features "\{{features}}" --lib -- -Z unstable-options --pretty=expanded
53+
cargo rustc --features "\{{features}}" --lib -- -Z unstable-options --pretty=expanded
5654

5755
# Assert the reset signal
5856
reset:

src/templates/new/_cargo/config.hbs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
[target.'cfg(target_os = "none")']
1+
[build]
2+
target = '{{device_target}}'
23
rustflags = [
3-
"-C", "linker=drone-ld",
4+
'--cfg', '{{platform_flag_name}}="{{platform_flag}}"',
5+
'--cfg', '{{bindings_flag_name}}="{{bindings_flag}}"',
6+
]
7+
8+
[target.{{device_target}}]
9+
rustflags = [
10+
'--cfg', '{{platform_flag_name}}="{{platform_flag}}"',
11+
'--cfg', '{{bindings_flag_name}}="{{bindings_flag}}"',
12+
'-C', 'linker=drone-ld',
413
]

0 commit comments

Comments
 (0)