Skip to content

Commit

Permalink
Bump cargo version
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero committed May 3, 2024
1 parent 1395afb commit 67e1aaa
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cargo-c"
version = "0.9.31+cargo-0.78.0"
version = "0.9.31+cargo-0.79.0"
authors = ["Luca Barbato <lu_zero@gentoo.org>"]
description = "Helper program to build and install c-like libraries"
license = "MIT"
Expand Down Expand Up @@ -28,7 +28,7 @@ name = "cargo-ctest"
path = "src/bin/ctest.rs"

[dependencies]
cargo = "0.78.0"
cargo = "0.79.0"
cargo-util = "0.2"
semver = "1.0.3"
log = "0.4"
Expand Down
7 changes: 3 additions & 4 deletions src/bin/capi.rs
Expand Up @@ -5,13 +5,12 @@ use cargo_c::install::cinstall;

use cargo::util::command_prelude::flag;
use cargo::util::command_prelude::ArgMatchesExt;
use cargo::CliResult;
use cargo::Config;
use cargo::{CliResult, GlobalContext};

use clap::*;

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

let cli_build = subcommand_build("build", "Build the crate C-API");
let cli_install = subcommand_install("install", "Install the crate C-API");
Expand Down Expand Up @@ -60,7 +59,7 @@ fn main() -> CliResult {
return Ok(());
}

config_configure(&mut config, subcommand_args)?;
global_context_configure(&mut config, subcommand_args)?;

let mut ws = subcommand_args.workspace(&config)?;

Expand Down
6 changes: 3 additions & 3 deletions src/bin/cbuild.rs
@@ -1,14 +1,14 @@
use cargo::util::command_prelude::ArgMatchesExt;
use cargo::CliResult;
use cargo::Config;
use cargo::GlobalContext;

use cargo_c::build::*;
use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_build;
use cargo_c::config::*;

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

let subcommand = subcommand_build("cbuild", "Build the crate C-API");
let mut app = clap::command!()
Expand All @@ -35,7 +35,7 @@ fn main() -> CliResult {
return Ok(());
}

config_configure(&mut config, subcommand_args)?;
global_context_configure(&mut config, subcommand_args)?;

let mut ws = subcommand_args.workspace(&config)?;

Expand Down
8 changes: 4 additions & 4 deletions src/bin/cinstall.rs
@@ -1,15 +1,15 @@
use cargo::util::command_prelude::ArgMatchesExt;
use cargo::CliResult;
use cargo::Config;
use cargo::GlobalContext;

use cargo_c::build::cbuild;
use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_install;
use cargo_c::config::config_configure;
use cargo_c::config::global_context_configure;
use cargo_c::install::cinstall;

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

let subcommand = subcommand_install("cinstall", "Install the crate C-API");
let mut app = clap::command!()
Expand All @@ -36,7 +36,7 @@ fn main() -> CliResult {
return Ok(());
}

config_configure(&mut config, subcommand_args)?;
global_context_configure(&mut config, subcommand_args)?;

let mut ws = subcommand_args.workspace(&config)?;

Expand Down
4 changes: 2 additions & 2 deletions src/bin/ctest.rs
Expand Up @@ -6,7 +6,7 @@ use cargo_c::cli::subcommand_test;
use cargo_c::config::*;

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

let subcommand = subcommand_test("ctest");

Expand Down Expand Up @@ -34,7 +34,7 @@ fn main() -> CliResult {
return Ok(());
}

config_configure(&mut config, subcommand_args)?;
global_context_configure(&mut config, subcommand_args)?;

let mut ws = subcommand_args.workspace(&config)?;

