Skip to content

Commit

Permalink
clean up and update of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Erk- committed Jan 28, 2023
1 parent 51c4614 commit 0c8ca80
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 50 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ readme = "README.md"
repository = "https://github.com/Erk-/genfut"

[dependencies]
bindgen = "0.60.0"
cc = "1.0.73"
bindgen = "0.63.0"
cc = "1.0.78"
Inflector = "0.11.4"
regex = "1"
clap = { version = "3.2.4", features = ["derive"] }
regex = "1.7.1"
clap = { version = "4.1.4", features = ["derive"] }

[features]
default = []
6 changes: 3 additions & 3 deletions examples/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Binary to generate the matmul library
extern crate genfut;
use genfut::{genfut, Backend, Opt};
use genfut::{genfut, Backend, Options};

fn main() {
genfut(Opt {
genfut(Options {
name: "matmul".to_string(),
file: std::path::PathBuf::from("matmul.fut"),
file: std::path::PathBuf::from("./matmul.fut"),
author: "Name <[email protected]>".to_string(),
version: "0.1.0".to_string(),
license: "MIT".to_string(),
Expand Down
15 changes: 5 additions & 10 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use regex::Regex;

fn type_translation(input: &str) -> String {
if input.starts_with("futhark") {
auto_ctor(&input)
auto_ctor(input)
} else {
let mut buffer = String::new();
if input.starts_with("int8") {
Expand Down Expand Up @@ -66,7 +66,7 @@ pub(crate) fn gen_entry_point(input: &str) -> (String, String, Vec<String>) {
write!(&mut buffer, "(&mut self, ");
for (i, (argtype, argname)) in arg_pairs.iter().enumerate() {
if argname.starts_with("in") {
let argtype_string = type_translation(argtype.clone());
let argtype_string = type_translation(argtype);
write!(
&mut buffer,
"{}: {}{}, ",
Expand All @@ -89,7 +89,7 @@ pub(crate) fn gen_entry_point(input: &str) -> (String, String, Vec<String>) {
write!(&mut output_buffer, ", ");
}
output_counter += 1;
write!(&mut output_buffer, "{}", type_translation(argtype.clone()));
write!(&mut output_buffer, "{}", type_translation(argtype));
}
}
write!(&mut output_buffer, ")>");
Expand Down Expand Up @@ -123,12 +123,7 @@ pub(crate) fn gen_entry_point(input: &str) -> (String, String, Vec<String>) {
if argtype.starts_with("futhark") {
write!(&mut buffer2, "{}: *const bindings::{}, ", argname, argtype);
} else {
write!(
&mut buffer2,
"{}: {}, ",
argname,
type_translation(argtype.clone())
);
write!(&mut buffer2, "{}: {}, ", argname, type_translation(argtype));
}
}
}
Expand All @@ -146,7 +141,7 @@ pub(crate) fn gen_entry_point(input: &str) -> (String, String, Vec<String>) {
&mut buffer2,
"let mut raw_{} = {}::default();",
argname,
type_translation(argtype.clone())
type_translation(argtype)
);
}
}
Expand Down
58 changes: 28 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@
//!
//!`build.rs`
//!```rust, no_run
//!use genfut::{Opt, genfut};
//!
//!fn main() {
//! genfut(Opt {
//! name: "<Rust lib name>".to_string(),
//! file: std::path::PathBuf::from("futhark_file.fut"),
//! author: "Name <[email protected]>".to_string(),
//! version: "0.1.0".to_string(),
//! license: "YOLO".to_string(),
//! description: "Futhark example".to_string(),
//! })
//!}
//! use genfut::{Opt, genfut};
//!
//! genfut(Opt {
//! name: "<Rust lib name>".to_string(),
//! file: std::path::PathBuf::from("futhark_file.fut"),
//! author: "Name <[email protected]>".to_string(),
//! version: "0.1.0".to_string(),
//! license: "YOLO".to_string(),
//! description: "Futhark example".to_string(),
//! })
//!```
#![allow(unused_must_use)]
#![allow(unused_variables)]
#![allow(clippy::uninlined_format_args)]

use clap::Parser;
use std::fs::create_dir_all;
Expand All @@ -49,44 +47,44 @@ pub use crate::genc::Backend;
use crate::genc::{gen_c, generate_bindings};

#[derive(Parser, Debug)]
#[clap(author, version, about)]
pub struct Opt {
#[command(author, version, about)]
pub struct Options {
/// Output dir
#[clap(name = "NAME")]
#[arg(name = "NAME")]
pub name: String,

/// File to process
#[clap(name = "FILE", parse(from_os_str))]
#[arg(name = "FILE")]
pub file: PathBuf,

/// License
#[clap(long, name = "LICENSE", default_value = "MIT")]
#[arg(long, name = "LICENSE", default_value = "MIT")]
pub license: String,

/// Author
#[clap(long, name = "AUTHOR", default_value = "Name <[email protected]>")]
#[arg(long, name = "AUTHOR", default_value = "Name <[email protected]>")]
pub author: String,

/// Version
#[clap(long, name = "VERSION", default_value = "0.1.0")]
#[arg(long, name = "VERSION", default_value = "0.1.0")]
pub version: String,

/// Description
#[clap(
#[arg(
long,
name = "DESCRIPTION",
default_value = "Rust interface to Futhark library"
)]
pub description: String,

/// Backend
#[clap(long, name = "BACKEND", default_value = "c")]
#[arg(long, name = "BACKEND", default_value = "c")]
pub backend: Backend,
}

pub fn genfut(opt: Opt) {
let name = opt.name;
let futhark_file = &opt.file;
pub fn genfut(options: Options) {
let name = options.name;
let futhark_file = &options.file;
let out_dir_str: String = format!("./{}", name);
let out_dir = Path::new(&out_dir_str);

Expand All @@ -112,7 +110,7 @@ pub fn genfut(opt: Opt) {

// Generate C code, Though only headerfiles are needed.
// In general C files are generated when build at the user.
gen_c(opt.backend, futhark_file, out_dir);
gen_c(options.backend, futhark_file, out_dir);

// copy futhark file
if let Err(e) = std::fs::copy(futhark_file, PathBuf::from(out_dir).join("lib/a.fut")) {
Expand Down Expand Up @@ -156,11 +154,11 @@ pub fn genfut(opt: Opt) {
let static_cargo = format!(
include_str!("static/static_cargo.toml"),
libname = name,
description = &opt.description,
author = &opt.author,
version = &opt.version,
license = &opt.license,
backend = opt.backend.to_feature(),
description = &options.description,
author = &options.author,
version = &options.version,
license = &options.license,
backend = options.backend.to_feature(),
);
let mut cargo_file =
File::create(PathBuf::from(out_dir).join("Cargo.toml")).expect("File creation failed!");
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Parser;
use genfut::{genfut, Opt};
use genfut::{genfut, Options};

fn main() {
let opt = Opt::parse();
let opt = Options::parse();
genfut(opt);
}
2 changes: 1 addition & 1 deletion src/static/static_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl FutharkContext {
}
}

// calling free() will cause any new calls using this context to fail
/// Calling free() will cause any new calls using this context to fail
// TODO: free should take Self as an argument, so that the context cannot
// be used after having been freed.
// See https://github.com/Erk-/genfut/pull/20
Expand Down

0 comments on commit 0c8ca80

Please sign in to comment.