1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-24 22:21:43 +02:00

Added trex.json in tar.gz

This commit is contained in:
Anthony Scemama 2023-10-24 19:46:15 +02:00
parent d224396b4c
commit 92e71be956
3 changed files with 72 additions and 88 deletions

View File

@ -34,10 +34,9 @@
ACLOCAL_AMFLAGS = -I m4
CLEANFILES = trexio.mod
BUILT_SOURCES = trex.json
if HAVE_FORTRAN
BUILT_SOURCES = trexio.mod
else
BUILT_SOURCES =
BUILT_SOURCES += trexio.mod
endif
EXTRA_DIST = .git_hash
@ -87,14 +86,63 @@ src_libtrexio_la_SOURCES = $(trexio_h) $(SOURCES)
# Include CMake-related files in the distribution.
EXTRA_DIST += CMakeLists.txt \
trex.json \
src/CMakeLists.txt \
tests/CMakeLists.txt \
tests/test_macros.h \
cmake/cmake_uninstall.cmake.in \
cmake/FindTREXIO.cmake
# =============== TESTS =============== #
TEST_FILES = \
tests/delete_group.c \
tests/delete_group_hdf5.c \
tests/delete_group_text.c \
tests/io_all.c \
tests/io_determinant.c \
tests/io_determinant_hdf5.c \
tests/io_determinant_text.c \
tests/io_dset_float.c \
tests/io_dset_float_hdf5.c \
tests/io_dset_float_text.c \
tests/io_dset_int.c \
tests/io_dset_int_hdf5.c \
tests/io_dset_int_text.c \
tests/io_dset_sparse.c \
tests/io_dset_sparse_hdf5.c \
tests/io_dset_sparse_text.c \
tests/io_dset_str.c \
tests/io_dset_str_hdf5.c \
tests/io_dset_str_text.c \
tests/io_jastrow.c \
tests/io_jastrow_hdf5.c \
tests/io_jastrow_text.c \
tests/io_num.c \
tests/io_num_hdf5.c \
tests/io_num_text.c \
tests/io_safe_dset_float.c \
tests/io_safe_dset_float_hdf5.c \
tests/io_safe_dset_float_text.c \
tests/io_str.c \
tests/io_str_hdf5.c \
tests/io_str_text.c \
tests/open.c \
tests/open_hdf5.c \
tests/open_text.c \
tests/overwrite_all.c \
tests/overwrite_all_hdf5.c \
tests/overwrite_all_text.c \
tests/pre_close.c \
tests/template_hdf5.c \
tests/template_text.c \
tests/test_f.f90 \
tests/test_macros.h \
tests/trexio_f.f90
EXTRA_DIST += $(TEST_FILES)
TESTS_C = \
tests/open_text \
tests/io_num_text \

View File

@ -23,3 +23,4 @@ flate2 = "1.0"
doctest = false
[dependencies]
hdf5 = "0.8.1"

View File

