-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Librarify #50
Draft
petervdonovan
wants to merge
11
commits into
main
Choose a base branch
from
librarify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Librarify #50
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2c2a9c1
Begin to support use of lingo as a library
petervdonovan 7e24f79
Make LfcJsonArgs public.
petervdonovan f77354a
Isolate deps that can't wasm
petervdonovan cec460d
Capabilitify read_to_string
petervdonovan 92ec3ab
Rename lingua-franca -> lingo for package name
petervdonovan cbb0b2e
Use lifetimes to improve restriction on capability
petervdonovan f5153d3
Make logging externally configurable
petervdonovan 3ebb401
Minor updates, including making CCpp a target
petervdonovan 5fb461c
init: lingo dependency management
tanneberger 05edd2e
formatting and preparing for merge
tanneberger 48f7451
merging dependency-managment
tanneberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,18 @@ use clap::{Args, Parser, Subcommand}; | |
use serde_derive::{Deserialize, Serialize}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, PartialEq)] | ||
#[clap(rename_all = "lowercase")] | ||
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)] | ||
#[value(rename_all = "lowercase")] | ||
pub enum TargetLanguage { | ||
C, | ||
CCpp, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
Cpp, | ||
Rust, | ||
TypeScript, | ||
Python, | ||
} | ||
|
||
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, PartialEq)] | ||
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)] | ||
pub enum Platform { | ||
Native, | ||
Zephyr, | ||
|
@@ -32,40 +33,39 @@ pub enum BuildSystem { | |
#[derive(Args, Debug)] | ||
pub struct BuildArgs { | ||
/// Which build system to use | ||
/// TODO: discuss this | ||
#[clap(short, long)] | ||
#[arg(short, long)] | ||
pub build_system: Option<BuildSystem>, | ||
|
||
/// Which target to build | ||
#[clap(short, long)] | ||
#[arg(short, long)] | ||
pub language: Option<TargetLanguage>, | ||
|
||
/// Overwrites any possible board definition in Lingo.toml | ||
#[clap(long)] | ||
#[arg(long)] | ||
pub platform: Option<Platform>, | ||
|
||
/// Tell lingo where the lfc toolchain can be found | ||
#[clap(long)] | ||
#[arg(long)] | ||
pub lfc: Option<PathBuf>, | ||
|
||
/// Skips building aka invoking the build system so it only generates code | ||
#[clap(short, long, action)] | ||
#[arg(short, long)] | ||
pub no_compile: bool, | ||
|
||
/// If one of the apps fails to build dont interrupt the build process | ||
#[clap(short, long, action)] | ||
#[arg(short, long)] | ||
pub keep_going: bool, | ||
|
||
/// Compiles the binaries with optimizations turned on and strips debug symbols | ||
#[clap(short, long, action)] | ||
#[arg(short, long)] | ||
pub release: bool, | ||
|
||
/// List of apps to build if left empty all apps are built | ||
#[clap(short, long, value_delimiter = ',')] | ||
#[arg(short, long, value_delimiter = ',')] | ||
pub apps: Vec<String>, | ||
|
||
/// Number of threads to use for parallel builds. Zero means it will be determined automatically. | ||
#[clap(short, long, default_value_t = 0)] | ||
#[arg(short, long, default_value_t = 0)] | ||
pub threads: usize, | ||
} | ||
|
||
|
@@ -81,9 +81,9 @@ impl BuildArgs { | |
|
||
#[derive(Args, Debug)] | ||
pub struct InitArgs { | ||
#[clap(value_enum, short, long)] | ||
#[arg(value_enum, short, long)] | ||
pub language: Option<TargetLanguage>, | ||
#[clap(value_enum, short, long, default_value_t = Platform::Native)] | ||
#[arg(value_enum, short, long, default_value_t = Platform::Native)] | ||
pub platform: Platform, | ||
} | ||
|
||
|
@@ -120,20 +120,20 @@ pub enum Command { | |
} | ||
|
||
#[derive(Parser)] | ||
#[clap(name = "Lingua Franca package manager and build tool")] | ||
#[clap(author = "[email protected]")] | ||
#[clap(version = env!("CARGO_PKG_VERSION"))] | ||
#[clap(about = "Build system for the Lingua Franca coordination language", long_about = None)] | ||
#[command(name = "Lingua Franca package manager and build tool")] | ||
#[command(author = "[email protected]")] | ||
#[command(version = env!("CARGO_PKG_VERSION"))] | ||
#[command(about = "Build system for the Lingua Franca coordination language", long_about = None)] | ||
pub struct CommandLineArgs { | ||
/// which command of lingo to use | ||
#[clap(subcommand)] | ||
pub command: Command, | ||
|
||
/// lingo wouldn't produce any output | ||
#[clap(short, long, action)] | ||
#[arg(short, long)] | ||
pub quiet: bool, | ||
|
||
/// lingo will give more detailed feedback | ||
#[clap(short, long, action)] | ||
#[arg(short, long)] | ||
pub verbose: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
use std::fs; | ||
use std::io::Write; | ||
use std::process::Command; | ||
|
||
use crate::backends::{ | ||
BatchBackend, BatchBuildResults, BuildCommandOptions, BuildProfile, BuildResult, CommandSpec, | ||
}; | ||
use crate::util::errors::LingoError; | ||
use crate::util::execute_command_to_build_result; | ||
use crate::package::App; | ||
|
||
pub struct CmakeC; | ||
|
||
fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult { | ||
let build_dir = app.output_root.join("build"); | ||
fs::create_dir_all(&build_dir)?; | ||
|
||
// location of the cmake file | ||
let app_build_folder = app.src_gen_dir().join(&app.main_reactor_name); | ||
let _ = std::fs::create_dir_all(&app_build_folder); | ||
let cmake_file = app_build_folder.clone().join("CMakeLists.txt"); | ||
|
||
// create potential files that come from the target properties | ||
app.properties | ||
.write_artifacts(&app_build_folder) | ||
.expect("cannot write artifacts"); | ||
|
||
// read file and append cmake include to generated cmake file | ||
let mut content = fs::read_to_string(&cmake_file)?; | ||
let include_statement = "\ninclude(./aggregated_cmake_include.cmake)"; | ||
content += include_statement; | ||
|
||
// overwrite cmake file | ||
let mut f = fs::OpenOptions::new() | ||
.write(true) | ||
.open(&cmake_file) | ||
.expect("cannot open file"); | ||
f.write_all(content.as_ref()).expect("cannot write file"); | ||
f.flush().expect("cannot flush"); | ||
|
||
// cmake args | ||
let mut cmake = Command::new("cmake"); | ||
cmake.arg(format!( | ||
"-DCMAKE_BUILD_TYPE={}", | ||
if options.profile == BuildProfile::Release { | ||
"RELEASE" | ||
} else { | ||
"DEBUG" | ||
} | ||
)); | ||
cmake.arg(format!( | ||
"-DCMAKE_INSTALL_PREFIX={}", | ||
app.output_root.display() | ||
)); | ||
cmake.arg("-DCMAKE_INSTALL_BINDIR=bin"); | ||
cmake.arg(&app_build_folder); | ||
cmake.arg(format!("-B {}", app_build_folder.display())); | ||
cmake.current_dir(&build_dir); | ||
|
||
execute_command_to_build_result(cmake) | ||
} | ||
|
||
fn do_cmake_build(results: &mut BatchBuildResults, options: &BuildCommandOptions) { | ||
// open lingo.toml of the dependency | ||
// read the version | ||
// cry loud when it doesn't match out specified version | ||
|
||
results.keep_going(options.keep_going); | ||
super::lfc::LFC::do_parallel_lfc_codegen(options, results, false); | ||
if !options.compile_target_code { | ||
return; | ||
} | ||
results | ||
// generate all CMake files ahead of time | ||
.map(|app| gen_cmake_files(app, options)) | ||
// Run cmake to build everything. | ||
.map(|app| { | ||
let app_build_folder = app.src_gen_dir().join(&app.main_reactor_name); | ||
|
||
// compile everything | ||
let mut cmake = Command::new("cmake"); | ||
cmake.current_dir(&app_build_folder); | ||
cmake.args(["--build", "."]); | ||
|
||
// add one target arg for each app | ||
let name = app | ||
.main_reactor | ||
.file_stem() | ||
.ok_or(LingoError::InvalidMainReactor)?; | ||
cmake.arg("--target"); | ||
cmake.arg(name); | ||
|
||
execute_command_to_build_result(cmake) | ||
}) | ||
.map(|app| { | ||
let bin_source = app | ||
.src_gen_dir() | ||
.join(&app.main_reactor_name) | ||
.join(&app.main_reactor_name); | ||
fs::rename(bin_source, app.executable_path())?; | ||
Ok(()) | ||
}); | ||
} | ||
|
||
impl BatchBackend for CmakeC { | ||
fn execute_command(&mut self, command: &CommandSpec, results: &mut BatchBuildResults) { | ||
match command { | ||
CommandSpec::Build(options) => do_cmake_build(results, options), | ||
CommandSpec::Clean => { | ||
results.par_map(|app| { | ||
crate::util::default_build_clean(&app.output_root)?; | ||
Ok(()) | ||
}); | ||
} | ||
_ => todo!(), | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave it as lingua-franca because we still want to squat that name on crates.io ;D