Upgrade to Pro — share decks privately, control downloads, hide ads and more …

fukuoka.rs #7 LT

Shuji N
October 22, 2020

fukuoka.rs #7 LT

コマンドオプションの処理について

Shuji N

October 22, 2020
Tweet

More Decks by Shuji N

Other Decks in Programming

Transcript

  1. 2020 - 10 - 22 github @shnarazk ࣗݾ঺հ ڈ೥·Ͱେֶڭһɿ޷͖ͳ͜ͱΛ޷͖ͳݴޠʢHaskell, 2೥લ͔ΒRustʣͰ

    ݱࡏ͸ • ϓϩάϥϜΛॻ͘࢓ࣄʢJavaScript, TypeScriptʣ • ϓϩάϥϛϯάΛڭ͑Δ࢓ࣄʢScratch, Swift …ʣ Մॲ෼࣌ؒɿ޷͖ͳ͜ͱΛ޷͖ͳݴޠʢRustʣͰ 2
  2. 2020 - 10 - 22 getopt(bash, gnu), argparse(python)... ίϚϯυΦϓγϣϯ $

    cargo --help Rust's package manager USAGE: cargo [+toolchain] [OPTIONS] [SUBCOMMAND] OPTIONS: -V, --version Print version info and exit --list List installed commands --explain <CODE> Run `rustc --explain CODE` -v, --verbose Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color <WHEN> Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date 3
  3. 2020 - 10 - 22 σϑΝΫτελϯμʔυʁ, ϏϧμʔͰ૊ΈཱͯɺYAML, DSLͳͲ clap 2.

    let conf = App::new(“program name”)ɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹ .arg(Arg::with_name(“stp") ɹɹɹɹɹ .short(“s” ) .long(“step” ) .default_value(“50” ) .help(“#conflicts between restarts”) ) .arg(...) .. . let matches = conf.get_matches();ɹɹɹɹɹɹɹɹɹɹɹɹɹɹ let stp = matches.value_of(“stp”).parse::<usize>().unwrap(); 4 OPTIONS : -s, —step <stp> #conflicts between restarts [default: 50]
  4. 2020 - 10 - 22 clapͷ֦ுɿ೿ੜߏ଄ମͷϑΟʔϧυଐੑͱͯ͠એݴ, proc-macroʹ৽ͨʹґଘ structopt 0.3 #[derive(Clone,

    Debug, StructOpt)] struct Config { /// #conflicts between restarts #[structopt(short = [‘s’], long = "step", default_value = "50")] pub stp: usize, ... 5 ੜ੒͞ΕΔϔϧϓςΩετɿ -s, --step <stp> #conflicts between restarts [default: 50] let config: Config = Config.from_args();ɹɹɹɹ// default͸ແࢹ͞ΕΔ
  5. 2020 - 10 - 22 structopt͕clapʹͦͷ··औΓࠐ·ΕΔ clap 3. ݱࡏ beta

    2 ଐੑ໊ɺϝιου໊͕एׯมߋ •#[structopt(...)] -> #[clap(...) ] •Arg::with_name(…) -> Arg::new(…) 6
  6. 2020 - 10 - 22 RustͰॻ͔Εͨ SAT solverʢͱʹ͔͘ߴ଎Ͱ͋Δ͜ͱ͕ٻΊΒΕΔʣ Splr •

    LOCɿ 8600 - α ߦఔ౓ • ࣮ߦϑΝΠϧαΠζɿ΄΅1000 K B • Φϓγϣϯ਺ɿ41ݸ • ґଘΫϨʔτ • ɹbitflag s • ɹstructopt 7
  7. 2020 - 10 - 22 2019͔Β2020ͷҰԡ͠SATιϧόʔCaDiCaL ଞݴޠͱͷൺֱ 8 ϓϩάϥϜ ݴޠ

    LOC Φϓγϣϯ਺ ࣮ߦϑΝΠϧαΠζ CaDiCaL C++ 23,000 - α ߦ 187 ݸ 680,800 Byte Splr Rust 8,600 - α ߦ 41 ݸ 1,024,648 Byte τʔλϧ1000KBͷϓϩάϥϜͰ300KBେ͖͍ ※ ॲཧ͸ࣗલ
  8. 2020 - 10 - 22 Φϓγϣϯղੳ෦Λॻ͖௚͠ɺ࣮ߦϑΝΠϧͷαΠζΛൺֱ ൺֱ࣮ݧ •structop t •clap

    2. 0 •clap 3.0 beta 2 (builder, derive ) •खॻ͖: while let Some(arg) = args.next() { … } 300ߦఔ౓ 9
  9. 2020 - 10 - 22 ※ clap͸࠷௿ݶͷॲཧͷΈ; -opt-level=3, LTO=fat, codegen-units=1,

    panic=“abort”, Darwin ݁Ռ ํ๏ ࣮ߦαΠζ Byte stripped ArchLinux stripped structopt 0.3.20 1,024,648 826,064 890,968 clap 2.33.3 (builder) 970,504 776,808 841,816 clap 3.0 β2 builder 943,184 792,848 833,624 clap 3.0 β2 derive 1,014,304 858,504 890,968 खॻ͖ͰΠςϨʔτ 593,656 481,024 510,040 ࠶ܝ: CaDiCaL 680,800 619,208 627,304 10
  10. 2020 - 10 - 22 ݁࿦ • 1ສߦఔ౓ͷϓϩάϥϜͷ࣮ߦϑΝΠϧʹରͯ͠structopt͸ҙ֎ʹ݁ߏͳ෼ྔ • clapʹม͑ͯ΋େ͖ͳมԽ͸ͳ͍

    elf segmentͰ.text͕໿1.4ഒʀargpars.py΋2000ߦ͋ΔͷͰ͜Μͳ΋ͷʁ • ॏཁɿ Sub-Commands, Validation, Auto-generated completion scripts, etc . • ঢ়گʹΑͬͯ͸ݕ౼ͯ͠Έͯ΋͍͍͔΋ 11 $ cargo tree splr v0.5.1-dev.1 └── bitflags v1.2.1
  11. 2020 - 10 - 22 https://github.com/rust-cli/climake climake 2.2.2 [ UsedArg

    { argument: Argument { calls: [ Short('a'), ], help: Some(...), datatype: Text, }, passed_data: Text( [ “foo", ], ), },... • Rust CLI WG: The @rustlang commandline application working grou p • About: The simple, dependency-less cli library ✨ ࠷৽όʔδϣϯ2.2͸·ͱ΋ʹಈ͘ ඇৗʹ؆ૉ 12 let args: &[Argument] = & [ Argument::new(&['a'], &[], Some("option a"), DataType::Text).unwrap() , Argument::new(&['b'], &[], Some("option b"), DataType::Text).unwrap() , ];
  12. 2020 - 10 - 22 13 └── structopt v0.3.20 ├──

    clap v2.33.3 ├── lazy_static v1.4.0 └── structopt-derive v0.4.13 ├── heck v0.3.1 │ └── unicode-segmentation v1.6.0 ├── proc-macro-error v1.0.4 │ ├── proc-macro-error-attr v1.0.4 │ │ ├── proc-macro2 v1.0.24 │ │ │ └── unicode-xid v0.2.1 │ │ └── quote v1.0.7 │ │ └── proc-macro2 v1.0.24 (*) │ ├── proc-macro2 v1.0.24 (*) │ ├── quote v1.0.7 (*) │ └── syn v1.0.45 │ ├── proc-macro2 v1.0.24 (*) │ ├── quote v1.0.7 (*) │ └── unicode-xid v0.2.1 ├── proc-macro2 v1.0.24 (*) ├── quote v1.0.7 (*) └── syn v1.0.45 (*) ├── clap v2.33.3 │ ├── ansi_term v0.11.0 │ ├── atty v0.2.14 │ │ └── libc v0.2.76 │ ├── bitflags v1.2.1 │ ├── strsim v0.8.0 │ ├── textwrap v0.11.0 │ │ └── unicode-width v0.1.8 │ ├── unicode-width v0.1.8 │ └── vec_map v0.8.2
  13. 2020 - 10 - 22 14 └── structopt v0.3.20 ├──

    clap v2.33.3 │ ├── ansi_term v0.11.0 │ ├── atty v0.2.14 │ │ └── libc v0.2.79 │ ├── bitflags v1.2.1 │ ├── strsim v0.8.0 │ ├── textwrap v0.11.0 │ │ └── unicode-width v0.1.8 │ ├── unicode-width v0.1.8 │ └── vec_map v0.8.2 ├── lazy_static v1.4.0 └── structopt-derive v0.4.13 ├── heck v0.3.1 │ └── unicode-segmentation v1.6.0 ├── proc-macro-error v1.0.4 │ ├── proc-macro-error-attr v1.0.4 │ │ ├── proc-macro2 v1.0.24 │ │ │ └── unicode-xid v0.2.1 │ │ └── quote v1.0.7 │ │ └── proc-macro2 v1.0.24 (*) │ ├── proc-macro2 v1.0.24 (*) │ ├── quote v1.0.7 (*) │ └── syn v1.0.45 │ ├── proc-macro2 v1.0.24 (*) │ ├── quote v1.0.7 (*) │ └── unicode-xid v0.2.1 ├── proc-macro2 v1.0.24 (*) ├── quote v1.0.7 (*) └── syn v1.0.45 (*) └── clap v3.0.0-beta.2 ├── atty v0.2.14 │ └── libc v0.2.79 ├── bitflags v1.2.1 ├── clap_derive v3.0.0-beta.2 │ ├── heck v0.3.1 │ │ └── unicode-segmentation v1.6.0 │ ├── proc-macro-error v1.0.4 │ │ ├── proc-macro-error-attr v1.0.4 │ │ │ ├── proc-macro2 v1.0.24 │ │ │ │ └── unicode-xid v0.2.1 │ │ │ └── quote v1.0.7 │ │ │ └── proc-macro2 v1.0.24 (*) │ │ ├── proc-macro2 v1.0.24 (*) │ │ ├── quote v1.0.7 (*) │ │ └── syn v1.0.45 │ │ ├── proc-macro2 v1.0.24 (*) │ │ ├── quote v1.0.7 (*) │ │ └── unicode-xid v0.2.1 │ ├── proc-macro2 v1.0.24 (*) │ ├── quote v1.0.7 (*) │ └── syn v1.0.45 (*) ├── indexmap v1.6.0 │ └── hashbrown v0.9.1 ├── lazy_static v1.4.0 ├── os_str_bytes v2.3.2 ├── strsim v0.10.0 ├── termcolor v1.1.0 ├── textwrap v0.12.1 │ └── unicode-width v0.1.8 ├── unicode-width v0.1.8 └── vec_map v0.8.2