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 Rust 2024 edition #913

Merged
merged 1 commit into from
Feb 24, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Raised Minimum Supported Rust Version (MSRV) to `1.85`. ([#913](https://github.com/heroku/libcnb.rs/pull/913))
- Updated to Rust 2024 edition. ([#913](https://github.com/heroku/libcnb.rs/pull/913))
- `libcnb`:
- Implemented custom OTLP File Exporter instead of `opentelemetry-stdout` and updated `opentelemetry` libraries to `0.28`. ([#909](https://github.com/heroku/libcnb.rs/pull/909/))

Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ members = [

[workspace.package]
version = "0.26.1"
rust-version = "1.76"
edition = "2021"
rust-version = "1.85"
edition = "2024"
license = "BSD-3-Clause"

[workspace.lints.rust]
Expand All @@ -35,8 +35,6 @@ pedantic = { level = "warn", priority = -1 }
unwrap_used = "warn"
# In most cases adding error docs provides little value.
missing_errors_doc = "allow"
# This lint is too noisy and enforces a style that reduces readability in many cases.
module_name_repetitions = "allow"

[workspace.dependencies]
libcnb = { version = "=0.26.1", path = "libcnb" }
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder};
use libcnb::generic::{GenericError, GenericMetadata, GenericPlatform};
use libcnb::{buildpack_main, Buildpack};
use libcnb::{Buildpack, buildpack_main};

pub(crate) struct BasicBuildpack;

Expand Down
2 changes: 1 addition & 1 deletion examples/execd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
use libcnb::data::layer_name;
use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder};
use libcnb::generic::{GenericError, GenericMetadata, GenericPlatform};
use libcnb::{additional_buildpack_binary_path, buildpack_main, Buildpack};
use libcnb::{Buildpack, additional_buildpack_binary_path, buildpack_main};

// Suppress warnings due to the `unused_crate_dependencies` lint not handling integration tests well.
use fastrand as _;
Expand Down
2 changes: 1 addition & 1 deletion examples/execd/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use libcnb_test::{assert_contains, assert_empty, BuildConfig, TestRunner};
use libcnb_test::{BuildConfig, TestRunner, assert_contains, assert_empty};

#[test]
#[ignore = "integration test"]
Expand Down
9 changes: 6 additions & 3 deletions libcnb-cargo/src/package/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use crate::cli::PackageArgs;
use crate::package::error::Error;
use libcnb_data::buildpack::BuildpackId;
use libcnb_package::buildpack_dependency_graph::build_libcnb_buildpacks_dependency_graph;
use libcnb_package::cross_compile::{cross_compile_assistance, CrossCompileAssistance};
use libcnb_package::cross_compile::{CrossCompileAssistance, cross_compile_assistance};
use libcnb_package::dependency_graph::get_dependencies;
use libcnb_package::output::create_packaged_buildpack_dir_resolver;
use libcnb_package::util::absolutize_path;
use libcnb_package::{find_cargo_workspace_root_dir, CargoProfile};
use libcnb_package::{CargoProfile, find_cargo_workspace_root_dir};
use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};

#[allow(clippy::too_many_lines)]
pub(crate) fn execute(args: &PackageArgs) -> Result<(), Error> {
let current_dir = std::env::current_dir().map_err(Error::CannotGetCurrentDir)?;

Expand Down Expand Up @@ -49,7 +50,9 @@ pub(crate) fn execute(args: &PackageArgs) -> Result<(), Error> {
"Couldn't determine automatic cross-compile settings for target triple {}.",
args.target
);
eprintln!("This is not an error, but without proper cross-compile settings in your Cargo manifest and locally installed toolchains, compilation might fail.");
eprintln!(
"This is not an error, but without proper cross-compile settings in your Cargo manifest and locally installed toolchains, compilation might fail."
);
eprintln!("To disable this warning, pass --no-cross-compile-assistance.");
Vec::new()
}
Expand Down
10 changes: 6 additions & 4 deletions libcnb-cargo/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use libcnb_common::toml_file::read_toml_file;
use libcnb_data::buildpack::{BuildpackDescriptor, BuildpackId};
use libcnb_data::buildpack_id;
use libcnb_data::package_descriptor::{PackageDescriptor, PackageDescriptorDependency};
use libcnb_package::output::create_packaged_buildpack_dir_resolver;
use libcnb_package::CargoProfile;
use libcnb_package::output::create_packaged_buildpack_dir_resolver;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs};
use tempfile::{tempdir_in, TempDir};
use tempfile::{TempDir, tempdir_in};

#[test]
#[ignore = "integration test"]
Expand Down Expand Up @@ -58,8 +58,9 @@ fn package_single_composite_buildpack_in_monorepo_buildpack_project() {
.output()
.unwrap();

let package_dir = fixture_dir.path().join(DEFAULT_PACKAGE_DIR_NAME);
let packaged_buildpack_dir_resolver = create_packaged_buildpack_dir_resolver(
&fixture_dir.path().join(DEFAULT_PACKAGE_DIR_NAME),
&package_dir,
CargoProfile::Release,
X86_64_UNKNOWN_LINUX_MUSL,
);
Expand Down Expand Up @@ -144,8 +145,9 @@ fn package_all_buildpacks_in_monorepo_buildpack_project() {
.output()
.unwrap();

let package_dir = fixture_dir.path().join(DEFAULT_PACKAGE_DIR_NAME);
let packaged_buildpack_dir_resolver = create_packaged_buildpack_dir_resolver(
&fixture_dir.path().join(DEFAULT_PACKAGE_DIR_NAME),
&package_dir,
CargoProfile::Release,
X86_64_UNKNOWN_LINUX_MUSL,
);
Expand Down
2 changes: 1 addition & 1 deletion libcnb-common/src/toml_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};
use std::{fs, path::Path};

/// An error that occurred during reading or writing a TOML file.
Expand Down
2 changes: 1 addition & 1 deletion libcnb-data/src/build_plan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::ser::Error;
use serde::Serialize;
use serde::ser::Error;
use std::collections::VecDeque;
use toml::value::Table;

Expand Down
2 changes: 1 addition & 1 deletion libcnb-data/src/buildpack/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum BuildpackApiError {

#[cfg(test)]
mod tests {
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
use serde_test::{Token, assert_de_tokens, assert_de_tokens_error};

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion libcnb-data/src/buildpack/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub enum BuildpackVersionError {

#[cfg(test)]
mod tests {
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
use serde_test::{Token, assert_de_tokens, assert_de_tokens_error};

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion libcnb-data/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ libcnb_newtype!(
#[cfg(test)]
mod tests {
use super::*;
use serde_test::{assert_ser_tokens, Token};
use serde_test::{Token, assert_ser_tokens};

#[test]
fn launch_builder_add_processes() {
Expand Down
2 changes: 1 addition & 1 deletion libcnb-data/src/newtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub(crate) use libcnb_newtype;

#[cfg(test)]
mod tests {
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
use serde_test::{Token, assert_de_tokens, assert_de_tokens_error};

libcnb_newtype!(
newtypes::tests,
Expand Down
6 changes: 3 additions & 3 deletions libcnb-package/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::CargoProfile;
use crate::cargo::{
cargo_binary_target_names, determine_buildpack_cargo_target_name,
DetermineBuildpackCargoTargetNameError,
DetermineBuildpackCargoTargetNameError, cargo_binary_target_names,
determine_buildpack_cargo_target_name,
};
use crate::CargoProfile;
use cargo_metadata::Metadata;
use std::collections::HashMap;
use std::ffi::OsString;
Expand Down
33 changes: 14 additions & 19 deletions libcnb-package/src/buildpack_dependency_graph.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::buildpack_kind::determine_buildpack_kind;
use crate::buildpack_kind::BuildpackKind;
use crate::buildpack_kind::determine_buildpack_kind;
use crate::dependency_graph::{
create_dependency_graph, CreateDependencyGraphError, DependencyNode,
CreateDependencyGraphError, DependencyNode, create_dependency_graph,
};
use crate::find_buildpack_dirs;
use crate::package_descriptor::buildpack_id_from_libcnb_dependency;
use libcnb_common::toml_file::{read_toml_file, TomlFileError};
use libcnb_common::toml_file::{TomlFileError, read_toml_file};
use libcnb_data::buildpack::{BuildpackDescriptor, BuildpackId, BuildpackIdError};
use libcnb_data::package_descriptor::PackageDescriptor;
use petgraph::Graph;
Expand Down Expand Up @@ -58,22 +58,17 @@ fn build_libcnb_buildpack_dependency_graph_node(
.map_err(BuildBuildpackDependencyGraphError::ReadBuildpackDescriptorError)
.map(|buildpack_descriptor| buildpack_descriptor.buildpack().id.clone())?;

let dependencies = {
let package_toml_path = buildpack_directory.join("package.toml");

package_toml_path
.is_file()
.then(|| {
read_toml_file::<PackageDescriptor>(package_toml_path)
.map_err(BuildBuildpackDependencyGraphError::ReadPackageDescriptorError)
.and_then(|package_descriptor| {
get_buildpack_dependencies(&package_descriptor).map_err(
BuildBuildpackDependencyGraphError::InvalidDependencyBuildpackId,
)
})
})
.unwrap_or(Ok(Vec::new()))
}?;
let package_toml_path = buildpack_directory.join("package.toml");
let dependencies = if package_toml_path.is_file() {
read_toml_file::<PackageDescriptor>(package_toml_path)
.map_err(BuildBuildpackDependencyGraphError::ReadPackageDescriptorError)
.and_then(|package_descriptor| {
get_buildpack_dependencies(&package_descriptor)
.map_err(BuildBuildpackDependencyGraphError::InvalidDependencyBuildpackId)
})?
} else {
Vec::new()
};

Ok(BuildpackDependencyGraphNode {
buildpack_id,
Expand Down
4 changes: 2 additions & 2 deletions libcnb-package/src/dependency_graph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use petgraph::visit::DfsPostOrder;
use petgraph::Graph;
use petgraph::visit::DfsPostOrder;
use std::error::Error;

/// A node of a dependency graph.
Expand Down Expand Up @@ -107,7 +107,7 @@ pub enum GetDependenciesError<I> {

#[cfg(test)]
mod tests {
use crate::dependency_graph::{create_dependency_graph, get_dependencies, DependencyNode};
use crate::dependency_graph::{DependencyNode, create_dependency_graph, get_dependencies};
use std::convert::Infallible;

impl DependencyNode<String, Infallible> for (&str, Vec<&str>) {
Expand Down
2 changes: 1 addition & 1 deletion libcnb-package/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub fn default_buildpack_directory_name(buildpack_id: &BuildpackId) -> String {

#[cfg(test)]
mod tests {
use crate::output::create_packaged_buildpack_dir_resolver;
use crate::CargoProfile;
use crate::output::create_packaged_buildpack_dir_resolver;
use libcnb_data::buildpack_id;
use std::path::PathBuf;

Expand Down
8 changes: 4 additions & 4 deletions libcnb-package/src/package.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::build::build_buildpack_binaries;
use crate::buildpack_kind::{determine_buildpack_kind, BuildpackKind};
use crate::package_descriptor::{normalize_package_descriptor, NormalizePackageDescriptorError};
use crate::{assemble_buildpack_directory, CargoProfile};
use crate::buildpack_kind::{BuildpackKind, determine_buildpack_kind};
use crate::package_descriptor::{NormalizePackageDescriptorError, normalize_package_descriptor};
use crate::{CargoProfile, assemble_buildpack_directory};
use cargo_metadata::MetadataCommand;
use libcnb_common::toml_file::{read_toml_file, write_toml_file, TomlFileError};
use libcnb_common::toml_file::{TomlFileError, read_toml_file, write_toml_file};
use libcnb_data::buildpack::BuildpackId;
use libcnb_data::package_descriptor::PackageDescriptor;
use std::collections::BTreeMap;
Expand Down
2 changes: 1 addition & 1 deletion libcnb-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use proc_macro::TokenStream;
use quote::quote;
use std::path::PathBuf;
use syn::Token;
use syn::parse::{Parse, ParseStream};
use syn::parse_macro_input;
use syn::Token;

/// Compiles the given regex using the `fancy_regex` crate and tries to match the given value. If
/// the value matches the regex, the macro will expand to the first expression. Otherwise it will
Expand Down
2 changes: 1 addition & 1 deletion libcnb-test/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fs_extra::dir::CopyOptions;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use tempfile::{tempdir, TempDir};
use tempfile::{TempDir, tempdir};

/// Copies an application directory to a temporary location.
pub(crate) fn copy_app(app_dir: impl AsRef<Path>) -> Result<AppDir, PrepareAppError> {
Expand Down
10 changes: 5 additions & 5 deletions libcnb-test/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use libcnb_common::toml_file::{read_toml_file, TomlFileError};
use libcnb_common::toml_file::{TomlFileError, read_toml_file};
use libcnb_data::buildpack::{BuildpackDescriptor, BuildpackId};
use libcnb_package::buildpack_dependency_graph::{
build_libcnb_buildpacks_dependency_graph, BuildBuildpackDependencyGraphError,
BuildBuildpackDependencyGraphError, build_libcnb_buildpacks_dependency_graph,
};
use libcnb_package::cross_compile::{cross_compile_assistance, CrossCompileAssistance};
use libcnb_package::dependency_graph::{get_dependencies, GetDependenciesError};
use libcnb_package::cross_compile::{CrossCompileAssistance, cross_compile_assistance};
use libcnb_package::dependency_graph::{GetDependenciesError, get_dependencies};
use libcnb_package::output::create_packaged_buildpack_dir_resolver;
use libcnb_package::{find_cargo_workspace_root_dir, CargoProfile, FindCargoWorkspaceRootError};
use libcnb_package::{CargoProfile, FindCargoWorkspaceRootError, find_cargo_workspace_root_dir};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::{fs, io};
Expand Down
2 changes: 1 addition & 1 deletion libcnb-test/src/container_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::docker::{
};
use crate::log::LogOutput;
use crate::util::CommandError;
use crate::{util, ContainerConfig};
use crate::{ContainerConfig, util};
use std::net::SocketAddr;

/// Context of a launched container.
Expand Down
8 changes: 5 additions & 3 deletions libcnb-test/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ mod tests {
// Assert conditional '--trust-builder' flag works as expected:
input.trust_builder = false;
let command: Command = input.clone().into();
assert!(!command
.get_args()
.any(|arg| arg == OsStr::new("--trust-builder")));
assert!(
!command
.get_args()
.any(|arg| arg == OsStr::new("--trust-builder"))
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions libcnb-test/src/test_context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::docker::DockerRunCommand;
use crate::pack::PackSbomDownloadCommand;
use crate::{
util, BuildConfig, ContainerConfig, ContainerContext, LogOutput, TemporaryDockerResources,
TestRunner,
BuildConfig, ContainerConfig, ContainerContext, LogOutput, TemporaryDockerResources,
TestRunner, util,
};
use libcnb_data::buildpack::BuildpackId;
use libcnb_data::layer::LayerName;
Expand Down
4 changes: 2 additions & 2 deletions libcnb-test/src/test_runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::docker::{DockerRemoveImageCommand, DockerRemoveVolumeCommand};
use crate::pack::PackBuildCommand;
use crate::util::CommandError;
use crate::{app, build, util, BuildConfig, BuildpackReference, PackResult, TestContext};
use crate::{BuildConfig, BuildpackReference, PackResult, TestContext, app, build, util};
use std::borrow::Borrow;
use std::env;
use std::path::PathBuf;
Expand Down Expand Up @@ -146,7 +146,7 @@ impl TestRunner {
BuildpackReference::Other(id) => {
pack_command.buildpack(id.clone());
}
};
}
}

let pack_result = util::run_command(pack_command);
Expand Down
6 changes: 3 additions & 3 deletions libcnb-test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use indoc::{formatdoc, indoc};
use libcnb_data::buildpack_id;
use libcnb_test::{
assert_contains, assert_empty, assert_not_contains, BuildConfig, BuildpackReference,
ContainerConfig, PackResult, TestRunner,
BuildConfig, BuildpackReference, ContainerConfig, PackResult, TestRunner, assert_contains,
assert_empty, assert_not_contains,
};
use std::path::PathBuf;
use std::time::Duration;
Expand Down Expand Up @@ -686,7 +686,7 @@ fn address_for_port_when_port_not_exposed() {
fn address_for_port_when_container_crashed() {
let mut container_name = String::new();

// AssertUnwindSafe is required so that `container_name`` can be mutated across the unwind boundary.
// AssertUnwindSafe is required so that `container_name` can be mutated across the unwind boundary.
let err = panic::catch_unwind(panic::AssertUnwindSafe(|| {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/procfile")
Expand Down
Loading