Rust Install and Setup

INSTALL install - ์„ค์น˜ ํ›„ ~/.bashrc์— ~/.cargo ์ž๋™ ํ™˜๊ฒฝ ์„ค์ • $ curl https://sh.rustup.rs -sSf | sh -- --help rustup ์—…๋ฐ์ดํŠธ/ ์ œ๊ฑฐ $ rustup update $ rustup self uninstall rustc ์ปดํŒŒ์ผ๋Ÿฌ ๋ฒ„์ „ํ™•์ธ $ rustc --version Hello World $ vim hello_world.rs fn main() { #println!๋Š” ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ๋งคํฌ๋กœ println!("Hello, world!"); } $ rustc hello_world.rs Cargo๋ฅผ ํ†ตํ•œ ๊ฐœ๋ฐœ $ cargo new hello_cargo --bin $ cd hello_cargo $ vim src/main.rs fn main() { println!("Hello, world!"); } ./target/debug/hello_cargo ๋กœ ๋ฐ”์ด๋„ˆ๋ฆฌ ์ƒ์„ฑ $ cargo run # compile and run $ cargo run # run only: source is not changed $ cargo check # compile only no exe file create (rapid compile and test) $ cargo clean # cleanup all object and binary files $ cargo run -- --help #์‹คํ–‰ํŒŒ์ผ ์ธ์ž๋ฅผ ๋ฐ›์•„์„œ ์‹คํ–‰ํ•  ๋•Œ $ cargo build $ cargo build --release (optimize for release) ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ $ cargo add ansi_term #์ž๋™์œผ๋กœ Cargo.toml์— ๋ชจ๋“ˆ์ด๋ฆ„๊ณผ ๋ฒ„์ „์ด ๋“ฑ๋ก๋œ๋‹ค. $ vim src/main.rs #use ansi_term::xxxx ์„ ๋„ฃ๊ณ  ์ฝ”๋”ฉ $ cargo run Build From Git $ git clone someurl.com/someproject $ cd someproject $ cargo build reference ์ œ์ผ ๊ถ๊ธˆํ•œ ๊ฒƒ์€ ์ „์ฒด์ ์ธ ๊ฐœ๋ฐœ ๋ฐ ๋ฐฐํฌ ๊ณผ์ •์ธ๋ฐ ์•„๋ž˜๊ฐ€ ์•„์ฃผ ์ข‹์Œ https://free-strings.blogspot.com/2017/03/cargo-cargo.html https://rust-cli.github.io/book/tutorial/packaging.html ์•„์ฃผ ํ›Œ๋ฅญํ•œ ์ฟก๋ถ์ด๋‹ค. ๋จผ์ € ๊ธฐ๋ณธ ์˜จ๋ผ์ธ๋ถ์„ ๋ณด๊ณ ์„œ ์ด๊ฒƒ์„ ๊ณต๋ถ€ํ•˜์ž. https://rust-lang-nursery.github.io/rust-cookbook/

2022-08-31 ยท 197 words

Rust Compile์‹œ ์šฉ๋Ÿ‰ ์ค„์ด๊ธฐ

Intro debug > release ์ˆœ์œผ๋กœ ์—„์ฒญ๋‚œ ๋ฐ”์ด๋„ˆ๋ฆฌ ์‚ฌ์ด์ฆˆ๋ฅผ ์ž๋ž‘ํ•œ๋‹ค. ์šฐ์„  ๊ฐœ๋ฐœ๊ณผ ๋””๋ฒ„๊น…์„ ๋ณ‘ํ–‰ํ•œ ํ›„์— ์ตœ์ข… ๋ฆด๋ฆฌ์ฆˆ์‹œ์— ์ ์šฉํ•œ๋‹ค. ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. Howto Cargo.toml์— ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•œ๋‹ค. [profile.release] lto = true codegen-units = 1 opt-level = "z" panic = 'abort' build cargo build --release reference https://www.collabora.com/news-and-blog/blog/2020/04/28/reducing-size-rust-gstreamer-plugin/ https://github.com/johnthagen/min-sized-rust

2022-08-31 ยท 44 words

LuaJit - Lua Just in Time Compiler

