project-mahiwa / mahiwa-frontend-rust

mahiwaのRust向けフロントエンド
https://docs.rs/mahiwa_frontend_rust/latest/mahiwa_frontend_rust/
MIT License
0 stars 0 forks source link

[🛠️Refactor]:ビルド時のスタックサイズなどのパラメータを見直す #16

Open usuyuki opened 10 months ago

usuyuki commented 10 months ago

🛠️ 概要

言語側,マイコン側がそれぞれ作用していて,適切な値を決めるのが難しい. (一応触るのはユーザー側なので,ユーザーにおまかせという形はあるが,どのくらいまで問題ないのか,どのくらいないと止まるのかの大雑把な把握だけでもして起きたい)

なぜ必要

備考

usuyuki commented 10 months ago

.cargo/configの説明 https://doc.rust-lang.org/cargo/reference/config.html

.cargo/config [build]のrustflagsの説明 https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags

→rustflagsはrustcに渡すflagsになる

usuyuki commented 10 months ago
rustflags = [
  "-C", "link-args=-zstack-size=2048 -s",
]

の-Cはコード生成オプションの指定のために必要. -C link-argsのようにすることで,より細かい指定をコンパイラにさせることができるらしい.

cargo buildをしているが,rustcも内部で使うので,そのためのオプション

usuyuki commented 10 months ago

rustc -C help

target=の指定をしても結果は変わらない

❯ rustc -C help

Available codegen options:

    -C                       ar=val -- this option is deprecated and does nothing
    -C               code-model=val -- choose the code model to use (`rustc --print code-models` for details)
    -C            codegen-units=val -- divide crate into N units to optimize in parallel
    -C       control-flow-guard=val -- use Windows Control Flow Guard (default: no)
    -C         debug-assertions=val -- explicitly enable the `cfg(debug_assertions)` directive
    -C                debuginfo=val -- debug info emission level (0-2, none, line-directives-only, line-tables-only, limited, or full; default: 0)
    -C default-linker-libraries=val -- allow the linker to link its default libraries (default: no)
    -C                  dlltool=val -- import library generation tool (ignored except when targeting windows-gnu)
    -C            embed-bitcode=val -- emit bitcode in rlibs (default: yes)
    -C           extra-filename=val -- extra data to put in each output filename
    -C     force-frame-pointers=val -- force use of the frame pointers
    -C      force-unwind-tables=val -- force use of unwind tables
    -C              incremental=val -- enable incremental compilation
    -C         inline-threshold=val -- set the threshold for inlining a function
    -C      instrument-coverage=val -- instrument the generated code to support LLVM source-based code coverage reports (note, the compiler build config must include `profiler = true`); implies `-C symbol-mangling-version=v0`. Optional values are:
        `=all` (implicit value)
        `=except-unused-generics`
        `=except-unused-functions`
        `=off` (default)
    -C                 link-arg=val -- a single extra argument to append to the linker invocation (can be used several times)
    -C                link-args=val -- extra arguments to append to the linker invocation (space separated)
    -C           link-dead-code=val -- keep dead code at link time (useful for code coverage) (default: no)
    -C      link-self-contained=val -- control whether to link Rust provided C objects/libraries or rely
        on a C toolchain or linker installed in the system
    -C                   linker=val -- system linker to link outputs with
    -C            linker-flavor=val -- linker flavor
    -C        linker-plugin-lto=val -- generate build artifacts that are compatible with linker-based LTO
    -C                llvm-args=val -- a list of arguments to pass to LLVM (space separated)
    -C                      lto=val -- perform LLVM link-time optimizations
    -C                 metadata=val -- metadata to mangle symbol names with
    -C    no-prepopulate-passes=val -- give an empty list of passes to the pass manager
    -C               no-redzone=val -- disable the use of the redzone
    -C           no-stack-check=val -- this option is deprecated and does nothing
    -C       no-vectorize-loops=val -- disable loop vectorization optimization passes
    -C         no-vectorize-slp=val -- disable LLVM's SLP vectorization pass
    -C                opt-level=val -- optimization level (0-3, s, or z; default: 0)
    -C          overflow-checks=val -- use overflow checks for integer arithmetic
    -C                    panic=val -- panic strategy to compile crate with
    -C                   passes=val -- a list of extra LLVM passes to run (space separated)
    -C           prefer-dynamic=val -- prefer dynamic linking to static linking (default: no)
    -C         profile-generate=val -- compile the program with profiling instrumentation
    -C              profile-use=val -- use the given `.profdata` file for profile-guided optimization
    -C         relocation-model=val -- control generation of position-independent code (PIC) (`rustc --print relocation-models` for details)
    -C                   remark=val -- output remarks for these optimization passes (space separated, or "all")
    -C                    rpath=val -- set rpath values in libs/exes (default: no)
    -C               save-temps=val -- save all temporary output files during compilation (default: no)
    -C               soft-float=val -- use soft float ABI (*eabihf targets only) (default: no)
    -C          split-debuginfo=val -- how to handle split-debuginfo, a platform-specific option
    -C                    strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)
    -C  symbol-mangling-version=val -- which mangling version to use for symbol names ('legacy' (default) or 'v0')
    -C               target-cpu=val -- select target processor (`rustc --print target-cpus` for details)
    -C           target-feature=val -- target specific attributes. (`rustc --print target-features` for details). This feature is unsafe.
usuyuki commented 10 months ago
❯ rustc -C help | rg link-args
    -C                link-args=val -- extra arguments to append to the linker invocation (space separated)

らしく,link-args=でさらに指定ができる模様. link-argsでリンカの変更もできるっぽい.

linkerに渡す引数なので,おそらくwasm-ld? goのldflagsと同等?

usuyuki commented 10 months ago

link-argsの引数情報は公式ドキュメントにないし(リンカ次第なので,ターゲットによって違うはず),link-argsのhelpも出せないので,おそらくgoのldflagsと同等であると解釈して進める. (wasm-ldを使っている可能性が極めて高いため)

usuyuki commented 10 months ago

https://github.com/project-mahiwa/mahiwa-frontend-go/issues/29#issuecomment-1857407028