Skip to content

Commit

Permalink
Update to libyang 3.1.0 and release yang3 0.1.0
Browse files Browse the repository at this point in the history
Support for libyang v2 will continue in the yang2 branch.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Jul 8, 2024
1 parent b3aa9dd commit 3bf04fb
Show file tree
Hide file tree
Showing 28 changed files with 113 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
test:
name: Tests and Coverage Report
env:
yang2_rs: rust_ci_github_actions_workflow
yang_rs: rust_ci_github_actions_workflow
CARGO_INCREMENTAL: 0
RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort
RUSTDOCFLAGS: -Cpanic=abort
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
run: |
cargo install cargo2junit grcov;
cargo test --features bundled $CARGO_OPTIONS -- -Z unstable-options --format json | cargo2junit > results.xml;
grcov . -s . -t lcov --llvm --ignore-not-existing --ignore "/*" --ignore "tests/*" --ignore "examples/*" --ignore "libyang2-sys/*" -o lcov.info;
grcov . -s . -t lcov --llvm --ignore-not-existing --ignore "/*" --ignore "tests/*" --ignore "examples/*" --ignore "libyang3-sys/*" -o lcov.info;
- name: Upload test results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "libyang2-sys/libyang"]
path = libyang2-sys/libyang
[submodule "libyang3-sys/libyang"]
path = libyang3-sys/libyang
url = https://github.com/CESNET/libyang.git
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "yang2"
version = "0.13.1"
name = "yang3"
version = "0.1.0"
authors = ["Renato Westphal <[email protected]>"]
description = "libyang2 bindings for Rust"
description = "libyang3 bindings for Rust"
keywords = ["yang", "libyang"]
edition = "2018"
license = "MIT"
repository = "https://github.com/holo-routing/yang2-rs"
documentation = "https://docs.rs/yang2"
repository = "https://github.com/holo-routing/yang-rs"
documentation = "https://docs.rs/yang3"
readme = "README.md"
categories = ["parser-implementations"]
exclude = ["assets/**"]

[dependencies]
libyang2-sys = { path = "libyang2-sys", version = "0.9.0" }
libyang3-sys = { path = "libyang3-sys", version = "0.1.0" }
bitflags = "2.5"
num-traits = "0.2"
num-derive = "0.4"
Expand All @@ -33,5 +33,5 @@ harness = false

[features]
default = []
use_bindgen = ["libyang2-sys/use_bindgen"]
bundled = ["libyang2-sys/bundled"]
bindgen = ["libyang3-sys/bindgen"]
bundled = ["libyang3-sys/bundled"]
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
# yang2-rs
# yang-rs

[![Crates.io][crates-badge]][crates-url]
[![Documentation][docs-badge]][docs-url]
[![MIT licensed][mit-badge]][mit-url]
[![Build Status][actions-badge]][actions-url]
[![codecov][codecov-badge]][codecov-url]

[crates-badge]: https://img.shields.io/crates/v/yang2.svg
[crates-url]: https://crates.io/crates/yang2
[docs-badge]: https://docs.rs/yang2/badge.svg
[docs-url]: https://docs.rs/yang2
[crates-badge]: https://img.shields.io/crates/v/yang3.svg
[crates-url]: https://crates.io/crates/yang3
[docs-badge]: https://docs.rs/yang3/badge.svg
[docs-url]: https://docs.rs/yang3
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[mit-url]: https://github.com/holo-routing/yang2-rs/blob/master/LICENSE
[actions-badge]: https://github.com/holo-routing/yang2-rs/workflows/CI/badge.svg
[actions-url]: https://github.com/holo-routing/yang2-rs/actions?query=workflow%3ACI+branch%3Amaster
[codecov-badge]: https://codecov.io/gh/holo-routing/yang2-rs/branch/master/graph/badge.svg?token=1KE3JMHG0H
[codecov-url]: https://codecov.io/gh/holo-routing/yang2-rs
[mit-url]: https://github.com/holo-routing/yang-rs/blob/master/LICENSE
[actions-badge]: https://github.com/holo-routing/yang-rs/workflows/CI/badge.svg
[actions-url]: https://github.com/holo-routing/yang-rs/actions?query=workflow%3ACI+branch%3Amaster
[codecov-badge]: https://codecov.io/gh/holo-routing/yang-rs/branch/master/graph/badge.svg?token=1KE3JMHG0H
[codecov-url]: https://codecov.io/gh/holo-routing/yang-rs