last updated: {{ โ€œ1736305941โ€ | date: โ€œ%Y-%m-%d %H:%Mโ€ }} Intro ํ•จ์ˆ˜๋“ค์ด ์ฒ˜์Œ ์‹คํ–‰ ๋  ๋•Œ ํ•„์š”์— ์˜ํ•ด ์ปดํŒŒ์ผ๋œ๋‹ค. ์ด๊ฒƒ์€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋น ๋ฅด๊ฒŒ ์‹œ์ž‘๋˜๋Š” ๊ฒƒ๊ณผ ๋ถˆํ•„์š”ํ•œ ์ž‘์—…์„ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š๋Š” ๊ฒƒ์„ ๋ณด์žฅํ•ด ์ค€๋‹ค. LuaJit์€ neovim์— ๊ธฐ๋ณธ ํƒ‘์žฌ๋˜์–ด ์žˆ๋‹ค. python, ruby ๋“ฑ์˜ Jit๋ณด๋‹ค ์šฐ์ˆ˜ํ•œ ์„ฑ๋Šฅ์„ ๋ณด์—ฌ์ค€๋‹ค. LuaJit์˜ FFI(Foreign Function Interface)๋Š” Low-Level C์–ธ์–ด ํ•จ์ˆ˜๋“ค์„ ๋ณ„๋‹ค๋ฅธ ์ž‘์—… ์—†์ด ์ง์ ‘์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋„ค์ดํ‹ฐ๋ธŒ์— ๊ฒฌ์ค„๋งŒํผ ์†๋„๊ฐ€ ๋น ๋ฅด๊ณ , ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์ด ๋งค์šฐ ์ ๋‹ค. nginx์— LuaJIT์„ ํฌํ•จ์‹œ์ผœ์„œ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•์„ ํ•œ OpenResty ์›น ์„œ๋ฒ„๋„ ์žˆ๋‹ค. ...

2022-08-30 ยท 446 words

Luarocks - lua ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ

INTRO lua์˜ ํ™•์žฅ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค. INSTALL and SETUP Install System-Wide : /usr/local/ $ sudo apt install luarocks # luarocks ์„ค์น˜ $ sudo luarocks install stdlib # ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ $ sudo chmod a+r /usr/local/share/lua/5.1/* # ์ผ๋ฐ˜์‚ฌ์šฉ์ž ์ฝ๊ธฐ ๊ถŒํ•œ ๋ถ€์—ฌ $ sudo luarocks install package_name # ํŒจํ‚ค์ง€ ์„ค์น˜ Install User Base : $HOME/.luarocks $ sudo apt install luarocks # luarocks ์„ค์น˜ $ echo 'PATH=$PATH:$HOME/.luarocks/bin' >> ~/.bashrc # add luarock bin path $ echo 'eval "$(luarocks path --bin)"' >> ~/.bashrc # add LUA_PATH, LUA_CPATH $ . ~/.bashrc $ luarocks install --local package_name # ํŒจํ‚ค์ง€ ์„ค์น˜ (--local) Rcoktree Structure: ๊ธฐ๋ณธ ์„ค์น˜ ๊ตฌ์กฐ {base} (base rocks tree directory) โ”œโ”€โ”€ bin (deployment of command line scripts) โ”œโ”€โ”€ lib โ”‚ โ”œโ”€โ”€ luarocks โ”‚ โ”‚ โ””โ”€โ”€ rocks (contains manifest and sub-dirs with rocks) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ lua โ”‚ โ””โ”€โ”€ 5.1 (deployment of binary modules) โ”‚ โ””โ”€โ”€ share โ””โ”€โ”€ lua โ””โ”€โ”€ 5.1 (deployment of Lua modules) Usage $ luarocks # show help and usage $ luarocks list # show installed packages $ luarocks search pack_name # search packages $ luarocks install pack_name # remove installed packages $ luarocks show pack_name # show info installed packages $ luarocks remove pack_name # remove installed packages ํŒจํ‚ค์ง€ ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ๋ก€ ํŒจํ‚ค์ง€๋Š” http://luarocks.org ์ฐธ์กฐ - ๊ฐ ๋ชจ๋“ˆ ๋‹ค์šด๋กœ๋“œ ์ˆœ์œ„๋„ ์ฐธ๊ณ  ...

