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

Update to clap-3.1 and cargo-0.61 #255

Merged
merged 5 commits into from
Apr 19, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
- name: Install grcov
env:
LINK: https://github.com/mozilla/grcov/releases/download
GRCOV_VERSION: 0.7.1
GRCOV_VERSION: 0.8.7
run: |
curl -L "$LINK/v$GRCOV_VERSION/grcov-linux-x86_64.tar.bz2" |
curl -L "$LINK/v$GRCOV_VERSION/grcov-x86_64-unknown-linux-gnu.tar.bz2" |
tar xj -C $HOME/.cargo/bin

- name: Install nightly
Expand All @@ -59,6 +59,12 @@ jobs:
override: true
components: llvm-tools-preview

- name: Set up MinGW
uses: egor-tensin/setup-mingw@v2
with:
platform: x64
cc: false

- name: Run cargo clean
run: |
cargo clean
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-c"
version = "0.9.8+cargo-0.60"
version = "0.9.9+cargo-0.61"
authors = ["Luca Barbato <lu_zero@gentoo.org>"]
description = "Helper program to build and install c-like libraries"
license = "MIT"
Expand All @@ -27,13 +27,13 @@ name = "cargo-ctest"
path = "src/bin/ctest.rs"

[dependencies]
cargo = "0.60"
cargo = "0.61"
cargo-util = "0.1"
semver = "1.0.3"
log = "0.4"
structopt = { version="0.3", features=["color"] }
clap = { version="3.1", features=["color", "derive", "cargo"] }
regex = "1"
cbindgen = "0.20"
cbindgen = "0.22"
toml = "0.5"
serde = "1.0.123"
serde_derive = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export LLVM_PROFILE_FILE="cargo-c-%p-%m.profraw"
export RUSTFLAGS=-Zinstrument-coverage
export RUSTFLAGS=-Cinstrument-coverage
export CARGO_INCREMENTAL=0

rustup default nightly
rustup target add x86_64-pc-windows-gnu
rustup default stable
cargo build
cargo test
rustup target add x86_64-pc-windows-gnu
unset RUSTFLAGS

for project in example-project example-workspace; do
Expand All @@ -24,7 +24,7 @@ for project in example-project example-workspace; do
target/debug/cargo-cinstall cinstall --manifest-path=${project}/Cargo.toml --destdir=/tmp/staging
target/debug/cargo-cinstall cinstall clean --manifest-path=${project}/Cargo.toml

target/debug/cargo-cinstall cinstall --manifest-path=${project}/Cargo.toml --destdir=/tmp/staging-win --target=x86_64-pc-windows-gnu
target/debug/cargo-cinstall cinstall --manifest-path=${project}/Cargo.toml --destdir=/tmp/staging-win --target=x86_64-pc-windows-gnu --dlltool=x86_64-w64-mingw32-dlltool
done

grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov
2 changes: 1 addition & 1 deletion example-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ libc = { version = "0.2", optional = true }
inline-c = "0.1"

[build-dependencies]
cargo_metadata = "0.13.1"
cargo_metadata = "0.14"

[package.metadata.capi.header]
subdirectory = "example-project-0.1/example_project"
Expand Down
27 changes: 12 additions & 15 deletions src/bin/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo::util::command_prelude::ArgMatchesExt;
use cargo::CliResult;
use cargo::Config;

