Skip to content

Commit 2a84b50

Browse files
committed
Add rust target option and remove pio_include
1 parent 8a13d3b commit 2a84b50

File tree

4 files changed

+9
-100
lines changed

4 files changed

+9
-100
lines changed

cargo_build.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# PlatformIO specific
1010
Import("env")
1111

12+
CONFIG = ConfigParser()
13+
CONFIG.read(env.subst("$PROJECT_CONFIG"))
1214
MOD_PRELUDE = """
1315
#![allow(dead_code)]
1416
#![allow(non_camel_case_types)]
@@ -43,11 +45,8 @@
4345
"""
4446

4547
def get_rust_headers():
46-
config = ConfigParser()
47-
config.read(env.subst("$PROJECT_CONFIG"))
48-
4948
try:
50-
headers_to_process_str = config.get(env.subst("env:$PIOENV"), "rust_headers")
49+
headers_to_process_str = CONFIG.get(env.subst("env:$PIOENV"), "rust_headers")
5150
except NoOptionError:
5251
return []
5352

@@ -95,6 +94,8 @@ def get_rust_headers():
9594
def ignore_main_cpp(node):
9695
defines = env.subst("$_CPPDEFFLAGS").replace("\\\"", "\"")
9796
sysroot = popen(env.subst("$CC -print-sysroot")).read().strip()
97+
target = CONFIG.get(env.subst("env:$PIOENV"), "rust_target").strip()
98+
9899
mod_rs = open(env.subst("$PROJECT_SRC_DIR/platformio/mod.rs"), "w")
99100
mod_rs.write(MOD_PRELUDE)
100101

@@ -127,7 +128,7 @@ def ignore_main_cpp(node):
127128
name=name,
128129
header=h,
129130
sysroot=sysroot,
130-
target="thumbv7em-none-eabihf",
131+
target=target,
131132
defines=defines))
132133

133134
# As the preprocessor does not have any idea abut namespaces, we can re-export all the functions safely
@@ -137,8 +138,8 @@ def ignore_main_cpp(node):
137138
""".format(name=name[:-3])) # Remove .rs extension
138139

139140
mod_rs.close()
140-
env.Execute("cargo build --release --target=thumbv7em-none-eabihf -v")
141-
env.Append(PIOBUILDFILES=["$PROJECT_DIR/target/thumbv7em-none-eabihf/release/deps/firmware-platformio.o"])
141+
env.Execute("cargo build --release -v --target=" + target)
142+
env.Append(PIOBUILDFILES=["$PROJECT_DIR/target/" + target + "/release/deps/firmware-platformio.o"])
142143

143144
return None
144145

pio_include/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

pio_include/src/lib.rs

Lines changed: 0 additions & 81 deletions
This file was deleted.

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ board = adafruit_feather_nrf52832
1414
framework = arduino
1515
extra_scripts = pre:cargo_build.py
1616
rust_headers = Arduino.h
17+
rust_target = thumbv7em-none-eabihf

0 commit comments

Comments
 (0)