Skip to content

Commit

Permalink
fix docs.rs build
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Aug 30, 2024
1 parent b9e1918 commit 65345a0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ocaml"
version = "1.0.0"
version = "1.0.1"
authors = ["Zach Shipko <zachshipko@gmail.com>"]
readme = "README.md"
keywords = ["ocaml", "rust", "ffi"]
Expand All @@ -11,17 +11,18 @@ documentation = "https://docs.rs/ocaml"
edition = "2021"

[package.metadata.docs.rs]
features = [ "without-ocamlopt", "derive", "link" ]
no-default-features = true
features = [ "derive", "without-ocamlopt", "ocaml5", "docs-rs" ]

[dependencies]
ocaml-sys = {path = "./sys", version = ">=0.24"}
ocaml-boxroot-sys = {version = "0.3.1"}
ocaml-boxroot-sys = {version = "0.3.1", optional = true}
ocaml-derive = {path = "./derive", optional = true, version = "^1.0.0"}
cstr_core = {version = "0.2", optional = true}
ndarray = {version = "^0.16.1", optional = true}

[features]
default = ["derive"]
default = ["derive", "ocaml-boxroot-sys"]
derive = ["ocaml-derive"]
link = ["ocaml-sys/link"]
without-ocamlopt = [
Expand All @@ -32,6 +33,7 @@ bigarray-ext = ["ndarray"]
no-caml-startup = []
no-panic-hook = []
ocaml5 = ["ocaml-sys/ocaml5"]
docs-rs = []

[workspace]
members = [
Expand Down
45 changes: 42 additions & 3 deletions src/root.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
use crate::sys;

/// Wraps rooted values
pub struct Root(pub ocaml_boxroot_sys::BoxRoot);
pub struct Root(#[cfg(not(feature = "docs-rs"))] pub ocaml_boxroot_sys::BoxRoot);

impl PartialEq for Root {
#[cfg(not(feature = "docs-rs"))]
fn eq(&self, other: &Self) -> bool {
ocaml_boxroot_sys::boxroot_get_ref(self.0) == ocaml_boxroot_sys::boxroot_get_ref(other.0)
}

#[cfg(feature = "docs-rs")]
fn eq(&self, other: &Self) -> bool {
true
}
}

impl PartialOrd for Root {
#[cfg(not(feature = "docs-rs"))]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
ocaml_boxroot_sys::boxroot_get_ref(self.0)
.partial_cmp(&ocaml_boxroot_sys::boxroot_get_ref(other.0))
}

#[cfg(feature = "docs-rs")]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
None
}
}

impl core::fmt::Debug for Root {
#[cfg(not(feature = "docs-rs"))]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
ocaml_boxroot_sys::boxroot_get_ref(self.0).fmt(f)
}

#[cfg(feature = "docs-rs")]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Ok(())
}
}

impl Eq for Root {}

impl Root {
/// Create a new root
pub unsafe fn new(v: sys::Value) -> Root {
Root(ocaml_boxroot_sys::boxroot_create(v).expect("boxroot_create failed"))
Root(
#[cfg(not(feature = "docs-rs"))]
ocaml_boxroot_sys::boxroot_create(v).expect("boxroot_create failed"),
)
}

/// Get value from root
#[cfg(not(feature = "docs-rs"))]
pub unsafe fn get(&self) -> sys::Value {
ocaml_boxroot_sys::boxroot_get(self.0)
}

/// Get value from root
#[cfg(feature = "docs-rs")]
pub unsafe fn get(&self) -> sys::Value {
0
}

/// Modify root
pub unsafe fn modify(&mut self, v: sys::Value) {
#[cfg(not(feature = "docs-rs"))]
if !ocaml_boxroot_sys::boxroot_modify(&mut self.0, v) {
panic!("boxroot_modify failed")
}
}
}

impl Clone for Root {
#[cfg(not(feature = "docs-rs"))]
fn clone(&self) -> Root {
unsafe { Root::new(self.get()) }
}

#[cfg(feature = "docs-rs")]
fn clone(&self) -> Root {
Root()
}
}

impl Drop for Root {
fn drop(&mut self) {
unsafe { ocaml_boxroot_sys::boxroot_delete(self.0) }
#[cfg(not(feature = "docs-rs"))]
unsafe {
ocaml_boxroot_sys::boxroot_delete(self.0)
}
}
}
1 change: 1 addition & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl Runtime {
let c_args = [arg0, core::ptr::null()];
unsafe {
ocaml_sys::caml_startup(c_args.as_ptr());
#[cfg(not(feature = "docs-rs"))]
assert!(ocaml_boxroot_sys::boxroot_setup());
}
}
Expand Down

0 comments on commit 65345a0

Please sign in to comment.