Rust bindings for the [libyang2] library.
Rust bindings for the [libyang] library.

For raw FFI bindings for libyang2, see [libyang2-sys].
For raw FFI bindings for libyang, see [libyang-sys].

[libyang2]: https://github.com/CESNET/libyang/tree/libyang2
[libyang2-sys]: https://github.com/holo-routing/yang2-rs/tree/master/libyang2-sys
[libyang]: https://github.com/CESNET/libyang/tree/libyang
[libyang-sys]: https://github.com/holo-routing/yang-rs/tree/master/libyang-sys

#### Cargo.toml

```toml
[dependencies]
yang2 = "0.13"
yang3 = "0.1"
```
## Design Goals
* Provide high-level bindings for libyang2 using idiomatic Rust
* Provide high-level bindings for libyang using idiomatic Rust
* Leverage Rust's ownership system to detect API misuse problems at compile time
* Automatic resource management
* Zero-cost abstractions

## Feature flags
By default, yang2-rs uses pre-generated FFI bindings and uses dynamic linking to load libyang2. The following feature flags, however, can be used to change that behavior:
* **bundled**: instructs cargo to download and build libyang2 from the sources. The resulting objects are grouped into a static archive linked to this crate. This feature can be used when having a libyang2 dynamic link dependency isn't desirable.
By default, yang-rs uses pre-generated FFI bindings and uses dynamic linking to load libyang. The following feature flags, however, can be used to change that behavior:
* **bundled**: instructs cargo to download and build libyang from the sources. The resulting objects are grouped into a static archive linked to this crate. This feature can be used when having a libyang dynamic link dependency isn't desirable.
* Additional build requirements: *cc 1.0*, *cmake 0.1*, a C compiler and CMake.
* **use_bindgen**: generate new C FFI bindings dynamically instead of using the pre-generated ones. Useful when updating this crate to use newer libyang2 versions.
* **use_bindgen**: generate new C FFI bindings dynamically instead of using the pre-generated ones. Useful when updating this crate to use newer libyang versions.
* Additional build requirements: *bindgen 0.68.0*

