-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
autobins
and target renaming [lib]
and [[bin]]
- Loading branch information
Showing
9 changed files
with
277 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
name = "cargo-subcommand" | ||
version = "0.11.0" | ||
authors = ["David Craven <[email protected]>", "Marijn Suijten <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
description = "Library for creating cargo subcommands." | ||
repository = "https://github.com/dvc94ch/cargo-subcommand" | ||
license = "ISC" | ||
|
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
# cargo-subcommand library for building subcommands | ||
Is used by `cargo-apk` and `cargo-flutter`. | ||
# `cargo-subcommand` library for building subcommands | ||
|
||
Is used by [`cargo-apk`](https://crates.io/crates/cargo-apk) and `cargo-flutter`. | ||
|
||
# License | ||
|
||
Copyright 2020 David Craven <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
|
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 |
---|---|---|
@@ -1,50 +1,54 @@ | ||
use std::path::Path; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
pub enum Artifact { | ||
Root(String), | ||
Example(String), | ||
use crate::manifest::CrateType; | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
pub enum ArtifactType { | ||
Lib, | ||
Bin, | ||
Example, | ||
// Bench, | ||
// Test, | ||
} | ||
|
||
impl AsRef<Path> for Artifact { | ||
fn as_ref(&self) -> &Path { | ||
Path::new(match self { | ||
Self::Root(_) => "", | ||
Self::Example(_) => "examples", | ||
}) | ||
} | ||
#[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
pub struct Artifact { | ||
pub name: String, | ||
pub path: PathBuf, | ||
pub r#type: ArtifactType, | ||
} | ||
|
||
impl Artifact { | ||
pub fn name(&self) -> &str { | ||
match self { | ||
Self::Root(name) => name, | ||
Self::Example(name) => name, | ||
} | ||
pub fn build_dir(&self) -> &'static Path { | ||
Path::new(match self.r#type { | ||
ArtifactType::Lib | ArtifactType::Bin => "", | ||
ArtifactType::Example => "examples", | ||
}) | ||
} | ||
|
||
// TODO: CrateType should be read from the manifest' crate-type array, | ||
// and validated that the requested format is in that array | ||
pub fn file_name(&self, ty: CrateType, target: &str) -> String { | ||
match ty { | ||
CrateType::Bin => { | ||
match (self.r#type, ty) { | ||
(ArtifactType::Bin | ArtifactType::Example, CrateType::Bin) => { | ||
if target.contains("windows") { | ||
format!("{}.exe", self.name()) | ||
format!("{}.exe", self.name) | ||
} else if target.contains("wasm") { | ||
format!("{}.wasm", self.name()) | ||
format!("{}.wasm", self.name) | ||
} else { | ||
self.name().to_string() | ||
self.name.to_string() | ||
} | ||
} | ||
CrateType::Lib => format!("lib{}.rlib", self.name().replace('-', "_")), | ||
CrateType::Staticlib => format!("lib{}.a", self.name().replace('-', "_")), | ||
CrateType::Cdylib => format!("lib{}.so", self.name().replace('-', "_")), | ||
(ArtifactType::Lib | ArtifactType::Example, CrateType::Lib) => { | ||
format!("lib{}.rlib", self.name.replace('-', "_")) | ||
} | ||
(ArtifactType::Lib | ArtifactType::Example, CrateType::Staticlib) => { | ||
format!("lib{}.a", self.name.replace('-', "_")) | ||
} | ||
(ArtifactType::Lib | ArtifactType::Example, CrateType::Cdylib) => { | ||
format!("lib{}.so", self.name.replace('-', "_")) | ||
} | ||
(a, c) => panic!("{a:?} is not compatible with {c:?}"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
pub enum CrateType { | ||
Bin, | ||
Lib, | ||
Staticlib, | ||
Cdylib, | ||
} |
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
Oops, something went wrong.