-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve the interface #3
Comments
私が知っていることを書いておきます。 まず依存グラフおよび依存先のパッケージの情報は ❯ cargo metadata --format-version 1 | jq '.resolve.root as $r | .resolve.nodes[] | select(.id == $r) | .deps[0]'
{
"name": "anyhow",
"pkg": "anyhow 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"dep_kinds": [
{
"kind": null,
"target": null
}
]
}
少なくとも依存先の方はクレート全体が十分に小さいと考えて、無条件でroot moduleに依存するとみなすという手があると思います。 また展開方法ですが、cargo-equipではこのように +// このような"pseudo extern prelude"を挿入。
+mod __pseudo_extern_prelude {
+ // `extern_crate_name`を翻訳
+ pub(super) use crate::{another_lib1, another_lib2};
+}
+use self::__pseudo_extern_prelude::*;
+
use another_lib1::A;
use another_lib2::B; ただこれはRust 2015ではコンパイルできない(継ぎ木が無理)ので、ライブラリを2015-compatibleにしたい場合ユーザーがマーカーとして mod extern_crates {
- pub(super) extern crate __another_lib as another_lib;
+ pub(super) use crate::another_lib;
}
use self::extern_crates::another_lib::foo::Foo; // Prepend `self::` to make compatible with Rust 2015 ただバージョンが1.31+なのにエディションが2015なサイトに片っぱしから要望を出す方が早いかもしれません。私はこの前Library-CheckerにPRを出し、yukicoderにも昨日要望を出しました。
❯ cargo metadata --format-version 1 | jq '.packages[] | select(.name == "anyhow") | .manifest_path'
"/home/ryo/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.33/Cargo.toml" ソースコードを編集したやつを保存したいとなればどこかに
関係あるかわかりませんがAtCoderで使えるクレートについては私はハードコードしてしまいました。ただpermutohedronとか今のままでも普通に展開できそうなんですよね... |
ありがとうございます.助かります. とりあえずの要求として考えていたのは
だったので,(すべての依存先を展開するのではなく) ユーザーが明示的に (依存先のうち) どのクレートを展開するか選択するようにしようというつもりでした.なんですが,これだとクレートを細かく分割するスタイルのライブラリに対応しようとなった場合には困ったことになりますね…
これは知りませんでした.これなら簡単ですね. |
cargo-equip(と今online-judge-tools/verification-helperに出している途中のpr)では私がcollaboratorをやっているcargo-udepsを使って「深さ1」のクレートを絞り込んでます。 なんですが {
"success": false,
"unused_deps": {
"solve 0.0.0 (path+file:///home/ryo/src/local/play-cargo-equip/solve)": {
"manifest_path": "/home/ryo/src/local/play-cargo-equip/solve/Cargo.toml",
"normal": [
"ac-library-rs-parted",
"ac-library-rs-parted-convolution",
"ac-library-rs-parted-dsu",
"ac-library-rs-parted-fenwicktree",
"ac-library-rs-parted-lazysegtree",
"ac-library-rs-parted-math",
"ac-library-rs-parted-maxflow",
"ac-library-rs-parted-mincostflow",
"ac-library-rs-parted-scc",
"ac-library-rs-parted-segtree",
"ac-library-rs-parted-string",
"ac-library-rs-parted-twosat",
"im-rc",
"permutohedron"
],
"development": [],
"build": []
}
},
"note": "Note: These dependencies might be used by other targets.\n To find dependencies that are not used by any target, enable `--all-targets`.\nNote: They might be false-positive.\n For example, `cargo-udeps` cannot detect usage of crates that are only used in doc-tests.\n To ignore some dependencies, write `package.metadata.cargo-udeps.ignore` in Cargo.toml.\n"
} JSON自体も必要最低限の情報しか詰めてないのでちょっと面倒かも。注意点としてはこのあたり?
あとパッケージ/クレートの「名前」については、このように解決されると私は理解しています。Cargoに詳しいわけではないので誤っているかもしれませんが。
|
あと一応これについてですが、明示的に --exclude <SPEC>... Exclude library crates from bundling
--exclude-atcoder-crates Alias for `--exclude https://github.com/rust-lang/crates.io-index#alga:0.9.3 ..`
--exclude-codingame-crates Alias for `--exclude https://github.com/rust-lang/crates.io-index#chrono:0.4.9 ..` 破壊的変更なのでエラーメッセージも追加した上で。 note: attempted to bundle with the following crate(s), which are available on AtCoder. to exclude them from bundling, run with `--exclude-atcoder-crates`
- `im-rc 14.3.0 (registry+https://github.com/rust-lang/crates.io-index)`
- `rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)` 「CLIオプションで指定するパッケージ」を扱うとしたら |
今までは「ライブラリクレートに対して実行し,必要なコードを抜粋する」コマンドだったのを,「(ライブラリに依存する) バイナリクレートに対して実行し,提出可能なコードを生成する」コマンドにしたい.
Before:
After:
cargo simple-bundler --crates one,two >bundled.rs
path
(やgit
) のみ対応 /cargo-clone
などを使うThe text was updated successfully, but these errors were encountered: