-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
197 additions
and
12 deletions.
There are no files selected for viewing
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,3 @@ | ||
[submodule "raugeas_src/augeas"] | ||
path = raugeas_src/augeas | ||
url = https://github.com/hercules-team/augeas |
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,4 +3,6 @@ resolver = "2" | |
members = [ | ||
"raugeas", | ||
"raugeas_sys", | ||
] | ||
"raugeas_src", | ||
"raugeas_src/testcrate", | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "raugeas_src" | ||
version = "0.2.0+augeas-1.14.1" | ||
authors = ["panicbit <[email protected]>", "Alexis Mousset <[email protected]>"] | ||
description = "Low level bindings for augeas" | ||
license = "MIT" | ||
keywords = ["augeas", "bindings"] | ||
repository = "https://github.com/amousset/rust-augeas" | ||
edition = "2021" | ||
rust-version = "1.77" | ||
|
||
[dependencies] | ||
autotools = "0.2" |
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,79 @@ | ||
//! This crate aims to encapsulate the logic required for building `augeas` | ||
//! from source (so that `augeas-sys` can use it). | ||
use std::env; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
/// Information about the locations of files generated by `build()`. | ||
/// | ||
/// After the jq sources have been compiled, the fields in this struct | ||
/// represent where the various files ended up, and what sort of build was | ||
/// done (ie, static or dynamic). | ||
pub struct Artifacts { | ||
include_dir: PathBuf, | ||
lib_dir: PathBuf, | ||
} | ||
|
||
impl Artifacts { | ||
/// Prints cargo instructions for linking to the bundled `augeas` lib. | ||
pub fn print_cargo_metadata(&self) { | ||
println!("cargo:include={}", self.include_dir.display()); | ||
println!("cargo:rustc-link-search=native={}", self.lib_dir.display()); | ||
println!("cargo:rustc-link-lib=static={}", "augeas"); | ||
} | ||
pub fn include_dir(&self) -> &Path { | ||
&self.include_dir | ||
} | ||
pub fn lib_dir(&self) -> &Path { | ||
&self.lib_dir | ||
} | ||
} | ||
|
||
/// Entry point for callers to run the build. | ||
pub fn build() -> Result<Artifacts, String> { | ||
let out_dir = env::var_os("OUT_DIR") | ||
.map(PathBuf::from) | ||
.expect("OUT_DIR not set"); | ||
|
||
let augeas_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("augeas"); | ||
|
||
autotools::Config::new(&augeas_dir) | ||
.reconf("-iv") | ||
.out_dir(&out_dir) | ||
.enable_static() | ||
.disable_shared() | ||
.try_build()?; | ||
|
||
Ok(Artifacts { | ||
lib_dir: out_dir.join("lib"), | ||
include_dir: out_dir.join("include"), | ||
}) | ||
} | ||
|
||
/// Recursive file copy | ||
fn cp_r(src: &Path, dst: &Path) { | ||
for f in fs::read_dir(src).unwrap() { | ||
let f = f.unwrap(); | ||
let path = f.path(); | ||
let name = path.file_name().unwrap(); | ||
let dst = dst.join(name); | ||
if f.file_type().unwrap().is_dir() { | ||
fs::create_dir_all(&dst).unwrap(); | ||
cp_r(&path, &dst); | ||
} else { | ||
let _ = fs::remove_file(&dst); | ||
fs::copy(&path, &dst).unwrap(); | ||
} | ||
} | ||
} | ||
|
||
/// Cleanup old sources (left from a previous build attempt) then copy from | ||
/// the git submodule into the location where the build will happen. | ||
fn prepare_sources(src: &Path, dst: &Path) { | ||
if dst.exists() { | ||
fs::remove_dir_all(dst).unwrap(); | ||
} | ||
fs::create_dir_all(dst).unwrap(); | ||
cp_r(src, dst); | ||
} |
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,9 @@ | ||
[package] | ||
name = "testcrate" | ||
version = "0.1.0" | ||
authors = ["Alexis Mousset <[email protected]>"] | ||
links = "augeas" | ||
build = "build.rs" | ||
|
||
[build-dependencies] | ||
raugeas_src = { path = ".." } |
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,6 @@ | ||
extern crate raugeas_src; | ||
|
||
fn main() { | ||
let artifacts = raugeas_src::build().unwrap(); | ||
artifacts.print_cargo_metadata(); | ||
} |
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,7 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |
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