Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docs.rs build #2221

Merged
merged 2 commits into from Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethers-contract/README.md
@@ -1,4 +1,4 @@
# ethers-core
# ethers-contract

Type-safe abstractions for interacting with Ethereum smart contracts.

Expand Down
4 changes: 1 addition & 3 deletions ethers-contract/src/base.rs
@@ -1,12 +1,10 @@
use crate::contract::ContractInstance;

use crate::ContractInstance;
pub use ethers_core::abi::AbiError;
use ethers_core::{
abi::{Abi, Detokenize, Error, Event, Function, FunctionExt, RawLog, Token, Tokenize},
types::{Address, Bytes, Selector, H256},
};
use ethers_providers::Middleware;

use std::{
borrow::Borrow,
collections::{BTreeMap, HashMap},
Expand Down
34 changes: 32 additions & 2 deletions ethers-contract/src/lib.rs
Expand Up @@ -3,8 +3,9 @@
#![deny(unsafe_code)]
#![warn(missing_docs)]

mod contract;
pub use contract::{Contract, ContractInstance};
#[path = "contract.rs"]
mod _contract;
pub use _contract::{Contract, ContractInstance};

mod base;
pub use base::{decode_function_data, encode_function_data, AbiError, BaseContract};
Expand Down Expand Up @@ -67,3 +68,32 @@ pub use once_cell::sync::Lazy;

#[cfg(feature = "eip712")]
pub use ethers_derive_eip712::*;

// For Abigen expansions in docs.rs builds.

#[doc(hidden)]
#[allow(unused_extern_crates)]
extern crate self as ethers_contract;

#[doc(hidden)]
#[allow(unused_extern_crates)]
#[cfg(docsrs)]
extern crate self as ethers;

#[doc(hidden)]
#[cfg(docsrs)]
pub mod core {
pub use ethers_core::*;
}

#[doc(hidden)]
#[cfg(docsrs)]
pub mod contract {
pub use crate::*;
}

#[doc(hidden)]
#[cfg(docsrs)]
pub mod providers {
pub use ethers_providers::*;
}
27 changes: 8 additions & 19 deletions ethers-core/src/macros/ethers_crate.rs
Expand Up @@ -56,10 +56,13 @@ pub struct ProjectEnvironment {
}

impl ProjectEnvironment {
/// Creates a new instance using the given manifest dir and crate name.
pub fn new<T: Into<PathBuf>, U: Into<String>>(manifest_dir: T, crate_name: U) -> Self {
Self { manifest_dir: manifest_dir.into(), crate_name: Some(crate_name.into()) }
}

/// Creates a new instance using the the `CARGO_MANIFEST_DIR` and `CARGO_CRATE_NAME` environment
/// variables.
pub fn new_from_env() -> Option<Self> {
Some(Self {
manifest_dir: env::var_os("CARGO_MANIFEST_DIR")?.into(),
Expand Down Expand Up @@ -90,29 +93,15 @@ impl ProjectEnvironment {
}

#[inline]
pub fn crate_names_from_metadata(&self) -> Option<CrateNames> {
fn crate_names_from_metadata(&self) -> Option<CrateNames> {
let metadata = MetadataCommand::new().current_dir(&self.manifest_dir).exec().ok()?;
let pkg = metadata.root_package()?;

// return ethers_* if the root package is an internal ethers crate since `ethers` is not
// available
let crate_is_root = self.is_crate_root();
if let Ok(current_pkg) = pkg.name.parse::<EthersCrate>() {
// replace `current_pkg`'s name with "crate"
let names =
EthersCrate::path_names()
.map(|(pkg, name)| {
if crate_is_root && pkg == current_pkg {
(pkg, "crate")
} else {
(pkg, name)
}
})
.collect();
return Some(names)
} /* else if pkg.name == "ethers" {
// should not happen (the root package the `ethers` workspace package itself)
} */
if pkg.name.parse::<EthersCrate>().is_ok() || pkg.name == "ethers" {
return Some(EthersCrate::path_names().collect())
}

let mut names: CrateNames = EthersCrate::ethers_path_names().collect();
for dep in pkg.dependencies.iter() {
Expand Down Expand Up @@ -293,7 +282,7 @@ impl EthersCrate {
pub const fn ethers_path_name(self) -> &'static str {
match self {
// re-exported in ethers::contract
Self::EthersContractAbigen => "::ethers::contract", // partly
Self::EthersContractAbigen => "::ethers::contract", // partially
Self::EthersContractDerive => "::ethers::contract",
Self::EthersDeriveEip712 => "::ethers::contract",

Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Expand Up @@ -83,6 +83,11 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms), allow(dead_code, unused_variables))))]

// For macro expansion
#[doc(hidden)]
#[allow(unused_extern_crates)]
extern crate self as ethers;

#[doc(inline)]
pub use ethers_addressbook as addressbook;
#[doc(inline)]
Expand Down