2022-08-30 ยท 309 words

Luastatic - lua ๋…๋ฆฝ์‹คํ–‰ ๋ฐ”์ด๋„ˆ๋ฆฌ ์ปดํŒŒ์ผ๋Ÿฌ

Intro lua ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‹จ๋… ์‹คํ–‰ ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ (gcc๋กœ ์ปดํŒŒ์ผ) ์ฝ”๋“œ๋ฅผ ์ˆจ๊ธฐ๊ณ  ๋น ๋ฅธ ๋‹จ๋… ์‹คํ–‰ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ๋ฐ”๊พธ๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ์— ์œ ์šฉ ๋˜๋Š” ๊ฐœ๋ฐœ์‹œ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฃจ์•„ํŒŒ์ผ์„ require๋กœ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๊ณ ์ž ํ•  ๋•Œ luarocks๋กœ ์„ค์น˜ํ•œ๋‹ค. luarocks๋กœ ์„ค์น˜๋œ ๋ชจ๋“ˆ์€ ~/.bashrc์— eval "$(luarocks path --bin)"๋กœ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ž๋™์œผ๋กœ ํฌํ•จ๋œ๋‹ค. ๋ฌธ์ œ๋Š” ๊ฐ™์€ ๋ฆฌ๋ˆ…์Šค๋ผ๋„ ๋ฒ„์ „๊ฐ„ ๋ฐฐํฌํŒ๊ฐ„์— glibc ํ˜ธํ™˜์ด ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์ด๋‹ค. ๊ฑฐ์˜ ๋™์ผํ•œ ํ™˜๊ฒฝ์—์„œ๋งŒ ๋ฐฐํฌ ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ๋ณธ๋‹ค. ๋‹จ, alpine linux์˜ ๊ฒฝ์šฐ์—๋Š” glibc ๋ฒ„์ „ ๋ฌธ์ œ๊ฐ€ ์—†๊ณ , ์šฉ๋Ÿ‰๋„ ์ž‘๋‹ค. debian ๊ณ„์—ด ์š”๊ตฌ์‚ฌํ•ญ: build-essential(gcc), lua, luastatic alpine Linux ์š”๊ตฌ์‚ฌํ•ญ: build-base, clang, luajit, luastatic Install and Howto Install $ luarocks install --local luastatic # install luastatic $ export PATH=$PATH:$HOME/.luarocks/bin # set PATH for luarocks bin $ luastatic # show version and usage Compile Single Lua file $ luastatic myprogram.lua \ /usr/lib/x86_64-linux-gnu/liblua5.1.a \ -I /usr/include/lua5.1 $ ./myprogram Embed library.lua for require(โ€œlibraryโ€) $ luastatic myprogram.lua \ myprogram.lua \ library.lua \ /usr/lib/x86_64-linux-gnu/liblua5.1.a \ -I /usr/include/lua5.1 C library containing luaopen_() $ luastatic myprogram.lua \ library.a \ /usr/lib/x86_64-linux-gnu/liblua5.1.a \ -I /usr/include/lua5.1 LuaJit on Ubuntu - ์šฐ๋ถ„ํˆฌ์—์„œ LuaJit ์‚ฌ์šฉ $ sudo apt install luajit # install luajit - 2.1.0 $ sudo apt install libluajit-5.1-dev # install libluajit dev - 5.1 $ luastatic myprogram.lua \ /usr/lib/x86_64-linux-gnu/libluajit-5.1.a \ -I /usr/include/luajit-2.1 \ -no-pie LuaJit on Alpine - LuaJit, clang with musl lib static compile # apk add luajit luajit-dev # install luajit - 2.1.0 # apk add build-base clang make # install build base and clang # env CC=clang luastatic myprogram.lua \ /usr/lib/x86_64-linux-gnu/libluajit-5.1.a \ -I /usr/include/luajit-2.1 \ -no-pie ์ข€ ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ์กฐ Links https://github.com/ers35/luastatic ...

2022-08-30 ยท (updated 2022-11-29) ยท 249 words