@ -17,50 +17,6 @@ use tar::Archive;
/*
/// Checks that the version specified in the Cargo.toml file is consistent with the version of the TREXIO C library.
fn check_version(bindings: &PathBuf) -> Result<(), String> {
// Read version from Cargo.toml
let mut rust_version = String::new();
{
let file = File::open("Cargo.toml").map_err(|e| e.to_string())?;
let reader = io::BufReader::new(file);
for line in reader.lines() {
let line = line.map_err(|e| e.to_string())?;
if line.starts_with("version") {
rust_version = line.split('=').nth(1).unwrap().trim().to_string();
rust_version = rust_version[1..rust_version.len() - 1].to_string();
break;
}
}
}
// Check version from TREXIO
let mut trexio_version = String::new();
let file = File::open(bindings).map_err(|e| e.to_string())?;
let reader = io::BufReader::new(file);
for line in reader.lines() {
let line = line.map_err(|e| e.to_string())?;
if line.contains("TREXIO_PACKAGE_VERSION") {
trexio_version = line.split('"').nth(1).unwrap().trim().to_string();
trexio_version = trexio_version[0..trexio_version.len() - 2].to_string();
break;
}
}
// Compare versions
if rust_version != trexio_version {
eprintln!("Inconsistent versions:\nTREXIO: {}\nRust: {}\n", trexio_version, rust_version);
return Err("Inconsistent versions".to_string());
}
Ok(())
}
*/
fn download_trexio() -> PathBuf {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let trexio_url = format!("https://github.com/TREX-CoE/trexio/releases/download/v{VERSION}/trexio-{VERSION}.tar.gz");
@ -107,7 +63,6 @@ fn install_trexio(trexio_dir: &PathBuf) -> PathBuf {
assert!(make_status.success());
install_path
}
@ -116,18 +71,6 @@ fn make_interface(trexio_h: &PathBuf) -> io::Result<()> {
let mut err = HashMap::new();
let mut be = HashMap::new();
/*
let mut trexio_h = PathBuf::new().join("trexio.h");
if let Ok(library) = pkg_config::probe_library("trexio") {
for path in &library.include_paths {
if path.join("trexio.h").exists() {
trexio_h = path.join("trexio.h");
break;
}
}
}
*/
let trexio_file = File::open(trexio_h)?;
let trexio_reader = BufReader::new(trexio_file);
@ -165,7 +108,7 @@ fn make_interface(trexio_h: &PathBuf) -> io::Result<()> {
write!(&mut wrapper_file, "const back_end_t {} = {};\n", k, v)?;
}
write!(&mut wrapper_file, "#undef TREXIO_AUTO;\n")?;
write!(&mut wrapper_file, "#undef TREXIO_AUTO\n")?;
write!(&mut wrapper_file, "const back_end_t TREXIO_AUTO = TREXIO_INVALID_BACK_END;\n")?;
Ok(())
@ -698,25 +641,9 @@ pub fn write_{group_l}_{element_l}(&self, offset: usize, data: &[{typ}]) -> Resu
/// Reads the JSON file, processes its contents, and generates Rust functions according to the specifications in the JSON data.
fn make_functions(bindings: &PathBuf) -> std::io::Result<()> {
let file = File::open(bindings)?;
let reader = io::BufReader::new(file);
let mut json_file = String::new();
for line in reader.lines() {
let line = line?;
if line.contains("trexio_json") {
let index_start = match line.find('{') {
Some(x) => x,
_ => panic!("trexio_json not found"),
};
json_file = line[index_start..line.len()-5]
.replace(r#"\""#,"\"")
.replace(r#"\n"#,"\n")
.replace(r#"\t"#,"");
break;
}
}
let data: Value = serde_json::from_str(&json_file).unwrap();
fn make_functions(json_path: &PathBuf) -> std::io::Result<()> {
let file = File::open(json_path).unwrap();
let data: Value = serde_json::from_reader(file).unwrap();
let mut r: Vec<String> = vec![
String::from("
@ -750,8 +677,11 @@ impl File {
fn main() {
let path = download_trexio();
let install_path = install_trexio(&path);
let source_path = download_trexio();
println!("source path: {}", source_path.display());
let install_path = install_trexio(&source_path);
println!("install path: {}", install_path.display());
// Tell cargo to look for shared libraries in the specified directory
println!("cargo:rustc-link-search={}/lib", install_path.display());
@ -759,17 +689,17 @@ fn main() {
// Tell cargo to tell rustc to link the system trexio shared library.
println!("cargo:rustc-link-lib=trexio");
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let trexio_h = install_path.join("include").join("trexio.h");
println!("trexio.h: {}", trexio_h.display());
make_interface(&trexio_h).unwrap();
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let wrapper_h = out_path.join("wrapper.h");
let wrapper_h = out_path.join(WRAPPER_H);
println!("wrapper.h: {}", wrapper_h.display());
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
@ -784,9 +714,14 @@ fn main() {
// Write the bindings to the $OUT_DIR/bindings.rs file.
let bindings_path = out_path.join("bindings.rs");
println!("bindings.rs: {}", bindings_path.display());
bindings
.write_to_file(&bindings_path)
.expect("Couldn't write bindings!");
// check_version(&bindings_path).unwrap();
make_functions(&bindings_path).unwrap();
let json_path = source_path.join("trex.json");
println!("json path: {}", json_path.display());
make_functions(&json_path).unwrap();
}