Skip to content

Commit

Permalink
bug: fix cargo publish (#1403)
Browse files Browse the repository at this point in the history
using `include!` with paths that lead out of the current crate will lead
to `cargo publish` failures since, when publishing, you only have the
current crate code available.

Workaround is to have `version.rs` now live near the `Provider` and the
fuel version checker will have a cargo dep on `fuels-accounts` to get
it, as will the `e2e` tests.

Even though `e2e` tests aren't published, I've updated them as well to
use `fuels-accounts` even though it may add a few seconds to the build
stage.

### Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have updated the documentation.
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [X] I have added necessary labels.
- [X] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [X] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Ahmed Sagdati <[email protected]>
  • Loading branch information
segfault-magnet and Ahmed Sagdati authored May 31, 2024
1 parent 8f432e7 commit 10fcbff
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tokio = { workspace = true, features = ["test-util"] }
[build-dependencies]
anyhow = { workspace = true, features = ["std"] }
flate2 = { workspace = true, features = ["zlib"] }
fuels-accounts = { workspace = true, features = ["std"] }
reqwest = { workspace = true, features = ["blocking", "default-tls"] }
semver = { workspace = true }
tar = { workspace = true }
Expand Down
18 changes: 9 additions & 9 deletions e2e/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use flate2::read::GzDecoder;
use semver::Version;
use fuels_accounts::provider::SUPPORTED_FUEL_CORE_VERSION;
use std::{
io::Cursor,
path::{Path, PathBuf},
Expand All @@ -12,8 +12,6 @@ struct Downloader {

impl Downloader {
const EXECUTOR_FILE_NAME: &'static str = "fuel-core-wasm-executor.wasm";
const CORRECT_VERSION_CONTENTS: &'static str =
include_str!("../scripts/fuel-core-version/version.rs");

pub fn new() -> Self {
let env = std::env::var("OUT_DIR").unwrap();
Expand All @@ -32,8 +30,8 @@ impl Downloader {
return Ok(true);
}

let saved_version = std::fs::read_to_string(self.version_path())?;
if saved_version != Self::CORRECT_VERSION_CONTENTS {
let saved_version = semver::Version::parse(&std::fs::read_to_string(self.version_path())?)?;
if saved_version != SUPPORTED_FUEL_CORE_VERSION {
return Ok(true);
}

Expand All @@ -44,8 +42,7 @@ impl Downloader {
std::fs::create_dir_all(&self.dir)?;

const LINK_TEMPLATE: &str = "https://github.com/FuelLabs/fuel-core/releases/download/vVERSION/fuel-core-VERSION-x86_64-unknown-linux-gnu.tar.gz";
const CORE_VERSION: semver::Version = include!("../scripts/fuel-core-version/version.rs");
let link = LINK_TEMPLATE.replace("VERSION", &CORE_VERSION.to_string());
let link = LINK_TEMPLATE.replace("VERSION", &SUPPORTED_FUEL_CORE_VERSION.to_string());

let response = reqwest::blocking::get(link)?;
if !response.status().is_success() {
Expand All @@ -58,7 +55,7 @@ impl Downloader {

let mut extracted = false;
let executor_in_tar = Path::new(&format!(
"fuel-core-{CORE_VERSION}-x86_64-unknown-linux-gnu"
"fuel-core-{SUPPORTED_FUEL_CORE_VERSION}-x86_64-unknown-linux-gnu"
))
.join(Self::EXECUTOR_FILE_NAME);

Expand All @@ -67,7 +64,10 @@ impl Downloader {

if entry.path()? == executor_in_tar {
entry.unpack(self.executor_path())?;
std::fs::write(self.version_path(), Self::CORRECT_VERSION_CONTENTS)?;
std::fs::write(
self.version_path(),
format!("{SUPPORTED_FUEL_CORE_VERSION}"),
)?;

extracted = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{collections::HashMap, fmt::Debug, net::SocketAddr};

mod retry_util;
mod retryable_client;
mod supported_fuel_core_version;
mod supported_versions;

#[cfg(feature = "coin-cache")]
Expand Down Expand Up @@ -41,6 +42,7 @@ use fuels_core::{
},
};
pub use retry_util::{Backoff, RetryConfig};
pub use supported_fuel_core_version::SUPPORTED_FUEL_CORE_VERSION;
use tai64::Tai64;
#[cfg(feature = "coin-cache")]
use tokio::sync::Mutex;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 27, 0);
4 changes: 1 addition & 3 deletions packages/fuels-accounts/src/provider/supported_versions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::provider::supported_fuel_core_version::SUPPORTED_FUEL_CORE_VERSION;
use semver::Version;

pub const SUPPORTED_FUEL_CORE_VERSION: Version =
include!("../../../../scripts/fuel-core-version/version.rs");

#[derive(Debug, PartialEq, Eq)]
pub(crate) struct VersionCompatibility {
pub(crate) supported_version: Version,
Expand Down
1 change: 1 addition & 0 deletions scripts/fuel-core-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ rust-version = { workspace = true }
[dependencies]
clap = { version = "4.5.3", features = ["derive"] }
color-eyre = "0.6.2"
fuels-accounts = { workspace = true, features = ["std"] }
semver = { workspace = true }
versions-replacer = { workspace = true }
6 changes: 3 additions & 3 deletions scripts/fuel-core-version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use color_eyre::{
eyre::{bail, ContextCompat},
Result,
};
use fuels_accounts::provider::SUPPORTED_FUEL_CORE_VERSION;
use semver::Version;
use versions_replacer::metadata::collect_versions_from_cargo_toml;

Expand Down Expand Up @@ -40,11 +41,10 @@ fn get_version_file_path(
}

fn verify_version_from_file(version: Version) -> Result<()> {
let version_from_file: Version = include!("../version.rs");
if version != version_from_file {
if version != SUPPORTED_FUEL_CORE_VERSION {
bail!(
"fuel_core version in version.rs ({}) doesn't match one in Cargo.toml ({})",
version_from_file,
SUPPORTED_FUEL_CORE_VERSION,
version
);
}
Expand Down
1 change: 0 additions & 1 deletion scripts/fuel-core-version/version.rs

This file was deleted.

0 comments on commit 10fcbff

Please sign in to comment.