Rust 첫 앱 실행 명령: cargo run -p hello-rust

넥스트플랫폼 동준상 대표 (naebon@naver.com)

2026.07.05 / 동준상.넥스트플랫폼
(AWS SAA, AWS AIF, GCP GenAI Leader)

이번 포스트에서는 기존 React 등 Node.js 프로젝트와 다른, Rust 특유의 워크스페이스 구조를 기준으로 -p 옵션과 cargo run의 다른 유용한 옵션에 대해 알아봅니다.

이번 Rust 프로젝트에 포함된 4개의 예제 앱

이번 프로젝트는 루트 Cargo.toml에 4개 crate가 묶인 Cargo workspace입니다.

Rust Command: cargo run -p hello-rust
Rust project Cargo.toml by NextPlatform

[workspace]

members = [

“hello-rust”,

“greeting-app”,

“mini-calculator”,

“rust-profile”,

]

hello-rust 앱 프로젝트 둘러보기

hello-rust 앱 프로젝트 (Rust Crate)에는 /src 속 main.rs, .gitignore, Cargo.toml 파일이 포함돼 있습니다.

Rust hello-rust crate files by NextPlatform

그 중 main.rs에는 아래와 같은 코드가 입력돼있습니다. 이 코드가 실행되면 어떤 결과가 출력될지 짐작이 가시지요?

Rust hello-rust crate main.rs by NextPlatform

크레이트 속에 있는 Cargo.toml에는 아래와 같은 내용이 입력돼있습니다.

Rust hello-rust crate Cargo.toml by NextPlatform

cargo run의 의미: Rust 앱 실행

Rust 기반 개별 앱 프로젝트(crate)를 선택한 후 cargo run을 실행하면 해당 앱이 빌드 & 런 상태가 됩니다.

cargo run -p hello-rust

Rust hello-rust by NextPlatform

-p 옵션의 의미

cargo run -p rust-profile

-p는 --package의 짧은 형태입니다.

“이 workspace 안에서 rust-profile이라는 crate(패키지)를 골라서 실행해라” 는 뜻입니다.

workspace 안에는 실행 가능한 프로그램이 여러 개 있으므로, Cargo는 어느 crate를 실행할지 알아야 합니다. 그때 -p로 crate 이름을 지정합니다.

명령어의미
cargo run -p hello-rusthello-rust crate 실행
cargo run -p greeting-appgreeting-app crate 실행
cargo run -p rust-profilerust-profile crate 실행

-p 없이 실행하면?

  • workspace 루트에서 cargo run만 치면 → Cargo가 어떤 crate를 실행할지 몰라 에러가 납니다.
  • crate 폴더 안(rust-profile/)에서 cargo run을 치면 → 그 폴더의 crate가 자동 선택되어 -p 없이도 됩니다.

# workspace 루트에서

cargo run -p rust-profile # OK

# crate 폴더에서

cd rust-profile

cargo run # OK (-p 불필요)

JS/TS로 비유하면, monorepo에서 pnpm --filter rust-profile start처럼 특정 패키지만 골라 실행하는 것과 비슷합니다.


cargo run에서 써볼 만한 다른 옵션

자주 쓰는 옵션

옵션긴 형태설명예시
-p--package실행할 crate 지정cargo run -p rust-profile
--release최적화 빌드 후 실행 (느리게 빌드, 빠르게 실행)cargo run -p rust-profile --release
--bin같은 crate에 binary가 여러 개일 때 특정 binary 지정cargo run -p my-crate --bin server
--exampleexample 코드 실행cargo run --example demo
--프로그램에 전달할 인자 (Cargo 옵션과 구분)cargo run -p greeting-app -- arg1
-q--quietCargo 출력 줄이기cargo run -p hello-rust -q
-v--verbose빌드 과정 자세히 보기cargo run -p hello-rust -v
--features특정 feature 켜고 빌드/실행cargo run -p my-crate --features json
--no-default-features기본 feature 끄고 실행cargo run -p my-crate --no-default-features
--target특정 OS/CPU용 cross-compile 후 실행cargo run --target x86_64-pc-windows-msvc

이번 Day 1 프로젝트에서 바로 써볼 수 있는 것

1. 조용히 실행 (-q)

cargo run -p hello-rust -q

Compiling...Finished... 같은 Cargo 메시지 없이 프로그램 출력만 보입니다.

2. release 모드 (--release)

cargo run -p rust-profile –release

디버그(target/debug/) 대신 최적화 빌드(target/release/)로 실행합니다. Day 1 수준에서는 체감 차이는 거의 없지만, 나중에 성능 비교할 때 유용합니다.

3. verbose (-v)

cargo run -p mini-calculator -v

어떤 파일을 컴파일하는지 상세 로그를 볼 수 있습니다. 빌드가 왜 느린지, 무엇이 다시 컴파일되는지 알 때 좋습니다.

4. 프로그램에 인자 전달 (--)

Day 1 코드는 아직 CLI 인자를 받지 않지만, 나중에 이런 식으로 씁니다:

cargo run -p my-app — –help

# Cargo 옵션 ↑ ↑ 프로그램 인자

-- 앞은 Cargo 옵션, 뒤는 여러분 Rust 프로그램(main의 args)에 넘어갑니다.


workspace와 함께 자주 쓰는 조합

# 특정 crate만 release로 실행

cargo run -p greeting-app –release

# workspace 전체 빌드만 (실행 X)

cargo build –workspace

# 특정 crate만 빌드

cargo build -p mini-calculator

# 빌드 없이, 이미 만들어진 binary만 실행

cargo run -p hello-rust –quiet


결론: 한 줄 정리

  • -p rust-profile → workspace 4개 crate 중 rust-profile만 골라 cargo run
  • -p 없이 루트에서 cargo run → 어떤 crate인지 모름 → 에러
  • 다른 유용 옵션: --release(최적화), -q(조용히), -v(자세히), --(프로그램 인자 전달)

답글 남기기