Skip to content
Open
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,013 changes: 1,101 additions & 912 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions cargo-container-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0-alpha.3] - 2022-06-23
### Changed
- Cargo updated to `v0.62.0`.
- Fixes `edition = "2021"` issue

## [0.2.0-alpha.1] - 2019-12-01
### Changed
- Switched to stable Rust channel.
Expand Down
10 changes: 5 additions & 5 deletions cargo-container-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

[package]
name = "cargo-container-tools"
version = "0.2.0-alpha.2"
version = "0.2.0-alpha.3"
authors = ["Denys Zariaiev <denys.zariaiev@gmail.com>"]
edition = "2018"
publish = false
license = "MIT/Apache-2.0"

[dependencies]
cargo = "0.40"
cargo = "0.62"
clap = "2.33"
either = "1.5"
failure = "0.1"
anyhow = "1.0.57"
lazy_static = "1.4"
semver = "0.9"
toml = "0.5"
semver = "1"
toml_edit = {version = "0.13.4", features = ["easy", "serde"]}

serde = "1.0"
serde_json = "1.0"
Expand Down
52 changes: 37 additions & 15 deletions cargo-container-tools/src/bin/cargo-build-plan/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ use std::env::{current_dir, current_exe};
use std::fs::File;
use std::io::{copy, BufWriter};
use std::process::{exit, Command, Stdio};
use std::rc::Rc;
use std::sync::Arc;

use cargo::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor};
use cargo::core::resolver::CliFeatures;
use cargo::core::summary::FeatureValue;
use cargo::core::{Shell, Workspace};
use cargo::ops::{CompileFilter, CompileOptions, FilterRule, LibRule, Packages};
use cargo::util::interning::InternedString;
use cargo::util::{config::Config, CargoResult};

use anyhow::{bail, Context};
use clap::{crate_authors, crate_version, App, Arg, ArgMatches};
use failure::{bail, ResultExt};

