Skip to content

RUST-1934 Publish internal macros as their own crate #1109

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

Merged
merged 6 commits into from
May 22, 2024
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
6 changes: 6 additions & 0 deletions .evergreen/release-danger-do-not-run-manually.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ if [[ "${DRY_RUN}" == "yes" ]]; then
fi

if [[ "${PACKAGE_ONLY}" == "yes" ]]; then
pushd macros
cargo package --no-verify --allow-dirty
popd
cargo package --no-verify --allow-dirty
else
pushd macros
cargo publish --token $CRATES_IO_TOKEN ${EXTRA}
popd
cargo publish --token $CRATES_IO_TOKEN ${EXTRA}
fi
8 changes: 8 additions & 0 deletions .evergreen/release-sign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ docker run \
-w $(pwd) \
artifactory.corp.mongodb.com/release-tools-container-registry-local/garasign-gpg \
/bin/bash -c "gpgloader && gpg --yes -v --armor -o mongodb-${CRATE_VERSION}.sig --detach-sign target/package/mongodb-${CRATE_VERSION}.crate"

docker run \
--env-file=signing-envfile \
--rm \
-v $(pwd):$(pwd) \
-w $(pwd) \
artifactory.corp.mongodb.com/release-tools-container-registry-local/garasign-gpg \
/bin/bash -c "gpgloader && gpg --yes -v --armor -o mongodb-internal-macros-${CRATE_VERSION}.sig --detach-sign macros/target/package/mongodb-internal-macros-${CRATE_VERSION}.crate"
4 changes: 3 additions & 1 deletion .evergreen/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#
# If the changes need to be developed against the main branch, more steps are needed:
#
# 1. Add dummy version numbers to the Cargo.toml lines for action_macro, bson, and libmongocrypt
# 1. Add dummy version numbers to the Cargo.toml lines for mongodb-internal-macros, bson,
# and libmongocrypt
# 2. Comment out the "fetch tag" func call from the "publish-release" task in this file
# 3. Execute:
#
Expand Down Expand Up @@ -141,6 +142,7 @@ functions:
version: ${CRATE_VERSION}
filenames:
- src/target/package/mongodb-${CRATE_VERSION}.crate
- src/macros/target/package/mongodb-internal-macros-${CRATE_VERSION}.crate

"sign release":
- command: subprocess.exec
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ in-use-encryption-unstable = ["dep:mongocrypt", "dep:rayon", "dep:num_cpus"]
tracing-unstable = ["dep:tracing", "dep:log"]

[dependencies]
action_macro = { path = "action_macro" }
async-trait = "0.1.42"
base64 = "0.13.0"
bitflags = "1.1.0"
Expand All @@ -82,6 +81,7 @@ once_cell = "1.19.0"
log = { version = "0.4.17", optional = true }
md-5 = "0.10.1"
mongocrypt = { git = "https://github.com/mongodb/libmongocrypt-rust.git", branch = "main", optional = true }
mongodb-internal-macros = { path = "macros" }
num_cpus = { version = "1.13.1", optional = true }
openssl = { version = "0.10.38", optional = true }
openssl-probe = { version = "0.1.5", optional = true }
Expand Down
41 changes: 25 additions & 16 deletions etc/update_version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,54 @@ struct Args {
}

fn main() {
// nosemgrep: current-exe
let zero = std::env::current_exe().unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated but I got annoyed at having to prepend "../.." to every path.

let self_dir = zero.parent().unwrap();
let main_dir = self_dir.join("../../../..");
std::env::set_current_dir(main_dir).unwrap();

let version_locs = vec![
Location::new(
"../../Cargo.toml",
"Cargo.toml",
r#"name = "mongodb"\nversion = "(?<target>.*?)"\n"#,
),
Location::new("../../README.md", r#"mongodb = "(?<target>.*?)"\n"#),
Location::new(
"../../README.md",
r#"\[dependencies.mongodb\]\nversion = "(?<target>.*?)"\n"#,
"macros/Cargo.toml",
r#"name = "mongodb-internal-macros"\nversion = "(?<target>.*?)"\n"#,
),
Location::new("../../src/lib.rs", r#"//! mongodb = "(?<target>.*?)"\n"#),
Location::new("../../src/lib.rs", r#"//! version = "(?<target>.*?)"\n"#),
Location::new("README.md", r#"mongodb = "(?<target>.*?)"\n"#),
Location::new(
"../../src/lib.rs",
r#"html_root_url = "https://docs.rs/mongodb/(?<target>.*?)""#,
"README.md",
r#"\[dependencies.mongodb\]\nversion = "(?<target>.*?)"\n"#,
),
Location::new(
"../../manual/src/installation_features.md",
r#"\[dependencies.mongodb\]\nversion = "(?<target>.*?)"\n"#,
"src/lib.rs",
r#"html_root_url = "https://docs.rs/mongodb/(?<target>.*?)""#,
),
];
let bson_version_loc =
Location::new("../../Cargo.toml", r#"bson = (?<target>\{ git = .*? \})\n"#);
let mongocrypt_version_loc = Location::new(
"../../Cargo.toml",
r#"mongocrypt = (?<target>\{ git = .*? \})\n"#,
let quote_version_loc = Location::new(
"Cargo.toml",
r#"mongodb-internal-macros = (?<target>\{ path = .* \})\n"#,
);
let bson_version_loc = Location::new("Cargo.toml", r#"bson = (?<target>\{ git = .*? \})\n"#);
let mongocrypt_version_loc =
Location::new("Cargo.toml", r#"mongocrypt = (?<target>\{ git = .*? \})\n"#);

let args: Args = argh::from_env();

let mut pending = PendingUpdates::new();
for loc in &version_locs {
pending.apply(loc, &args.version);
}
pending.apply(&quote_version_loc, &format!("{:?}", args.version));
if let Some(bson) = args.bson {
pending.apply(&bson_version_loc, &format!("{:?}", bson));
}
if let Some(mongocrypt) = args.mongocrypt {
pending.apply(&mongocrypt_version_loc, &format!("{{ version = {:?}, optional = true }}", mongocrypt));
pending.apply(
&mongocrypt_version_loc,
&format!("{{ version = {:?}, optional = true }}", mongocrypt),
);
}
pending.write();
}
File renamed without changes.
4 changes: 2 additions & 2 deletions action_macro/Cargo.toml → macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "action_macro"
version = "0.1.0"
name = "mongodb-internal-macros"
version = "2.8.0"
edition = "2021"
license = "Apache-2.0"

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Single;
#[allow(missing_docs)]
pub struct Multiple;

use action_macro::option_setters;
use mongodb_internal_macros::option_setters;

pub(crate) mod private {
pub trait Sealed {}
Expand Down Expand Up @@ -109,7 +109,7 @@ pub trait Action: private::Sealed + IntoFuture {
}
}

pub(crate) use action_macro::{action_impl, deeplink};
pub(crate) use mongodb_internal_macros::{action_impl, deeplink};

use crate::Collection;

Expand Down