Skip to content

Commit

Permalink
Move the SWAY_GIT_TAG from forc into forc-pkg (FuelLabs#2448)
Browse files Browse the repository at this point in the history
Move the SWAY_GIT_TAG from `forc` into `forc-pkg`

Closes FuelLabs#2447.

See this comment for context:
FuelLabs#2440 (comment)
  • Loading branch information
mitchmindtree authored Aug 3, 2022
1 parent 63db860 commit 2816c13
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 145 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 24 additions & 16 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ impl ManifestFile {
/// fields were used.
///
/// If `core` and `std` are unspecified, `std` will be added to the `dependencies` table
/// implicitly. In this case, the `sway_git_tag` is used to specify the pinned commit at which
/// we fetch `std`.
pub fn from_file(path: PathBuf, sway_git_tag: &str) -> Result<Self> {
/// implicitly. In this case, the git tag associated with the version of this crate is used to
/// specify the pinned commit at which we fetch `std`.
pub fn from_file(path: PathBuf) -> Result<Self> {
let path = path.canonicalize()?;
let manifest = Manifest::from_file(&path, sway_git_tag)?;
let manifest = Manifest::from_file(&path)?;
Ok(Self { manifest, path })
}

Expand All @@ -118,11 +118,11 @@ impl ManifestFile {
///
/// This is short for `Manifest::from_file`, but takes care of constructing the path to the
/// file.
pub fn from_dir(manifest_dir: &Path, sway_git_tag: &str) -> Result<Self> {
pub fn from_dir(manifest_dir: &Path) -> Result<Self> {
let dir = forc_util::find_manifest_dir(manifest_dir)
.ok_or_else(|| manifest_file_missing(manifest_dir))?;
let path = dir.join(constants::MANIFEST_FILE_NAME);
Self::from_file(path, sway_git_tag)
Self::from_file(path)
}

/// Validate the `Manifest`.
Expand Down Expand Up @@ -232,9 +232,9 @@ impl Manifest {
/// fields were used.
///
/// If `core` and `std` are unspecified, `std` will be added to the `dependencies` table
/// implicitly. In this case, the `sway_git_tag` is used to specify the pinned commit at which
/// we fetch `std`.
pub fn from_file(path: &Path, sway_git_tag: &str) -> Result<Self> {
/// implicitly. In this case, the git tag associated with the version of this crate is used to
/// specify the pinned commit at which we fetch `std`.
pub fn from_file(path: &Path) -> Result<Self> {
let manifest_str = std::fs::read_to_string(path)
.map_err(|e| anyhow!("failed to read manifest at {:?}: {}", path, e))?;
let toml_de = &mut toml::de::Deserializer::new(&manifest_str);
Expand All @@ -243,7 +243,7 @@ impl Manifest {
println_yellow_err(&warning);
})
.map_err(|e| anyhow!("failed to parse manifest: {}.", e))?;
manifest.implicitly_include_std_if_missing(sway_git_tag);
manifest.implicitly_include_std_if_missing();
manifest.implicitly_include_default_build_profiles_if_missing();
manifest.validate()?;
Ok(manifest)
Expand All @@ -265,10 +265,10 @@ impl Manifest {
///
/// This is short for `Manifest::from_file`, but takes care of constructing the path to the
/// file.
pub fn from_dir(dir: &Path, sway_git_tag: &str) -> Result<Self> {
pub fn from_dir(dir: &Path) -> Result<Self> {
let manifest_dir = find_manifest_dir(dir).ok_or_else(|| manifest_file_missing(dir))?;
let file_path = manifest_dir.join(constants::MANIFEST_FILE_NAME);
Self::from_file(&file_path, sway_git_tag)
Self::from_file(&file_path)
}

/// Produce an iterator yielding all listed dependencies.
Expand Down Expand Up @@ -311,7 +311,7 @@ impl Manifest {
///
/// Note: If only `core` is specified, we are unable to implicitly add `std` as we cannot
/// guarantee that the user's `core` is compatible with the implicit `std`.
fn implicitly_include_std_if_missing(&mut self, sway_git_tag: &str) {
fn implicitly_include_std_if_missing(&mut self) {
use crate::{CORE, STD};
// Don't include `std` if:
// - this *is* `core` or `std`.
Expand All @@ -329,7 +329,7 @@ impl Manifest {
// Add a `[dependencies]` table if there isn't one.
let deps = self.dependencies.get_or_insert_with(Default::default);
// Add the missing dependency.
let std_dep = implicit_std_dep(sway_git_tag.to_string());
let std_dep = implicit_std_dep();
deps.insert(STD.to_string(), std_dep);
}

Expand Down Expand Up @@ -425,11 +425,19 @@ impl Default for BuildProfile {
}

/// The definition for the implicit `std` dependency.
fn implicit_std_dep(sway_git_tag: String) -> Dependency {
fn implicit_std_dep() -> Dependency {
// The `forc-pkg` crate version formatted with the `v` prefix. E.g. "v1.2.3".
//
// This git tag is used during `Manifest` construction to pin the version of the implicit `std`
// dependency to the `forc-pkg` version.
//
// This is important to ensure that the version of `sway-core` that is baked into `forc-pkg` is
// compatible with the version of the `std` lib.
const SWAY_GIT_TAG: &str = concat!("v", env!("CARGO_PKG_VERSION"));
const SWAY_GIT_REPO_URL: &str = "https://github.com/fuellabs/sway";
let det = DependencyDetails {
git: Some(SWAY_GIT_REPO_URL.to_string()),
tag: Some(sway_git_tag),
tag: Some(SWAY_GIT_TAG.to_string()),
..Default::default()
};
Dependency::Detailed(det)
Expand Down
Loading

0 comments on commit 2816c13

Please sign in to comment.