## Example
Expand All @@ -50,8 +50,8 @@ it to the XML format:
```rust,no_run
use std::sync::Arc;
use std::fs::File;
use yang2::context::{Context, ContextFlags};
use yang2::data::{
use yang3::context::{Context, ContextFlags};
use yang3::data::{
Data, DataFormat, DataParserFlags, DataPrinterFlags, DataTree,
DataValidationFlags,
};
Expand Down Expand Up @@ -98,14 +98,14 @@ fn main() -> std::io::Result<()> {
Note the `NO_STATE` flag passed to `parse_file` since the example json file does not contain state data.
More examples can be found [here][examples].

[examples]: https://github.com/holo-routing/yang2-rs/tree/master/examples
[examples]: https://github.com/holo-routing/yang-rs/tree/master/examples

## License

This project is licensed under the [MIT license].

[MIT license]: https://github.com/holo-routing/yang2-rs/blob/master/LICENSE
[MIT license]: https://github.com/holo-routing/yang-rs/blob/master/LICENSE

### Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/holo-routing/yang2-rs.
Bug reports and pull requests are welcome on GitHub at https://github.com/holo-routing/yang-rs.
4 changes: 2 additions & 2 deletions benches/data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use yang2::context::{Context, ContextFlags};
use yang2::data::{Data, DataDiffFlags, DataTree, DataValidationFlags};
use yang3::context::{Context, ContextFlags};
use yang3::data::{Data, DataDiffFlags, DataTree, DataValidationFlags};

static SEARCH_DIR: &str = "./assets/yang/";

Expand Down
4 changes: 2 additions & 2 deletions examples/data_diff.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;
use yang2::context::{Context, ContextFlags};
use yang2::data::{
use yang3::context::{Context, ContextFlags};
use yang3::data::{
Data, DataDiffFlags, DataFormat, DataParserFlags, DataPrinterFlags,
DataTree, DataValidationFlags,
};
Expand Down
4 changes: 2 additions & 2 deletions examples/data_edit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::sync::Arc;
use yang2::context::{Context, ContextFlags};
use yang2::data::{
use yang3::context::{Context, ContextFlags};
use yang3::data::{
Data, DataFormat, DataParserFlags, DataPrinterFlags, DataTree,
DataValidationFlags,
};
Expand Down
4 changes: 2 additions & 2 deletions examples/data_iteration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::sync::Arc;
use yang2::context::{Context, ContextFlags};
use yang2::data::{
use yang3::context::{Context, ContextFlags};
use yang3::data::{
Data, DataFormat, DataParserFlags, DataTree, DataValidationFlags,
};

Expand Down
4 changes: 2 additions & 2 deletions examples/data_json2xml.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::sync::Arc;
use yang2::context::{Context, ContextFlags};
use yang2::data::{
use yang3::context::{Context, ContextFlags};
use yang3::data::{
Data, DataFormat, DataParserFlags, DataPrinterFlags, DataTree,
DataValidationFlags,
};
Expand Down
4 changes: 2 additions & 2 deletions examples/schema_iteration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use yang2::context::{Context, ContextFlags};
use yang2::schema::SchemaPathFormat;
use yang3::context::{Context, ContextFlags};
use yang3::schema::SchemaPathFormat;

static SEARCH_DIR: &str = "./assets/yang/";
static MODULE_NAME: &str = "ietf-isis";
Expand Down
4 changes: 2 additions & 2 deletions examples/schema_yang2yin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use yang2::context::{Context, ContextFlags};
use yang2::schema::{SchemaOutputFormat, SchemaPrinterFlags};
use yang3::context::{Context, ContextFlags};
use yang3::schema::{SchemaOutputFormat, SchemaPrinterFlags};

static SEARCH_DIR: &str = "./assets/yang/";
static MODULE_NAME: &str = "ietf-routing";
Expand Down
1 change: 0 additions & 1 deletion libyang2-sys/libyang
Submodule libyang deleted from 4c7334
18 changes: 9 additions & 9 deletions libyang2-sys/Cargo.toml → libyang3-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "libyang2-sys"
version = "0.9.0"
name = "libyang3-sys"
version = "0.1.0"
authors = ["Renato Westphal <[email protected]>"]
description = "Raw FFI bindings for libyang2"
description = "Raw FFI bindings for libyang3"
keywords = ["yang", "libyang"]
edition = "2018"
license = "MIT"
documentation = "https://docs.rs/libyang2-sys"
documentation = "https://docs.rs/libyang3-sys"
categories = ["external-ffi-bindings"]

[dependencies]
Expand All @@ -21,8 +21,8 @@ pkg-config = "0.3.27"
# Use pre-generated FFI bindings
default = []
# Generate FFI bindings dynamically.
# For this to work libyang2 needs to be installed in the system.
use_bindgen = ["bindgen"]
# Bundle libyang2 C files into a static archive linked to this crate.
# This removes the libyang2 dynamic link dependency.
bundled = ["cc", "cmake"]
# For this to work libyang3 needs to be installed in the system.
bindgen = ["dep:bindgen"]
# Bundle libyang3 C files into a static archive linked to this crate.
# This removes the libyang3 dynamic link dependency.
bundled = ["dep:cc", "dep:cmake"]
File renamed without changes.
19 changes: 10 additions & 9 deletions libyang2-sys/build.rs → libyang3-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::path::PathBuf;

fn main() {
let dst = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_file = dst.join("libyang2.rs");
let out_file = dst.join("libyang3.rs");

#[cfg(feature = "use_bindgen")]
#[cfg(feature = "bindgen")]
{
// Generate Rust FFI to libfrr.
println!("cargo:rerun-if-changed=wrapper.h");
Expand All @@ -14,21 +14,21 @@ fn main() {
.derive_default(true)
.default_enum_style(bindgen::EnumVariation::ModuleConsts)
.generate()
.expect("Unable to generate libyang2 bindings");
.expect("Unable to generate libyang3 bindings");
bindings
.write_to_file(out_file)
.expect("Couldn't write libyang2 bindings!");
.expect("Couldn't write libyang3 bindings!");
}
#[cfg(not(feature = "use_bindgen"))]
#[cfg(not(feature = "bindgen"))]
{
let mut pregen_bindings = PathBuf::new();
pregen_bindings.push(env::var("CARGO_MANIFEST_DIR").unwrap());
pregen_bindings.push("pre-generated-bindings");
pregen_bindings
.push("libyang2-4c733412e7173219166be7053940326a92699765.rs");
.push("libyang3-fba28260f382d81cf8f4b91b24cd717b52324fc2.rs");

std::fs::copy(&pregen_bindings, &out_file)
.expect("Unable to copy pre-generated libyang2 bindings");
.expect("Unable to copy pre-generated libyang3 bindings");
}

#[cfg(feature = "bundled")]
Expand All @@ -46,11 +46,12 @@ fn main() {
// Run cmake.
let cmake_dst = cmake::build("libyang");

// Build libyang2.
// Build libyang3.
let mut build = cc::Build::new();
build
.include(format!("{}/build/compat", cmake_dst.display()))
.include(format!("{}/build/src", cmake_dst.display()))
.include(format!("{}/build/libyang", cmake_dst.display()))
.include("libyang/src")
.include("libyang/src/plugins_exts")
.file("libyang/compat/compat.c")
Expand Down Expand Up @@ -130,7 +131,7 @@ fn main() {
.file("libyang/src/xpath.c")
.warnings(false);

build.compile("yang2");
build.compile("yang3");
println!("cargo:root={}", env::var("OUT_DIR").unwrap());
if let Err(e) = pkg_config::Config::new().probe("libpcre2-8") {
println!("cargo:warning=failed to find pcre2 library with pkg-config: {}", e);
Expand Down
1 change: 1 addition & 0 deletions libyang3-sys/libyang
Submodule libyang added at fba282
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,9 @@ pub const LYD_VALHINT_BOOLEAN: u32 = 32;
pub const LYD_VALHINT_EMPTY: u32 = 64;
pub const LYD_NODEHINT_LIST: u32 = 128;
pub const LYD_NODEHINT_LEAFLIST: u32 = 256;
pub const LYD_HINT_DATA: u32 = 499;
pub const LYD_HINT_SCHEMA: u32 = 511;
pub const LYD_NODEHINT_CONTAINER: u32 = 512;
pub const LYD_HINT_DATA: u32 = 1011;
pub const LYD_HINT_SCHEMA: u32 = 1023;
pub const LYD_NEW_VAL_OUTPUT: u32 = 1;
pub const LYD_NEW_VAL_STORE_ONLY: u32 = 2;
pub const LYD_NEW_VAL_BIN: u32 = 4;
Expand Down Expand Up @@ -25082,6 +25083,9 @@ extern "C" {
extern "C" {
pub fn lyd_node_schema(node: *const lyd_node) -> *const lysc_node;
}
extern "C" {
pub fn lyd_meta_is_internal(meta: *const lyd_meta) -> ly_bool;
}
extern "C" {
pub fn lyd_new_inner(
parent: *mut lyd_node,
Expand Down Expand Up @@ -26764,7 +26768,7 @@ impl Default for lysp_stmt {
#[derive(Debug, Copy, Clone)]
pub struct lysp_ext_substmt {
pub stmt: ly_stmt::Type,
pub storage: *mut ::std::os::raw::c_void,
pub storage: u64,
}
#[test]
fn bindgen_test_layout_lysp_ext_substmt() {
Expand Down Expand Up @@ -26998,7 +27002,7 @@ impl Default for lysp_ext_instance {
#[derive(Debug, Copy, Clone)]
pub struct lysc_ext_substmt {
pub stmt: ly_stmt::Type,
pub storage: *mut ::std::os::raw::c_void,
pub storage: u64,
}
#[test]
fn bindgen_test_layout_lysc_ext_substmt() {
Expand Down
2 changes: 1 addition & 1 deletion libyang2-sys/src/lib.rs → libyang3-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
deref_nullptr,
)]

include!(concat!(env!("OUT_DIR"), "/libyang2.rs"));
include!(concat!(env!("OUT_DIR"), "/libyang3.rs"));
File renamed without changes.
6 changes: 3 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) The yang2-rs Core Contributors
// Copyright (c) The yang-rs Core Contributors
//
// SPDX-License-Identifier: MIT
//
Expand All @@ -19,13 +19,13 @@ use crate::error::{Error, Result};
use crate::iter::{SchemaModules, Set};
use crate::schema::{SchemaModule, SchemaNode};
use crate::utils::*;
use libyang2_sys as ffi;
use libyang3_sys as ffi;

/// Context of the YANG schemas.
///
/// [Official C documentation]
///
/// [Official C documentation]: https://netopeer.liberouter.org/doc/libyang/libyang2/html/howto_context.html
/// [Official C documentation]: https://netopeer.liberouter.org/doc/libyang/master/html/howto_context.html
#[derive(Debug, PartialEq)]
pub struct Context {
pub(crate) raw: *mut ffi::ly_ctx,
Expand Down
Loading

0 comments on commit 3bf04fb

Please sign in to comment.