fn main() {
let matches = get_cli_app().get_matches();

if let Err(error) = run(&matches) {
cargo::handle_error(&error, &mut Shell::new());
cargo::display_error(&error, &mut Shell::new());
exit(1);
}
}
Expand Down Expand Up @@ -123,29 +127,44 @@ fn run(matches: &ArgMatches<'static>) -> CargoResult<()> {

fn run_stdout(matches: &ArgMatches<'static>) -> CargoResult<()> {
let mut config = Config::default()?;
config.configure(0, None, &None, false, true, false, &None, &[])?;
config.configure(0, false, None, false, true, false, &None, &[], &[])?;

// TODO: Should I pass true to keep_going?
let mut build_config = BuildConfig::new(
&config,
Some(1),
false,
&matches
.value_of("target")
.map(String::from)
.into_iter()
.collect::<Vec<String>>(),
CompileMode::Build,
)?;
if matches.is_present("release") {
build_config.requested_profile = InternedString::new("release");
}

let mut build_config = BuildConfig::new(&config, Some(1), &None, CompileMode::Build)?;
build_config.release = matches.is_present("release");
build_config.force_rebuild = true;
build_config.build_plan = true;
build_config.requested_target = matches.value_of("target").map(String::from);

let features = {
let features = Rc::new(
matches
.values_of("features")
.unwrap_or_default()
.map(String::from)
.collect()
};
.map(InternedString::from)
.map(FeatureValue::Feature)
.collect(),
);

let options = CompileOptions {
config: &config,
build_config,

features,
all_features: false,
no_default_features: matches.is_present("no_default_features"),
cli_features: CliFeatures {
features,
all_features: false,
uses_default_features: !matches.is_present("no_default_features"),
},

spec: Packages::All,
filter: CompileFilter::Only {
Expand All @@ -160,7 +179,10 @@ fn run_stdout(matches: &ArgMatches<'static>) -> CargoResult<()> {
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,

honor_rust_version: true,
rustdoc_document_private_items: false,
target_rustc_crate_types: None,
};

let executor: Arc<dyn Executor> = Arc::new(DefaultExecutor);
Expand Down
6 changes: 3 additions & 3 deletions cargo-container-tools/src/bin/cargo-buildscript-apply/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

use std::process::{exit, Command, Stdio};

use anyhow::{bail, Context};
use cargo::core::Shell;
use cargo::util::CargoResult;
use clap::{crate_authors, crate_version, App, Arg, ArgMatches};
use failure::{bail, ResultExt};

use cargo_container_tools::BuildScriptOutput;

fn main() {
let matches = get_cli_app().get_matches();

if let Err(error) = run(&matches) {
cargo::handle_error(&error, &mut Shell::new());
cargo::display_error(&error, &mut Shell::new());
exit(1);
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ fn invoke_rustc<'a>(

let output = command
.output()
.with_context(|_| format!("Unable to spawn '{}'", bin_path))?;
.with_context(|| format!("Unable to spawn '{}'", bin_path))?;

if output.status.success() {
Ok(())
Expand Down
15 changes: 11 additions & 4 deletions cargo-container-tools/src/bin/cargo-buildscript-capture/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ use std::collections::BTreeMap;
use std::path::Path;
use std::process::{exit, Command, Stdio};

use anyhow::bail;
use anyhow::Context;
use cargo::core::{compiler::BuildOutput, Shell};
use cargo::util::CargoResult;
use clap::{crate_authors, crate_version, App, Arg, ArgMatches};
use failure::{bail, ResultExt};

use cargo_container_tools::{BuildScriptOutput, RuntimeEnv};

fn main() {
let matches = get_cli_app().get_matches();

if let Err(error) = run(&matches) {
cargo::handle_error(&error, &mut Shell::new());
cargo::display_error(&error, &mut Shell::new());
exit(1);
}
}
Expand Down Expand Up @@ -82,14 +83,20 @@ fn get_buildscript_output<'a>(
command
.args(bin_args)
.output()
.with_context(|_| format!("Unable to spawn '{}'", bin_path))?
.with_context(|| format!("Unable to spawn '{}'", bin_path))?
};

let package_name = RuntimeEnv::package_name()?;

let cargo_output_result = BuildOutput::parse(
&output.stdout,
RuntimeEnv::package_name()?,
Some(package_name.to_string()),
// pkg_descr is used for error messages
package_name,
RuntimeEnv::output_dir()?,
RuntimeEnv::output_dir()?,
true,
&[],
);

let cargo_output = match cargo_output_result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use cargo::util::{config::Config, CargoResult};

use clap::{crate_authors, crate_version, App, Arg, ArgMatches};
use either::Either;
use toml::Value;
use toml_edit::easy::Value;

use cargo_container_tools::metadata::*;

fn main() {
let matches = get_cli_app().get_matches();

if let Err(error) = run(&matches) {
cargo::handle_error(&error, &mut Shell::new());
cargo::display_error(&error, &mut Shell::new());
exit(1);
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ fn workspace_metadata(ws: &Workspace) -> Vec<Metadata> {

fn workspace_root_inner_metadata(ws: &Workspace) -> Option<Value> {
let manifest_contents = read_to_string(ws.root().join("Cargo.toml")).ok()?;
let manifest: manifest::Root = toml::from_str(&manifest_contents).ok()?;
let manifest: manifest::Root = toml_edit::easy::from_str(&manifest_contents).ok()?;

manifest.workspace?.metadata
}
4 changes: 2 additions & 2 deletions cargo-container-tools/src/bin/cargo-test-runner/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::process::{exit, Command, Stdio};
use cargo::core::Shell;
use cargo::util::CargoResult;

use anyhow::{bail, Context};
use clap::{crate_authors, crate_version, App, Arg, ArgMatches};
use failure::{bail, ResultExt};

fn main() {
let matches = get_cli_app().get_matches();

if let Err(error) = run(&matches) {
cargo::handle_error(&error, &mut Shell::new());
cargo::display_error(&error, &mut Shell::new());
exit(1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions cargo-container-tools/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;
use std::path::Path;

use anyhow::Error;
use cargo::util::CargoResult;
use failure::format_err;
use lazy_static::*;

lazy_static! {
Expand All @@ -18,14 +18,14 @@ impl RuntimeEnv {
OUT_DIR
.as_ref()
.map(|value| Path::new(value))
.ok_or_else(|| format_err!("unable to find OUT_DIR env variable"))
.ok_or_else(|| Error::msg("unable to find OUT_DIR env variable"))
}

pub fn package_name() -> CargoResult<&'static str> {
CARGO_PKG_NAME
.as_ref()
.map(|value| value.as_str())
.ok_or_else(|| format_err!("unable to find CARGO_PKG_NAME env variable"))
.ok_or_else(|| Error::msg("unable to find CARGO_PKG_NAME env variable"))
}

pub fn manifest_link_name() -> Option<&'static str> {
Expand Down
4 changes: 2 additions & 2 deletions cargo-container-tools/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use semver::Version;
use serde::{Deserialize, Serialize};
use toml::value::Value;
use toml_edit::easy::Value;

#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
Expand All @@ -26,6 +26,6 @@ pub mod manifest {

#[derive(Deserialize, Clone, Debug)]
pub struct Workspace {
pub metadata: Option<toml::Value>,
pub metadata: Option<toml_edit::easy::Value>,
}
}
9 changes: 7 additions & 2 deletions cargo-container-tools/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::path::{Path, PathBuf};

use anyhow::Context;
use cargo::core::compiler::BuildOutput;
use cargo::util::CargoResult;
use failure::ResultExt;
use serde_derive::{Deserialize, Serialize};

use crate::env::RuntimeEnv;
Expand Down Expand Up @@ -65,7 +65,12 @@ impl From<BuildOutput> for BuildScriptOutput {
Self {
library_paths: output.library_paths,
library_links: output.library_links,
linker_args: output.linker_args,
// TODO: Can we really drop all link types?
linker_args: output
.linker_args
.into_iter()
.map(|(_link_type, arg)| arg)
.collect(),
cfgs: output.cfgs,
env: output.env,
metadata: output.metadata,
Expand Down
2 changes: 1 addition & 1 deletion cargo-wharf-frontend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cfg_if::cfg_if! {
}
} else {
fn get_container_tools_ref() -> &'static str {
"denzp/cargo-container-tools:v0.2.0-alpha.1"
"denzp/cargo-container-tools:v0.2.0-alpha.3"
}
}
}