use structopt::clap::*;
use clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;
Expand All @@ -17,17 +17,14 @@ fn main() -> CliResult {
let cli_install = subcommand_install("install", "Install the crate C-API");
let cli_test = subcommand_test("test");

let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(
SubCommand::with_name("capi")
Command::new("capi")
.about("Build or install the crate C-API")
.arg(opt("version", "Print version info and exit").short("V"))
.arg(opt("version", "Print version info and exit").short('V'))
.subcommand(cli_build)
.subcommand(cli_install)
.subcommand(cli_test),
Expand All @@ -36,11 +33,11 @@ fn main() -> CliResult {
let args = app.clone().get_matches();

let (cmd, subcommand_args, default_profile) = match args.subcommand() {
("capi", Some(args)) => match args.subcommand() {
("build", Some(args)) => ("build", args, "dev"),
("test", Some(args)) => ("test", args, "dev"),
("install", Some(args)) => ("install", args, "release"),
(cmd, Some(args)) => {
Some(("capi", args)) => match args.subcommand() {
Some(("build", args)) => ("build", args, "dev"),
Some(("test", args)) => ("test", args, "dev"),
Some(("install", args)) => ("install", args, "release"),
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
18 changes: 7 additions & 11 deletions src/bin/cbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_build;
use cargo_c::config::*;

use structopt::clap::*;
use clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;

let subcommand = subcommand_build("cbuild", "Build the crate C-API");

let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);

let args = app.clone().get_matches();

let subcommand_args = match args.subcommand() {
("cbuild", Some(args)) => args,
(cmd, Some(args)) => {
Some(("cbuild", args)) => args,
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
17 changes: 7 additions & 10 deletions src/bin/cinstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ use cargo_c::cli::subcommand_install;
use cargo_c::config::config_configure;
use cargo_c::install::cinstall;

use structopt::clap::*;
use clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;

let subcommand = subcommand_install("cinstall", "Install the crate C-API");
let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);

let args = app.clone().get_matches();

let subcommand_args = match args.subcommand() {
("cinstall", Some(args)) => args,
(cmd, Some(args)) => {
Some(("cinstall", args)) => args,
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
17 changes: 6 additions & 11 deletions src/bin/ctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@ use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_test;
use cargo_c::config::*;

use structopt::clap::*;

fn main() -> CliResult {
let mut config = Config::default()?;

let subcommand = subcommand_test("ctest");

let mut app = app_from_crate!()
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::VersionlessSubcommands,
AppSettings::AllowExternalSubcommands,
])
let mut app = clap::command!()
.setting(AppSettings::DeriveDisplayOrder)
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);

let args = app.clone().get_matches();

let subcommand_args = match args.subcommand() {
("ctest", Some(args)) => args,
(cmd, Some(args)) => {
Some(("ctest", args)) => args,
Some((cmd, args)) => {
return run_cargo_fallback(cmd, args);
}
_ => {
Expand Down
33 changes: 19 additions & 14 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ fn load_manifest_capi_config(pkg: &Package) -> anyhow::Result<CApiConfig> {
fn compile_options(
ws: &Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
profile: InternedString,
compile_mode: CompileMode,
) -> anyhow::Result<CompileOptions> {
Expand Down Expand Up @@ -865,7 +865,7 @@ fn compile_with_exec<'a>(
exec: &Arc<dyn Executor>,
rustc_target: &target::Target,
root_output: &Path,
args: &ArgMatches<'_>,
args: &ArgMatches,
) -> CargoResult<HashMap<PackageId, PathBuf>> {
ws.emit_warnings()?;
let interner = UnitInterner::new();
Expand Down Expand Up @@ -954,7 +954,7 @@ pub struct CPackage {
impl CPackage {
fn from_package(
pkg: &mut Package,
args: &ArgMatches<'_>,
args: &ArgMatches,
libkinds: &[&str],
rustc_target: &target::Target,
root_output: &Path,
Expand Down Expand Up @@ -988,7 +988,7 @@ impl CPackage {
pub fn cbuild(
ws: &mut Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
default_profile: &str,
) -> anyhow::Result<(Vec<CPackage>, CompileOptions)> {
let rustc = config.load_global_rustc(Some(ws))?;
Expand All @@ -1002,13 +1002,18 @@ pub fn cbuild(
};

let rustc_target = target::Target::new(&target)?;
let libkinds = args.values_of("library-type").map_or_else(
|| match (rustc_target.os.as_str(), rustc_target.env.as_str()) {
("none", _) | (_, "musl") => vec!["staticlib"],
_ => vec!["staticlib", "cdylib"],
},
|v| v.collect::<Vec<_>>(),
);

let default_kind = || match (rustc_target.os.as_str(), rustc_target.env.as_str()) {
("none", _) | (_, "musl") => vec!["staticlib"],
_ => vec!["staticlib", "cdylib"],
};

let libkinds = if args._is_valid_arg("library-type") {
args.values_of("library-type")
.map_or_else(default_kind, |v| v.collect::<Vec<_>>())
} else {
default_kind()
};
let only_staticlib = !libkinds.contains(&"cdylib");
let only_cdylib = !libkinds.contains(&"staticlib");

Expand Down Expand Up @@ -1125,8 +1130,8 @@ pub fn cbuild(
.unwrap_or_else(|| PathBuf::from("dlltool"));

// dlltool argument overwrites environment var
if args.value_of("dlltool").is_some() {
dlltool = args.value_of("dlltool").map(PathBuf::from).unwrap();
if args.value_of_os("dlltool").is_some() {
dlltool = args.value_of_os("dlltool").map(PathBuf::from).unwrap();
}

build_implib_file(ws, lib_name, &rustc_target, &root_output, &dlltool)?;
Expand Down Expand Up @@ -1184,7 +1189,7 @@ pub fn cbuild(
pub fn ctest(
ws: &Workspace,
config: &Config,
args: &ArgMatches<'_>,
args: &ArgMatches,
packages: &[CPackage],
mut compile_opts: CompileOptions,
) -> CliResult {
Expand Down