Skip to content

Commit 2ed7d50

Browse files
lf-pico-template updates (#32)
* [init] platform opt, template repo * [package] abstract repo template setup * [backend] set lfc backend for C * [format] apply * stub c-cmake * remove cmake stub * add tempfile * format --------- Co-authored-by: Tassilo Tanneberger <[email protected]>
1 parent 20be607 commit 2ed7d50

File tree

7 files changed

+71
-23
lines changed

7 files changed

+71
-23
lines changed

Cargo.lock

Lines changed: 31 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ crossbeam = "*"
2222
termion = "1.5"
2323
git2 = "*"
2424
run_script = "0.10"
25+
tempfile = "*"

src/args.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum TargetLanguage {
1616
pub enum Platform {
1717
Native,
1818
Zephyr,
19+
RP2040,
1920
}
2021

2122
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)]
@@ -87,16 +88,17 @@ impl ToString for TargetLanguage {
8788
pub struct InitArgs {
8889
#[clap(value_enum, short, long)]
8990
pub language: Option<TargetLanguage>,
90-
9191
#[clap(value_enum, short, long, default_value_t = Platform::Native)]
9292
pub platform: Platform,
9393
}
9494
impl InitArgs {
9595
pub fn get_target_language(&self) -> TargetLanguage {
9696
self.language.unwrap_or({
97-
// Target language for Zephyr is C, else Cpp.
97+
// Target language for Zephyr and RP2040 is C
98+
// Else use Cpp.
9899
match self.platform {
99100
Platform::Zephyr => TargetLanguage::C,
101+
Platform::RP2040 => TargetLanguage::C,
100102
_ => TargetLanguage::Cpp,
101103
}
102104
})
@@ -108,7 +110,7 @@ pub enum Command {
108110
/// initializing a lingua-franca project
109111
Init(InitArgs),
110112

111-
/// compiling one ore multiple binaries in a lingua-franca package
113+
/// compiling one or multiple binaries in a lingua-franca package
112114
Build(BuildArgs),
113115

114116
/// Updates the dependencies and potentially build tools

src/backends/cmake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult {
1616
fs::create_dir_all(&build_dir)?;
1717

1818
let mut cmake = Command::new("cmake");
19+
// cmake args
1920
cmake.arg(format!(
2021
"-DCMAKE_BUILD_TYPE={}",
2122
if options.profile == BuildProfile::Release {

src/backends/lfc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl BatchBackend for LFC {
4848
CommandSpec::Update => todo!(),
4949
CommandSpec::Clean => {
5050
results.par_map(|app| {
51-
fs::remove_dir_all(app.src_gen_dir())?;
51+
crate::util::default_build_clean(&app.output_root)?;
5252
Ok(())
5353
});
5454
}
@@ -89,7 +89,10 @@ impl<'a> LfcJsonArgs<'a> {
8989
.unwrap()
9090
.as_object_mut()
9191
.unwrap();
92-
properties.insert("no-compile".to_string(), self.no_compile.into());
92+
// lfc does not support no-compile:false
93+
if self.no_compile {
94+
properties.insert("no-compile".to_string(), self.no_compile.into());
95+
}
9396
Ok(value)
9497
}
9598
}

src/backends/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::sync::Arc;
55

66
use rayon::prelude::*;
77

8-
use crate::args::Platform;
8+
use crate::args::{BuildSystem, Platform};
9+
use crate::package::App;
910
use crate::util::errors::{AnyError, BuildResult, LingoError};
10-
use crate::{args::BuildSystem, package::App};
1111

1212
pub mod cmake;
1313
pub mod lfc;

src/package/mod.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{env, io};
1313
use crate::args::BuildSystem::{CMake, Cargo, LFC};
1414
use crate::util::errors::{BuildResult, LingoError};
1515
use git2::Repository;
16+
use tempfile::tempdir;
1617
use which::which;
1718

1819
fn is_valid_location_for_project(path: &std::path::Path) -> bool {
@@ -92,6 +93,7 @@ pub struct App {
9293
impl App {
9394
pub fn build_system(&self) -> BuildSystem {
9495
match self.target {
96+
TargetLanguage::C => LFC,
9597
TargetLanguage::Cpp => CMake,
9698
TargetLanguage::Rust => Cargo,
9799
TargetLanguage::TypeScript => {
@@ -118,16 +120,16 @@ impl App {
118120
}
119121
}
120122

121-
/// Simple or DetailedDependcy
123+
/// Simple or DetailedDependency
122124
#[derive(Clone, Deserialize, Serialize)]
123-
pub enum FileDependcy {
125+
pub enum FileDependency {
124126
// the version string
125127
Simple(String),
126128
/// version string and source
127129
Advanced(DetailedDependency),
128130
}
129131

130-
/// Dependcy with source and version
132+
/// Dependency with source and version
131133
#[derive(Clone, Deserialize, Serialize)]
132134
pub struct DetailedDependency {
133135
version: String,
@@ -222,23 +224,32 @@ impl ConfigFile {
222224
Ok(())
223225
}
224226

225-
// Sets up a LF project with Zephyr as the target platform.
226-
pub fn setup_zephyr(&self) -> BuildResult {
227-
// Clone lf-west-template into a temporary directory
228-
let tmp_path = Path::new("zephyr_tmp");
229-
if tmp_path.exists() {
230-
remove_dir_all(tmp_path)?;
231-
}
232-
let url = "https://github.com/lf-lang/lf-west-template";
227+
fn setup_template_repo(&self, url: &str) -> BuildResult {
228+
let dir = tempdir()?;
229+
let tmp_path = dir.path();
233230
Repository::clone(url, tmp_path)?;
234-
235231
// Copy the cloned template repo into the project directory
236232
copy_recursively(tmp_path, Path::new("."))?;
233+
// Remove temporary folder
234+
dir.close()?;
235+
Ok(())
236+
}
237237

238-
// Remove .git, .gitignore ad temporary folder
238+
// Sets up a LF project with Zephyr as the target platform.
239+
fn setup_zephyr(&self) -> BuildResult {
240+
let url = "https://github.com/lf-lang/lf-west-template";
241+
self.setup_template_repo(url)?;
239242
remove_file(".gitignore")?;
240243
remove_dir_all(Path::new(".git"))?;
241-
remove_dir_all(tmp_path)?;
244+
Ok(())
245+
}
246+
247+
// Sets up a LF project with RP2040 MCU as the target platform.
248+
// Initializes a repo using the lf-pico-template
249+
fn setup_rp2040(&self) -> BuildResult {
250+
let url = "https://github.com/lf-lang/lf-pico-template";
251+
// leave git artifacts
252+
self.setup_template_repo(url)?;
242253
Ok(())
243254
}
244255

@@ -247,6 +258,7 @@ impl ConfigFile {
247258
match self.apps[0].platform {
248259
Some(Platform::Native) => self.setup_native(),
249260
Some(Platform::Zephyr) => self.setup_zephyr(),
261+
Some(Platform::RP2040) => self.setup_rp2040(),
250262
_ => Ok(()),
251263
}
252264
} else {

0 commit comments

Comments
 (0)