{{tag>[cli rust rustc compiler]}} ====== rustc ====== Rust crate root를 binary 또는 library로 컴파일하는 공식 compiler frontend. ===== Summary ===== 일반 project는 Cargo를 통해 ''rustc''를 호출한다. 직접 호출은 단일 file 실험, build system 통합, compiler option 진단에 적합하다. ===== Installation ===== ''rustc''는 rustup toolchain에 포함된다. platform별 설치는 [[rust:ko#installation|Rust Installation]]을 따른다. rustup default stable rustc --version ===== Usage ===== rustc [options] input * ''**rustc** [options...] INPUT'' ===== Options ===== * ''-o FILE'': 출력 file 이름 지정. * ''--out-dir DIR'': output directory 지정. * ''--crate-name NAME'', ''--crate-type TYPE'': crate 이름과 산출물 종류 지정. * ''--edition YEAR'': source의 Rust edition 지정. * ''--emit KIND'': ''link'', ''metadata'', ''llvm-ir'', ''asm'', ''obj'' 같은 output 선택. * ''--target TRIPLE'': build target 지정. * ''-L [KIND=]PATH'', ''-l LIBRARY'': library search path와 native library 지정. * ''--extern NAME=PATH'': external crate 위치 지정. * ''-g'', ''-O'', ''-C OPTION'': debug information, optimization, code generation option 설정. * ''-A LINT'', ''-W LINT'', ''-D LINT'', ''-F LINT'': lint level 설정. * ''--explain CODE'': compiler error code 상세 설명. * ''--print KIND'': sysroot, target list, cfg 등 compiler 정보 출력. * ''-Z OPTION'': nightly 전용 unstable option. ===== Examples ===== rustc hello.rs rustc --edition 2024 hello.rs -o hello rustc --crate-type lib src/lib.rs rustc --target wasm32-unknown-unknown src/lib.rs rustc --explain E0382 rustc --print sysroot rustc --print target-list cargo build --verbose module이 여러 개인 project와 dependency resolution에는 직접 ''rustc''를 조립하기보다 Cargo를 사용한다. ''cargo build --verbose''로 Cargo가 생성한 compiler invocation을 볼 수 있다. ===== Compatibility ===== ''-Z'' option과 일부 target은 nightly 또는 추가 component가 필요하다. stable build automation에서 nightly option을 무조건 사용하지 않는다. ===== Troubleshooting ===== * cross target standard library는 ''rustup target add TARGET''으로 설치하지만 linker와 system library는 별도 준비가 필요할 수 있다. * linker 실패 시 verbose Cargo output과 target-specific linker 설정을 함께 확인한다. * compiler 진단을 machine-readable하게 처리하려면 ''--error-format=json''을 검토한다. ===== Help ===== +++ rustc --help | 로컬 실행 파일이 없어 live output을 수집하지 않았다. rustc --help rustc -C help rustc --print target-list +++ ===== See Also ===== * [[rust:ko]] * [[rust:rustup:ko]] * [[rust:cargo:ko]] * [[https://doc.rust-lang.org/rustc/|The rustc book]] ===== History ===== * codex:: 2026-07-20 Added rustc compilation, diagnostics, target, and code-generation reference. {{indexmenu>.#1|js}}