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

Move lib-std and lib-core to separate repositories #522

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example_project/fuel_project/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ name = "Fuel example project"


[dependencies]
std = { path = "../../lib-std" }
std = { git = "http://github.com/FuelLabs/sway-lib-std" }
43 changes: 32 additions & 11 deletions forc/src/ops/forc_abi_json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::dependency::{Dependency, DependencyDetails};
use crate::utils::dependency::Dependency;
use crate::{
cli::JsonAbiCommand,
utils::dependency,
Expand Down Expand Up @@ -97,6 +97,7 @@ pub fn build(command: JsonAbiCommand) -> Result<Value, String> {
&mut namespace,
&mut dependency_graph,
silent_mode,
offline_mode,
)?);
}
}
Expand Down Expand Up @@ -130,22 +131,43 @@ pub fn build(command: JsonAbiCommand) -> Result<Value, String> {
fn compile_dependency_lib<'source, 'manifest>(
project_file_path: &Path,
dependency_name: &'manifest str,
dependency_lib: &Dependency,
dependency_lib: &mut Dependency,
namespace: &mut Namespace<'source>,
dependency_graph: &mut HashMap<String, HashSet<String>>,
silent_mode: bool,
offline_mode: bool,
) -> Result<Vec<Function>, String> {
let dep_path = match dependency_lib {
let mut details = match dependency_lib {
Dependency::Simple(..) => {
return Err(
"Not yet implemented: Simple version-spec dependencies require a registry.".into(),
)
}
Dependency::Detailed(DependencyDetails { path, .. }) => path,
Dependency::Detailed(ref mut details) => details,
};
// Download a non-local dependency if the `git` property is set in this dependency.
if let Some(ref git) = details.git {
let downloaded_dep_path = match dependency::download_github_dep(
dependency_name,
git,
&details.branch,
&details.version,
offline_mode.into(),
) {
Ok(path) => path,
Err(e) => {
return Err(format!(
"Couldn't download dependency ({:?}): {:?}",
dependency_name, e
))
}
};

// Mutate this dependency's path to hold the newly downloaded dependency's path.
details.path = Some(downloaded_dep_path);
}
let dep_path =
match dep_path {
match &details.path {
Some(p) => p,
None => return Err(
"Only simple path imports are supported right now. Please supply a path relative \
Expand All @@ -169,30 +191,29 @@ fn compile_dependency_lib<'source, 'manifest>(
))
}
};
let manifest_of_dep = read_manifest(&manifest_dir)?;
let mut manifest_of_dep = read_manifest(&manifest_dir)?;
let main_path = find_main_path(&manifest_dir, &manifest_of_dep);
let file_name = find_file_name(&manifest_dir, &main_path)?;

let build_config = BuildConfig::root_from_file_name_and_manifest_path(
file_name.to_owned(),
manifest_dir.clone(),
);
let mut dep_namespace = namespace.clone();
let mut dep_namespace = Default::default();

// The part below here is just a massive shortcut to get the standard library working
if let Some(ref deps) = manifest_of_dep.dependencies {
for dep in deps {
if let Some(ref mut deps) = manifest_of_dep.dependencies {
for ref mut dep in deps {
// to do this properly, iterate over list of dependencies make sure there are no
// circular dependencies
//return Err("Unimplemented: dependencies that have dependencies".into());
compile_dependency_lib(
&manifest_dir,
dep.0,
dep.1,
// give it a cloned namespace, which we then merge with this namespace
&mut dep_namespace,
dependency_graph,
silent_mode,
offline_mode,
)?;
}
}
Expand Down
76 changes: 36 additions & 40 deletions forc/src/ops/forc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,46 +70,14 @@ pub fn build(command: BuildCommand) -> Result<Vec<u8>, String> {
let mut namespace: Namespace = Default::default();
if let Some(ref mut deps) = manifest.dependencies {
for (dependency_name, dependency_details) in deps.iter_mut() {
// Check if dependency is a git-based dependency.
let dep = match dependency_details {
Dependency::Simple(..) => {
return Err(
"Not yet implemented: Simple version-spec dependencies require a registry."
.into(),
);
}
Dependency::Detailed(dep_details) => dep_details,
};

// Download a non-local dependency if the `git` property is set in this dependency.
if let Some(git) = &dep.git {
let downloaded_dep_path = match dependency::download_github_dep(
dependency_name,
git,
&dep.branch,
&dep.version,
offline_mode.into(),
) {
Ok(path) => path,
Err(e) => {
return Err(format!(
"Couldn't download dependency ({:?}): {:?}",
dependency_name, e
))
}
};

// Mutate this dependency's path to hold the newly downloaded dependency's path.
dep.path = Some(downloaded_dep_path);
}

compile_dependency_lib(
&this_dir,
dependency_name,
dependency_details,
&mut namespace,
&mut dependency_graph,
silent_mode,
offline_mode,
)?;
}
}
Expand Down Expand Up @@ -140,11 +108,41 @@ pub fn build(command: BuildCommand) -> Result<Vec<u8>, String> {
fn compile_dependency_lib<'n, 'source, 'manifest>(
project_file_path: &Path,
dependency_name: &'manifest str,
dependency_lib: &Dependency,
dependency_lib: &mut Dependency,
namespace: &mut Namespace<'source>,
dependency_graph: &mut HashMap<String, HashSet<String>>,
silent_mode: bool,
offline_mode: bool,
) -> Result<(), String> {
let mut details = match dependency_lib {
Dependency::Simple(..) => {
return Err(
"Not yet implemented: Simple version-spec dependencies require a registry.".into(),
)
}
Dependency::Detailed(ref mut details) => details,
};
// Download a non-local dependency if the `git` property is set in this dependency.
if let Some(ref git) = details.git {
let downloaded_dep_path = match dependency::download_github_dep(
dependency_name,
git,
&details.branch,
&details.version,
offline_mode.into(),
) {
Ok(path) => path,
Err(e) => {
return Err(format!(
"Couldn't download dependency ({:?}): {:?}",
dependency_name, e
))
}
};

// Mutate this dependency's path to hold the newly downloaded dependency's path.
details.path = Some(downloaded_dep_path);
}
let dep_path = match dependency_lib {
Dependency::Simple(..) => {
return Err(
Expand Down Expand Up @@ -180,7 +178,7 @@ fn compile_dependency_lib<'n, 'source, 'manifest>(
}
};

let manifest_of_dep = read_manifest(&manifest_dir)?;
let mut manifest_of_dep = read_manifest(&manifest_dir)?;

let main_path = {
let mut code_dir = manifest_dir.clone();
Expand All @@ -201,20 +199,18 @@ fn compile_dependency_lib<'n, 'source, 'manifest>(
);
let mut dep_namespace: Namespace = Default::default();

// The part below here is just a massive shortcut to get the standard library working
if let Some(ref deps) = manifest_of_dep.dependencies {
for (dependency_name, dependency_lib) in deps {
if let Some(ref mut deps) = manifest_of_dep.dependencies {
for (dependency_name, ref mut dependency_lib) in deps {
// to do this properly, iterate over list of dependencies make sure there are no
// circular dependencies
//return Err("Unimplemented: dependencies that have dependencies".into());
compile_dependency_lib(
&manifest_dir,
dependency_name,
dependency_lib,
// give it a cloned namespace, which we then merge with this namespace
&mut dep_namespace,
dependency_graph,
silent_mode,
offline_mode,
)?;
}
}
Expand Down
4 changes: 4 additions & 0 deletions forc/src/utils/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ name = "{}"
author = "{}"
entry = "main.sw"
license = "Apache-2.0"

[dependencies]
std = {{ git = "http://github.com/FuelLabs/sway-lib-std" }}
core = {{ git = "http://github.com/FuelLabs/sway-lib-core" }}
"#,
project_name, real_name,
)
Expand Down
5 changes: 4 additions & 1 deletion forc/src/utils/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ pub fn download_github_dep(

let github_api_url = build_github_repo_api_url(repo_base_url, branch, version);

println!("Downloading {:?} into {:?}", dep_name, out_dir);
let _ = crate::utils::helpers::println_green(&format!(
" Downloading {:?} ({:?})",
dep_name, out_dir
));

match download_tarball(&github_api_url, &out_dir) {
Ok(downloaded_dir) => Ok(downloaded_dir),
Expand Down
5 changes: 0 additions & 5 deletions lib-core/Forc.toml

This file was deleted.

3 changes: 0 additions & 3 deletions lib-core/src/lib.sw

This file was deleted.

Loading