This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e160ee
commit 8ef3615
Showing
11 changed files
with
288 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
//! Support for generic projects with cargo-dist build instructions | ||
|
||
use axoasset::{toml_edit, SourceFile}; | ||
use camino::Utf8Path; | ||
|
||
use crate::{PackageInfo, Result, Version, WorkspaceInfo, WorkspaceSearch}; | ||
|
||
/// Try to find a Cargo/Rust workspace at the given path | ||
/// | ||
/// See [`crate::get_workspaces`][] for the semantics. | ||
/// | ||
/// This relies on `cargo metadata` so will only work if you have `cargo` installed. | ||
pub fn get_workspace(start_dir: &Utf8Path, clamp_to_dir: Option<&Utf8Path>) -> WorkspaceSearch { | ||
let manifest_path = match crate::find_file("dist.toml", start_dir, clamp_to_dir) { | ||
Ok(path) => path, | ||
Err(e) => return WorkspaceSearch::Missing(e), | ||
}; | ||
|
||
match workspace_from(&manifest_path) { | ||
Ok(info) => WorkspaceSearch::Found(info), | ||
Err(e) => WorkspaceSearch::Broken { | ||
manifest_path, | ||
cause: e, | ||
}, | ||
} | ||
} | ||
|
||
fn workspace_from(manifest_path: &Utf8Path) -> Result<WorkspaceInfo> { | ||
let workspace_dir = manifest_path.parent().unwrap().to_path_buf(); | ||
let root_auto_includes = crate::find_auto_includes(&workspace_dir)?; | ||
|
||
let manifest = load_root_dist_toml(manifest_path)?; | ||
let mut binaries = vec![]; | ||
let mut cstaticlibs = vec![]; | ||
let mut cdylibs = vec![]; | ||
let mut repository_url = None; | ||
let mut name = String::new(); | ||
let mut version = None; | ||
let mut build_command = None; | ||
|
||
if let Some(package) = manifest.get("package").and_then(|t| t.as_table()) { | ||
binaries = fetch_string_array(package, "binaries")?; | ||
build_command = Some(fetch_string_array(package, "build-command")?); | ||
let result = fetch_string_array(package, "cstaticlibs"); | ||
match result { | ||
Ok(libs) => cstaticlibs = libs, | ||
// If not specified, the default is fine | ||
Err(crate::errors::AxoprojectError::ManifestFieldMissing { .. }) => {} | ||
Err(err) => return Err(err), | ||
} | ||
|
||
let result = fetch_string_array(package, "cdylibs"); | ||
match result { | ||
Ok(libs) => cdylibs = libs, | ||
// If not specified, the default is fine | ||
Err(crate::errors::AxoprojectError::ManifestFieldMissing { .. }) => {} | ||
Err(err) => return Err(err), | ||
} | ||
|
||
if let Some(url) = package.get("repository") { | ||
repository_url = url.as_str().map(|s| s.to_owned()); | ||
} | ||
if let Some(n) = package.get("name") { | ||
name = n.as_str().unwrap_or("").to_owned(); | ||
} | ||
if let Some(v) = package.get("version") { | ||
if let Some(s) = v.as_str() { | ||
if let Ok(value) = semver::Version::parse(s) { | ||
version = Some(Version::Generic(value)) | ||
} | ||
} | ||
} | ||
}; | ||
|
||
let manifest_path = manifest_path.to_path_buf(); | ||
|
||
let package_info = PackageInfo { | ||
manifest_path: manifest_path.clone(), | ||
package_root: manifest_path.clone(), | ||
name, | ||
version, | ||
// TODO | ||
description: None, | ||
// TODO | ||
authors: vec![], | ||
// TODO | ||
license: None, | ||
publish: true, | ||
keywords: None, | ||
repository_url: repository_url.clone(), | ||
// TODO | ||
homepage_url: None, | ||
// TODO | ||
documentation_url: None, | ||
// TODO | ||
readme_file: None, | ||
// TODO | ||
license_files: vec![], | ||
// TODO | ||
changelog_file: None, | ||
binaries, | ||
cstaticlibs, | ||
cdylibs, | ||
#[cfg(feature = "cargo-projects")] | ||
cargo_metadata_table: None, | ||
#[cfg(feature = "cargo-projects")] | ||
cargo_package_id: None, | ||
}; | ||
|
||
Ok(WorkspaceInfo { | ||
kind: crate::WorkspaceKind::Generic, | ||
target_dir: workspace_dir.clone(), | ||
workspace_dir, | ||
package_info: vec![package_info], | ||
manifest_path, | ||
repository_url, | ||
root_auto_includes, | ||
warnings: vec![], | ||
build_command, | ||
#[cfg(feature = "cargo-projects")] | ||
cargo_metadata_table: None, | ||
#[cfg(feature = "cargo-projects")] | ||
cargo_profiles: crate::rust::CargoProfiles::new(), | ||
}) | ||
} | ||
|
||
fn fetch_string_array(table: &toml_edit::Table, field: &str) -> Result<Vec<String>> { | ||
if let Some(array) = table.get(field) { | ||
if !array.is_array() { | ||
Err(crate::errors::AxoprojectError::ManifestWrongType { | ||
field: field.to_owned(), | ||
expected: "array".to_owned(), | ||
actual: array.type_name().to_owned(), | ||
}) | ||
} else { | ||
Ok(array | ||
.as_array() | ||
.unwrap() | ||
.into_iter() | ||
.map(|b| b.as_str().unwrap_or("").to_owned()) | ||
.collect()) | ||
} | ||
} else { | ||
Err(crate::errors::AxoprojectError::ManifestFieldMissing { | ||
field: field.to_owned(), | ||
}) | ||
} | ||
} | ||
|
||
/// Load the root workspace toml into toml-edit form | ||
pub fn load_root_dist_toml(manifest_path: &Utf8Path) -> Result<toml_edit::Document> { | ||
let manifest_src = SourceFile::load_local(manifest_path)?; | ||
let manifest = manifest_src.deserialize_toml_edit()?; | ||
Ok(manifest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CC := gcc | ||
RM := rm | ||
EXEEXT := | ||
|
||
all: main$(EXEEXT) | ||
|
||
main$(EXEEXT): | ||
$(CC) main.c -o main$(EXEEXT) | ||
|
||
clean: | ||
$(RM) -f main$(EXEEXT) | ||
|
||
.PHONY: all clean |
Oops, something went wrong.