Zig둜 gcc/clang 컴파일러 λŒ€μ²΄ν•˜κΈ°

last updated: {{ β€œ1712680347” | date: β€œ%Y-%m-%d %H:%M” }} Intro zig둜 c μ†ŒμŠ€λ₯Ό μ»΄νŒŒμΌν•  수 μžˆλ‹€. zig의 μž₯점은 μ—¬λŸ¬ ν”Œλž«νΌκ³Ό μ•„ν‚€ν…μ²˜μš© 컴파일이 κ°€λŠ₯ν•˜λ‹€λŠ” 것이닀. static, dynamic λͺ¨λ‘ κ°€λŠ₯ν•˜λ‹€. Linux, iOS, Windows λ“± μ—¬λŸ¬ OS ν™˜κ²½ 지원. x86, , x86-64, aarch64 λ“± μ•„ν‚€ν…μ²˜ 지원 Target List λ‹€μŒ λ°©λ²•μœΌλ‘œ μ›ν•˜λŠ” ν”Œλž«νΌ, 아킀텍쳐λ₯Ό λ¨Όμ € μ°ΎλŠ”λ‹€. $ zig targets $ zig targets | grep x86 $ zig targets | grep x86-64 $ zig targets | grep aarch64 $ zig targets | grep linux $ zig targets | grep windows $ zig targets | grep macos x86, x86_64 - intel 계열 aarch64 - arm 계열 (raspberrypi) linux - Linux windows - Ms Windows macos - Mac OS Local Compile dynamic: Alpine Linux (x86_64) $ zig cc -o hello_dynamic hello.c $ file hello_dynamic hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped $ ./hello Hello World! static: Alpine Linux (x86_64) $ zig cc -o hello hello.c -target x86_64-linux-musl $ file hello ./hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped $ ./hello Hello World! Cross Compile For windows $ zig cc -o hello.exe hello.c -target x86_64-windows-gnu $ file ./hello.exe hello: PE32+ executable (console) x86-64, for MS Windows, 7 sections Windows c:> .\hello.exe Hello World! For Linux dynamic with Gnu Libs $ zig cc -o hello hello.c -target x86_64-linux-gnu $ file ./hello.exe ./hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, with debug_info, not stripped gnu-linux$ ./hello Hello World! For Linux Static with musl $ zig cc -o hello.exe hello.c -target x86_64-linux-gnu $ file ./hello.exe ./hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped any-linux$ ./hello Hello World! Makefile or Build.sh ν•΄λ‹Ή νŒŒμΌμ—μ„œ gcc, clang 뢀뢄을 zig cc둜 μˆ˜μ •ν•œλ‹€. make λ˜λŠ” ./Build.sh μ‹€ν–‰ Links zig cc: a Powerful Drop-In Replacement for GCC/Clang https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html

2024-04-03 Β· 313 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