-
Notifications
You must be signed in to change notification settings - Fork 21
ci: add xtask for build and better test #469
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - 我发现了 1 个问题,并给出了一些高层次的反馈:
workspace_root的实现通过对CARGO_MANIFEST_DIR使用硬编码长度的切片来获取工作空间根目录,这种方式比较脆弱;建议使用Path::new(CARGO_MANIFEST_DIR).parent()来推导工作空间根目录,从而避免对目录名做出假设。- 在
xtask/build.rs中,std::env::var("TARGET").unwrap()会在TARGET未设置时触发 panic;使用带有更清晰错误信息的expect或者提供一个回退值,会让故障更容易诊断。 - 在
xtask/src/build.rs中构造target_dir和binary路径时,建议使用PathBuf和.join()而不是字符串拼接,以避免在不同平台上出现一些微妙的路径问题。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- `workspace_root` 的实现通过对 `CARGO_MANIFEST_DIR` 使用硬编码长度的切片来获取工作空间根目录,这种方式比较脆弱;建议使用 `Path::new(CARGO_MANIFEST_DIR).parent()` 来推导工作空间根目录,从而避免对目录名做出假设。
- 在 `xtask/build.rs` 中,`std::env::var("TARGET").unwrap()` 会在 `TARGET` 未设置时触发 panic;使用带有更清晰错误信息的 `expect` 或者提供一个回退值,会让故障更容易诊断。
- 在 `xtask/src/build.rs` 中构造 `target_dir` 和 `binary` 路径时,建议使用 `PathBuf` 和 `.join()` 而不是字符串拼接,以避免在不同平台上出现一些微妙的路径问题。
## Individual Comments
### Comment 1
<location> `xtask/src/main.rs:14-15` </location>
<code_context>
+const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
+const HOST_TRIPLET: &str = env!("TARGET");
+
+fn workspace_root() -> &'static str {
+ &CARGO_MANIFEST_DIR[..CARGO_MANIFEST_DIR.len() - 6]
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 避免通过硬编码的 `[..len-6]` 切片来推导工作空间根目录。
这种做法依赖目录名严格为 `/xtask`(包括分隔符在内共 6 个字节),因此一旦 crate 被重命名或移动就会出错。更好的方式是使用路径相关的 API,例如通过 `Path::new(CARGO_MANIFEST_DIR).parent().unwrap()`(如果需要的话可以再调用一次 `.parent()`)来以一种与布局和平台无关的方式推导工作空间根目录。
建议的实现:
```rust
mod build;
mod cmd;
mod env;
mod github;
mod release;
mod test;
use std::path::Path;
const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
const HOST_TRIPLET: &str = env!("TARGET");
```
```rust
fn workspace_root() -> &'static str {
Path::new(CARGO_MANIFEST_DIR)
.parent()
.expect("CARGO_MANIFEST_DIR should have a parent directory")
.to_str()
.expect("workspace root path should be valid UTF-8")
}
```
如果 `workspace_root()` 在多个地方被调用时依赖于结尾的斜杠或某个特定子目录,请检查这些调用点,确保在采用更通用、基于路径的实现之后,它们仍然能按预期工作。另外,如果该文件当前存在 `mod` / `const` 重复声明(如示例所示),你可能还希望将其去重以保持整洁,不过这不是本次修改能够正常工作的必需条件。
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The
workspace_rootimplementation relies on slicingCARGO_MANIFEST_DIRby a hardcoded length, which is brittle; consider deriving the workspace root usingPath::new(CARGO_MANIFEST_DIR).parent()to avoid assumptions about the directory name. - In
xtask/build.rs,std::env::var("TARGET").unwrap()will panic ifTARGETis not set; usingexpectwith a clearer message or a fallback would make failures easier to diagnose. - When constructing
target_dirandbinarypaths inxtask/src/build.rs, consider usingPathBufand.join()instead of string concatenation to avoid subtle path issues across platforms.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `workspace_root` implementation relies on slicing `CARGO_MANIFEST_DIR` by a hardcoded length, which is brittle; consider deriving the workspace root using `Path::new(CARGO_MANIFEST_DIR).parent()` to avoid assumptions about the directory name.
- In `xtask/build.rs`, `std::env::var("TARGET").unwrap()` will panic if `TARGET` is not set; using `expect` with a clearer message or a fallback would make failures easier to diagnose.
- When constructing `target_dir` and `binary` paths in `xtask/src/build.rs`, consider using `PathBuf` and `.join()` instead of string concatenation to avoid subtle path issues across platforms.
## Individual Comments
### Comment 1
<location> `xtask/src/main.rs:14-15` </location>
<code_context>
+const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
+const HOST_TRIPLET: &str = env!("TARGET");
+
+fn workspace_root() -> &'static str {
+ &CARGO_MANIFEST_DIR[..CARGO_MANIFEST_DIR.len() - 6]
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Avoid hard-coding the `[..len-6]` slice for deriving the workspace root.
This relies on the directory being exactly `/xtask` (6 bytes including the separator), so it will break if the crate is renamed or moved. Prefer using path APIs, e.g. `Path::new(CARGO_MANIFEST_DIR).parent().unwrap()` (and `.parent()` again if needed) to derive the workspace root in a layout- and platform-agnostic way.
Suggested implementation:
```rust
mod build;
mod cmd;
mod env;
mod github;
mod release;
mod test;
use std::path::Path;
const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
const HOST_TRIPLET: &str = env!("TARGET");
```
```rust
fn workspace_root() -> &'static str {
Path::new(CARGO_MANIFEST_DIR)
.parent()
.expect("CARGO_MANIFEST_DIR should have a parent directory")
.to_str()
.expect("workspace root path should be valid UTF-8")
}
```
If `workspace_root()` is used in multiple places assuming a trailing slash or specific subdirectory, review those call sites to ensure they still behave correctly with the more general, path-based implementation. Also, if this file currently has duplicated `mod` / `const` declarations (as in the snippet), you may want to deduplicate them for cleanliness, though that is not required for this change to work.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #469 +/- ##
===========================================
+ Coverage 59.06% 69.34% +10.28%
===========================================
Files 56 56
Lines 5560 5598 +38
Branches 5560 5598 +38
===========================================
+ Hits 3284 3882 +598
+ Misses 2018 1425 -593
- Partials 258 291 +33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Replace `--with-core` with `--install-core` and add `--no-core-tests` flag - Remove redundant `MAA_EXTRA_SHARE_NAME` environment variable - Simplify test command arguments in CI workflows - Update `config init` to accept `&Path` instead of `PathBuf` - Add debug logging to xtask command execution
Summary by Sourcery
为 maa-cli 引入基于 xtask 的构建命令,并将其接入发布工作流,以统一构建和打包流程。
新功能:
build子命令,用于构建带可选 vendored 依赖和 tar 打包的 maa-cli 可执行文件。增强改进:
xtask::build模块中,由 CI 复用。CI:
cargo x build来构建和打包制品,并从 xtask 的输出中推导制品名称。Original summary in English
Summary by Sourcery
Introduce an xtask-based build command for maa-cli and wire it into the release workflow to standardize building and packaging.
New Features:
buildsubcommand to build the maa-cli binary with optional vendored dependencies and tar packaging.Enhancements:
xtask::buildmodule reused by CI.CI:
cargo x buildfor building and packaging artifacts, and derive artifact names from xtask outputs.