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

Move nightly toolchain scripts to xtasks #1790

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
- name: Verify dependencies
run: |
find sdk/ -maxdepth 3 -type f -name Cargo.toml -exec bash -c 'eng/scripts/verify-dependencies.rs {}' \;
find sdk/ -maxdepth 3 -type f -name Cargo.toml -exec bash -c 'cargo --quiet xtask verify-dependencies {}' \;
5 changes: 4 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"asyncoperation",
"azsdk",
"azurecli",
"buildable",
"codespaces",
"datalake",
"devicecode",
"downcasted",
Expand All @@ -35,7 +37,8 @@
"servicebus",
"stylesheet",
"typespec",
"virtualmachine"
"virtualmachine",
"xtask"
],
"dictionaryDefinitions": [
{
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"cSpell.enabled": true,
"editor.formatOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.features": "all",
"yaml.format.printWidth": 240,
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell",
},
"yaml.format.printWidth": 240
}
}
73 changes: 73 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Azure SDK for Rust Contributing Guide

Thank you for your interest in contributing to Azure SDK for Rust.

- For reporting bugs, requesting features, or asking for support, please file an issue in the [issues](https://github.com/Azure/azure-sdk-for-rust/issues) section of the project.
- If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](https://azure.github.io/azure-sdk/policies_opensource.html).
- To make code changes, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the repo, make the change and propose it back by submitting a pull request.

## Pull Requests

- **DO** follow the API design and implementation [Rust Guidelines](https://azure.github.io/azure-sdk/rust_introduction.html).

When submitting large changes or features, **DO** have an issue or spec doc that describes the design, usage, and motivating scenario.

- **DO** submit all code changes via pull requests (PRs) rather than through a direct commit. PRs will be reviewed and potentially merged by the repo maintainers after a peer review that includes at least one maintainer.
- **DO** review your own PR to make sure there are no unintended changes or commits before submitting it.
- **DO NOT** submit "work in progress" PRs. A PR should only be submitted when it is considered ready for review and subsequent merging by the contributor.

If the change is work-in-progress or an experiment, **DO** start off as a temporary draft PR.

- **DO** give PRs short-but-descriptive names (e.g. "Improve code coverage for Azure.Core by 10%", not "Fix #1234") and add a description which explains why the change is being made.
- **DO** refer to any relevant issues, and include [keywords](https://help.github.com/articles/closing-issues-via-commit-messages/) that automatically close issues when the PR is merged.
- **DO** tag any users that should know about and/or review the change.
- **DO** ensure each commit successfully builds. The entire PR must pass all tests in the Continuous Integration (CI) system before it'll be merged.
- **DO** address PR feedback in an additional commit(s) rather than amending the existing commits, and only rebase/squash them when necessary. This makes it easier for reviewers to track changes.
- **DO** assume that ["Squash and Merge"](https://github.com/blog/2141-squash-your-commits) will be used to merge your commit unless you request otherwise in the PR.
- **DO NOT** mix independent, unrelated changes in one PR. Separate real product/test code changes from larger code formatting/dead code removal changes. Separate unrelated fixes into separate PRs, especially if they are in different modules or files that otherwise wouldn't be changed.
- **DO** comment your code focusing on "why", where necessary. Otherwise, aim to keep it self-documenting with appropriate names and style.
- **DO** add [GoDoc style comments](https://azure.github.io/azure-sdk/golang_introduction.html#documentation-style) when adding new APIs or modifying header files.
- **DO** make sure there are no typos or spelling errors, especially in user-facing documentation.
- **DO** verify if your changes have impact elsewhere. For instance, do you need to update other docs or exiting markdown files that might be impacted?
- **DO** add relevant unit tests to ensure CI will catch future regressions.

## Merging Pull Requests (for project contributors with write access)

- **DO** use ["Squash and Merge"](https://github.com/blog/2141-squash-your-commits) by default for individual contributions unless requested by the PR author.
Do so, even if the PR contains only one commit. It creates a simpler history than "Create a Merge Commit".
Reasons that PR authors may request "Merge and Commit" may include (but are not limited to):

- The change is easier to understand as a series of focused commits. Each commit in the series must be buildable so as not to break `git bisect`.
- Contributor is using an e-mail address other than the primary GitHub address and wants that preserved in the history. Contributor must be willing to squash the commits manually before acceptance.

## Developer Guide

### Codespaces

Codespaces allows you to use a container as your development environment. This repo provides a Codespaces container which is supported by both GitHub Codespaces and VS Code Codespaces.

#### GitHub Codespaces

1. From the Azure SDK GitHub repo, click on the "Code -> Open with Codespaces" button.
1. Open a Terminal. The development environment will be ready for you. Continue to [Building and Testing](https://github.com/Azure/azure-sdk-for-rust/blob/feature/track2/CONTRIBUTING.md#building-and-testing).

#### VS Code Codespaces

1. Install the [VS Code Remote Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)
1. When you open the Azure SDK for Rust repo in VS Code, it will prompt you to open the project in the Dev Container. If it does not prompt you, then hit CTRL+P, and select "Remote-Containers: Open Folder in Container..."
1. Open a Terminal. The development environment will be ready for you. Continue to [Building and Testing](https://github.com/Azure/azure-sdk-for-rust/blob/feature/track2/CONTRIBUTING.md#building-and-testing).

### Building and Testing

#### Building

You can use common `cargo` commands such as `cargo build` to build the entire workspace, or `cargo build --package azure_core` to build a single package e.g., `azure_core`.

##### Additional Tasks

You can discover additional tasks by running `cargo xtask --help` from any directory in the workspace.

#### Testing

You can use common `cargo` commands such as `cargo test` to test the entire workspace, or `cargo test --package azure_core` to test a single package e.g., `azure_core`. `cargo test --help` provides help for additional options.
Our build and test pipeline for Pull Requests will enforce more rules but run all the same commands you can locally. For example, we encourage you to test with all features enabled locally before committing changes to produce a clean history once the PR is merged rather than relying solely on the pipeline.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"eng/tools/xtask",
"sdk/typespec",
"sdk/typespec/typespec_client_core",
"sdk/core/azure_core",
Expand Down Expand Up @@ -49,6 +50,7 @@ async-stream = { version = "0.3.5" }
async-trait = "0.1"
base64 = "0.22"
bytes = "1.0"
cargo-util-schemas = "0.1.0"
clap = { version = "4.4.16", features = ["derive"] }
dyn-clone = "1.0"
fe2o3-amqp = { version = "0.12", features = ["native-tls", "tracing", "uuid"] }
Expand Down Expand Up @@ -89,6 +91,7 @@ tokio = { version = "1.0", default-features = false, features = [
"macros",
"time",
] }
toml = "0.8.10"
tracing = "0.1.40"
tracing-subscriber = "0.3"
tz-rs = { version = "0.6" }
Expand Down
14 changes: 14 additions & 0 deletions eng/dict/crates.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
async-lock
async-process
async-std
async-stream
async-trait
azure_core
azure_core_amqp
azure_identity
azure_storage_common
base64
bytes
cargo-util-schemas
clap
dyn-clone
fe2o3-amqp
fe2o3-amqp-cbs
fe2o3-amqp-ext
fe2o3-amqp-management
fe2o3-amqp-types
futures
getrandom
hmac
Expand All @@ -22,15 +31,20 @@ rand
reqwest
rustc_version
serde
serde_amqp
serde_bytes
serde_json
serde_test
serial_test
sha2
thiserror
time
tokio
toml
tracing
tracing-subscriber
typespec
typespec_client_core
tz-rs
url
uuid
20 changes: 20 additions & 0 deletions eng/tools/xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "xtask"
version = "0.1.0"
description = "Build tasks for Azure SDKs for Rust"
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage = "https://github.com/azure/azure-sdk-for-rust"
keywords = ["sdk", "azure", "rxtask"]
edition.workspace = true
rust-version.workspace = true
publish = false

[dependencies]
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
toml = "0.8.10"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
cargo-util-schemas = "0.1.0"
62 changes: 62 additions & 0 deletions eng/tools/xtask/src/check_editorconfig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use crate::find_file;
use serde::Deserialize;
use std::{env, fs, ops::Not, process::exit};

pub fn run(args: impl Iterator<Item = String>) {
// TODO: Find more than just the first .editorconfig in the ancestor directory tree.
let config_path = find_file(
env::current_dir().expect("current directory"),
".editorconfig",
)
.expect("expected .editorconfig");
let config_content = fs::read_to_string(config_path).expect("read .editorconfig");

// BUGBUG: A section named "*" and non-quoted strings are not supported.
let config: EditorConfig = toml::from_str(&config_content).expect("deserialize .editorconfig");

let mut missing_header = false;
for path in args.filter(filter) {
let content = fs::read_to_string(&path).unwrap_or_else(|_| panic!("read {}", &path));
if !content
.replace("\r\n", "\n")
.starts_with(&config.all.file_header_template)
{
println!("Missing copyright header from {}", &path);
missing_header = true;
}
}

if missing_header {
exit(1);
}
}

#[allow(clippy::ptr_arg)]
fn filter(value: &String) -> bool {
value.ends_with(".rs") && value.replace('\\', "/").contains("/generated/").not()
}

#[test]
fn test_filter() {
assert!(filter(&"dir/file.rs".to_string()));
assert!(filter(&"dir\\file.rs".to_string()));
assert!(!filter(&"dir/file.txt".to_string()));
assert!(filter(&"dir/generated_file.rs".to_string()));
assert!(filter(&"dir\\generated_file.rs".to_string()));
assert!(!filter(&"dir/generated/file.rs".to_string()));
assert!(!filter(&"dir\\generated\\file.rs".to_string()));
}

#[derive(Deserialize)]
struct EditorConfig {
// #[serde(rename = "*")]
pub all: Section,
}

#[derive(Debug, Deserialize)]
struct Section {
file_header_template: String,
}
55 changes: 55 additions & 0 deletions eng/tools/xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use std::{env, process::exit};

mod check_editorconfig;
#[cfg(not(target_arch = "wasm32"))]
mod update_cratenames;
#[cfg(not(target_arch = "wasm32"))]
mod verify_dependencies;

fn main() {
let mut args = env::args();
args.next().expect("expected executable");

let Some(command) = args.next() else {
eprintln!("Error: missing command.");
usage();

exit(1);
};

match command.as_str() {
"check-editorconfig" => check_editorconfig::run(args),
#[cfg(not(target_arch = "wasm32"))]
"update-cratenames" => update_cratenames::run(),
#[cfg(not(target_arch = "wasm32"))]
"verify-dependencies" => verify_dependencies::run(args),
"--help" | "-h" => usage(),
_ => {
eprintln!("Error: unknown command: {}", command);
usage();

exit(1);
}
}
}

fn usage() {
eprintln!("Usage: cargo xtask <command> [options]\n");
eprintln!("Commands:\n");
eprintln!(" check-editorconfig: Enforce (some) rules of .editorconfig");
eprintln!(" update-cratenames: Update eng/dict/crates.txt with names of crates used throughout the workspace.");
eprintln!(" verify-dependencies: Verify that all dependencies are centralized in the workspace Cargo.toml.");
}

fn find_file(dir: impl AsRef<std::path::Path>, name: &str) -> Option<String> {
for dir in dir.as_ref().ancestors() {
let path = dir.join(name);
if path.exists() {
return Some(path.to_str().unwrap().into());
}
}
None
}
15 changes: 4 additions & 11 deletions eng/scripts/update-cratenames.rs → eng/tools/xtask/src/update_cratenames.rs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#!/usr/bin/env -S cargo +nightly -Zscript
---
[package]
edition = "2021"

[dependencies]
cargo-util-schemas = "0.1.0"
toml = "0.8.10"
---
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use cargo_util_schemas::manifest::TomlManifest;
use std::{fs, path::PathBuf};

fn main() {
pub fn run() {
let workspace_root = get_workspace_root();
let workspace_manifest_path = workspace_root.join("Cargo.toml");
eprintln!("Reading {workspace_manifest_path:?}");
Expand All @@ -26,7 +19,7 @@ fn main() {
.expect("expected workspace")
.dependencies
.expect("expected workspace dependencies");
let crate_names: Vec<&str> = dependencies.iter().map(|(name, _)| name.as_str()).collect();
let crate_names: Vec<&str> = dependencies.keys().map(|name| name.as_str()).collect();

let crate_names_path = workspace_root
.join("eng/dict/crates.txt")
Expand Down
Loading
Loading