Expand Down
32 changes: 15 additions & 17 deletions src/build.rs
Expand Up @@ -10,7 +10,7 @@ use cargo::core::{FeatureValue, Package, PackageId, Target, TargetKind, Workspac
use cargo::ops::{self, CompileFilter, CompileOptions, FilterRule, LibRule};
use cargo::util::command_prelude::{ArgMatches, ArgMatchesExt, CompileMode, ProfileChecking};
use cargo::util::interning::InternedString;
use cargo::{CliResult, Config};
use cargo::{CliResult, GlobalContext};

use anyhow::Context as _;
use cargo_util::paths::{copy, create, create_dir_all, open, read, read_bytes, write};
Expand All @@ -29,7 +29,7 @@ fn build_include_file(
root_output: &Path,
root_path: &Path,
) -> anyhow::Result<()> {
ws.config()
ws.gctx()
.shell()
.status("Building", "header file using cbindgen")?;
let mut header_name = PathBuf::from(name);
Expand Down Expand Up @@ -64,7 +64,7 @@ fn copy_prebuilt_include_file(
build_targets: &BuildTargets,
root_output: &Path,
) -> anyhow::Result<()> {
let mut shell = ws.config().shell();
let mut shell = ws.gctx().shell();
shell.status("Populating", "uninstalled header directory")?;
let path = &format!("PKG_CONFIG_PATH=\"{}\"", root_output.display());
shell.verbose(move |s| s.note(path))?;
Expand All @@ -90,7 +90,7 @@ fn build_pc_files(
root_output: &Path,
pc: &PkgConfig,
) -> anyhow::Result<()> {
ws.config().shell().status("Building", "pkg-config files")?;
ws.gctx().shell().status("Building", "pkg-config files")?;
build_pc_file(filename, root_output, pc)?;
let pc_uninstalled = pc.uninstalled(root_output);
build_pc_file(
Expand Down Expand Up @@ -140,7 +140,7 @@ fn build_def_file(
let env = &target.env;

if os == "windows" && env == "msvc" {
ws.config()
ws.gctx()
.shell()
.status("Building", ".def file using dumpbin")?;

Expand Down Expand Up @@ -213,7 +213,7 @@ fn build_implib_file(
if os == "windows" {
let arch = &target.arch;
if env == "gnu" {
ws.config()
ws.gctx()
.shell()
.status("Building", "implib using dlltool")?;

Expand Down Expand Up @@ -242,7 +242,7 @@ fn build_implib_file(
Err(anyhow::anyhow!("Command failed {:?}", dlltool_command))
}
} else {
ws.config().shell().status("Building", "implib using lib")?;
ws.gctx().shell().status("Building", "implib using lib")?;
let target_str = format!("{}-pc-windows-msvc", &target.arch);
let mut lib = match cc::windows_registry::find(&target_str, "lib.exe") {
Some(command) => command,
Expand Down Expand Up @@ -802,14 +802,14 @@ fn load_manifest_capi_config(

fn compile_options(
ws: &Workspace,
config: &Config,
gctx: &GlobalContext,
args: &ArgMatches,
profile: InternedString,
compile_mode: CompileMode,
) -> anyhow::Result<CompileOptions> {
use cargo::core::compiler::CompileKind;
let mut compile_opts =
args.compile_options(config, compile_mode, Some(ws), ProfileChecking::Custom)?;
args.compile_options(gctx, compile_mode, Some(ws), ProfileChecking::Custom)?;

compile_opts.build_config.requested_profile = profile;

Expand All @@ -827,12 +827,12 @@ fn compile_options(

compile_opts.build_config.unit_graph = false;

let rustc = config.load_global_rustc(Some(ws))?;
let rustc = gctx.load_global_rustc(Some(ws))?;

// Always set the target, requested_kinds is a vec of a single element.
if compile_opts.build_config.requested_kinds[0].is_host() {
compile_opts.build_config.requested_kinds =
CompileKind::from_requested_targets(config, &[rustc.host.to_string()])?
CompileKind::from_requested_targets(gctx, &[rustc.host.to_string()])?
}

Ok(compile_opts)
Expand Down Expand Up @@ -893,7 +893,6 @@ impl Executor for Exec {

use cargo::core::compiler::{unit_graph, UnitInterner};
use cargo::ops::create_bcx;
use cargo::util::profile;

fn set_deps_args(
dep: &UnitDep,
Expand Down Expand Up @@ -959,11 +958,10 @@ fn compile_with_exec(
}

if options.build_config.unit_graph {
unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph, ws.config())?;
unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph, ws.gctx())?;
return Ok(HashMap::new());
}
let _p = profile::start("compiling");
let cx = cargo::core::compiler::Context::new(&bcx)?;
let cx = cargo::core::compiler::BuildRunner::new(&bcx)?;

let r = cx.compile(exec)?;

Expand Down Expand Up @@ -1039,7 +1037,7 @@ impl CPackage {

pub fn cbuild(
ws: &mut Workspace,
config: &Config,
config: &GlobalContext,
args: &ArgMatches,
default_profile: &str,
) -> anyhow::Result<(Vec<CPackage>, CompileOptions)> {
Expand Down Expand Up @@ -1240,7 +1238,7 @@ pub fn cbuild(

pub fn ctest(
ws: &Workspace,
config: &Config,
config: &GlobalContext,
args: &ArgMatches,
packages: &[CPackage],
mut compile_opts: CompileOptions,
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
@@ -1,7 +1,7 @@
use std::env;

use cargo::util::command_prelude::{ArgMatches, ArgMatchesExt};
use cargo::{CliResult, Config};
use cargo::{CliResult, GlobalContext};

// Take the original cargo instance and save it as a separate env var if not already set.
fn setup_env() {
Expand All @@ -12,14 +12,14 @@ fn setup_env() {
}
}

pub fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult {
let arg_target_dir = &args.value_of_path("target-dir", config);
pub fn global_context_configure(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let arg_target_dir = &args.value_of_path("target-dir", gctx);
let config_args: Vec<_> = args
.get_many::<String>("config")
.unwrap_or_default()
.map(|s| s.to_owned())
.collect();
config.configure(
gctx.configure(
args.verbose(),
args.flag("quiet"),
args.get_one::<String>("color").map(String::as_str),
Expand Down
12 changes: 5 additions & 7 deletions src/install.rs
Expand Up @@ -198,17 +198,15 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
create_dir_all(&install_path_lib)?;
create_dir_all(&install_path_pc)?;

ws.config()
.shell()
.status("Installing", "pkg-config file")?;
ws.gctx().shell().status("Installing", "pkg-config file")?;

copy(
&build_targets.pc,
install_path_pc.join(build_targets.pc.file_name().unwrap()),
)?;

if capi_config.header.enabled {
ws.config().shell().status("Installing", "header file")?;
ws.gctx().shell().status("Installing", "header file")?;
for (from, to) in build_targets.extra.include.iter() {
let to = install_path_include.join(to);
create_dir_all(to.parent().unwrap())?;
Expand All @@ -217,7 +215,7 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
}

if !build_targets.extra.data.is_empty() {
ws.config().shell().status("Installing", "data file")?;
ws.gctx().shell().status("Installing", "data file")?;
for (from, to) in build_targets.extra.data.iter() {
let to = install_path_data.join(to);
create_dir_all(to.parent().unwrap())?;
Expand All @@ -226,15 +224,15 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
}

if let Some(ref static_lib) = build_targets.static_lib {
ws.config().shell().status("Installing", "static library")?;
ws.gctx().shell().status("Installing", "static library")?;
copy(
static_lib,
install_path_lib.join(static_lib.file_name().unwrap()),
)?;
}

if let Some(ref shared_lib) = build_targets.shared_lib {
ws.config().shell().status("Installing", "shared library")?;
ws.gctx().shell().status("Installing", "shared library")?;

let lib_type = LibType::from_build_targets(build_targets);
match lib_type {
Expand Down

0 comments on commit 67e1aaa

Please sign in to comment.