Skip to content

Commit 84cedfd

Browse files
bors[bot]Robert Forsman
andauthored
Merge #277
277: Add support for Arduino Uno and 2560 r=japaric a=mutantbob This patch includes changes I needed to build my Arduino Uno sketches. I incorporated the work from #264 to reduce the chance of conflicts. Now that atomic-polyfill 0.1.8 supports AVR, things are a bit easier. Co-authored-by: Robert Forsman <[email protected]>
2 parents 0a844a0 + 178d44c commit 84cedfd

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
### Added
11+
- Added support for AVR architecture.
1112

1213
### Changed
1314

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ atomic-polyfill = { version = "0.1.4" }
3636
[target.riscv32imc-unknown-none-elf.dependencies]
3737
atomic-polyfill = { version = "0.1.4" }
3838

39+
[target.'cfg(target_arch = "avr")'.dependencies]
40+
atomic-polyfill = { version = "0.1.8", optional = true }
41+
42+
3943
[dependencies]
4044
hash32 = "0.2.1"
4145

build.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ fn main() -> Result<(), Box<dyn Error>> {
2323
println!("cargo:rustc-cfg=armv7a");
2424
}
2525

26+
let is_avr = env::var("CARGO_CFG_TARGET_ARCH") == Ok("avr".to_string());
27+
2628
// built-in targets with no atomic / CAS support as of nightly-2022-01-13
2729
// AND not supported by the atomic-polyfill crate
2830
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
29-
match &target[..] {
31+
if is_avr {
32+
// lacks cas
33+
} else {
34+
match &target[..] {
3035
"avr-unknown-gnu-atmega328"
3136
| "bpfeb-unknown-none"
3237
| "bpfel-unknown-none"
@@ -40,32 +45,41 @@ fn main() -> Result<(), Box<dyn Error>> {
4045
_ => {
4146
println!("cargo:rustc-cfg=has_cas");
4247
}
48+
}
4349
};
4450

45-
match &target[..] {
46-
"avr-unknown-gnu-atmega328"
47-
| "msp430-none-elf"
51+
if is_avr {
52+
// lacks atomics
53+
} else {
54+
match &target[..] {
55+
"msp430-none-elf"
4856
// | "riscv32i-unknown-none-elf" // supported by atomic-polyfill
4957
// | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill
5058
=> {}
5159

5260
_ => {
5361
println!("cargo:rustc-cfg=has_atomics");
5462
}
63+
}
5564
};
5665

5766
// Let the code know if it should use atomic-polyfill or not, and what aspects
5867
// of polyfill it requires
59-
match &target[..] {
60-
"riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
61-
println!("cargo:rustc-cfg=full_atomic_polyfill");
62-
println!("cargo:rustc-cfg=cas_atomic_polyfill");
63-
}
68+
if is_avr {
69+
println!("cargo:rustc-cfg=full_atomic_polyfill");
70+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
71+
} else {
72+
match &target[..] {
73+
"riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
74+
println!("cargo:rustc-cfg=full_atomic_polyfill");
75+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
76+
}
6477

65-
"thumbv6m-none-eabi" => {
66-
println!("cargo:rustc-cfg=cas_atomic_polyfill");
78+
"thumbv6m-none-eabi" => {
79+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
80+
}
81+
_ => {}
6782
}
68-
_ => {}
6983
}
7084

7185
if !matches!(

0 commit comments

Comments
 (0)