Compare commits
3 Commits
v1.0.6
...
working/#1
| Author | SHA1 | Date | |
|---|---|---|---|
| e25c27f082 | |||
| f30432c1db | |||
| 1b34dee81e |
24
README.md
24
README.md
@@ -6,11 +6,29 @@ This is a toy project not meant to be taken very seriously.
|
||||
|
||||
## Requirements for Use
|
||||
|
||||
[GCC](https://en.wikipedia.org/wiki/GNU_Compiler_Collection) is required as it is currently the back-end tool used to compile the C code.
|
||||
[GCC](https://en.wikipedia.org/wiki/GNU_Compiler_Collection) is recommended as the compiler installed for `Pallet` projects.
|
||||
|
||||
This tool calls `gcc` internally, so without it, it would fail.
|
||||
You can define a different `gcc` compatible compiler instead per-project by editing `Pallet.toml`:
|
||||
|
||||
At some point I would like to update `Pallet.toml` to instead allow more configuring of how the build should be performed.
|
||||
```toml
|
||||
name = "my-app"
|
||||
default_build = "debug"
|
||||
compiler = "clang"
|
||||
|
||||
[[build]]
|
||||
name = "debug"
|
||||
args = [
|
||||
"-g",
|
||||
"-O0",
|
||||
]
|
||||
|
||||
[[build]]
|
||||
name = "release"
|
||||
args = [
|
||||
"-DNDEBUG",
|
||||
"-O3",
|
||||
]
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
71
src/app.rs
71
src/app.rs
@@ -9,6 +9,7 @@ use colored::Colorize;
|
||||
use glob::glob;
|
||||
|
||||
const MAIN_C: &str = include_str!("templates/main.c");
|
||||
const TEST_C: &str = include_str!("templates/it_works.c");
|
||||
const GITIGNORE: &str = "target/";
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
@@ -53,6 +54,11 @@ enum Subcommand {
|
||||
#[clap(subcommand)]
|
||||
command: UtilSubcommand,
|
||||
},
|
||||
/// Run tests in your project
|
||||
Test {
|
||||
/// The build mode to use
|
||||
mode: Option<String>,
|
||||
},
|
||||
/// List available build modes
|
||||
List,
|
||||
}
|
||||
@@ -78,31 +84,26 @@ enum ShellCompletions {
|
||||
impl App {
|
||||
pub fn run(self) {
|
||||
match self.command {
|
||||
Subcommand::New { name } => match create_project(&name) {
|
||||
Err(e) => {
|
||||
Subcommand::New { name } => {
|
||||
if let Err(e) = create_project(&name) {
|
||||
eprintln!("Error creating project '{name}': {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Subcommand::Init => match create_project(".") {
|
||||
Err(e) => {
|
||||
}
|
||||
Subcommand::Init => {
|
||||
if let Err(e) = create_project(".") {
|
||||
eprintln!("Error initializing project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
Subcommand::Run {
|
||||
mode,
|
||||
args,
|
||||
force_recompile,
|
||||
} => {
|
||||
match build(&mode, force_recompile) {
|
||||
Err(e) => {
|
||||
if let Err(e) = build(&mode, force_recompile) {
|
||||
eprintln!("Error building project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
if let Err(e) = run(&mode, args) {
|
||||
eprintln!("Error running project: {e}");
|
||||
@@ -112,20 +113,18 @@ impl App {
|
||||
Subcommand::Build {
|
||||
mode,
|
||||
force_recompile,
|
||||
} => match build(&mode, force_recompile) {
|
||||
Err(e) => {
|
||||
} => {
|
||||
if let Err(e) = build(&mode, force_recompile) {
|
||||
eprintln!("Error building project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Subcommand::Clean => match clean() {
|
||||
Err(e) => {
|
||||
}
|
||||
Subcommand::Clean => {
|
||||
if let Err(e) = clean() {
|
||||
eprintln!("Error cleaning project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
Subcommand::Utils { command } => match command {
|
||||
UtilSubcommand::Completions { shell } => {
|
||||
let name = env!("CARGO_PKG_NAME");
|
||||
@@ -158,15 +157,28 @@ impl App {
|
||||
}
|
||||
}
|
||||
},
|
||||
Subcommand::List => match list() {
|
||||
Err(e) => {
|
||||
Subcommand::List => {
|
||||
if let Err(e) = list() {
|
||||
eprintln!("Error listing build profiles: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
Subcommand::Test { mode } => {
|
||||
if let Err(e) = test(mode) {
|
||||
eprintln!("Error running tests: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test(mode: Option<String>) -> std::io::Result<()> {
|
||||
for entry in glob("src/tests/*.c").expect("a valid glob pattern") {
|
||||
if let Ok(file) = entry {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list() -> std::io::Result<()> {
|
||||
@@ -292,9 +304,14 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
|
||||
.arg("-o")
|
||||
.arg(format!("target/{}/{}", build_config.name, conf.name));
|
||||
|
||||
let mut child = command.spawn()?;
|
||||
let status = command.status()?;
|
||||
|
||||
child.wait()?;
|
||||
if !status.success() {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("compiler exited with status {status}"),
|
||||
));
|
||||
}
|
||||
|
||||
std::fs::write(format!("target/{}/.build_hash", build_config.name), hash)?;
|
||||
|
||||
@@ -360,7 +377,7 @@ fn run(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()>
|
||||
}
|
||||
|
||||
fn clean() -> std::io::Result<()> {
|
||||
if let None = get_config() {
|
||||
if get_config().is_none() {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
"no Pallet.toml found in local dir",
|
||||
|
||||
7
src/templates/it_works.c
Normal file
7
src/templates/it_works.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
assert((1 + 1) == 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user