Bazel

From HPCWIKI
Revision as of 14:34, 16 July 2026 by Clara (talk | contribs) (Phase 6.1: LLM-Optimized Wiki Template 적용)
Jump to navigation Jump to search

Template:Status

Template:TOC

Overview

Bazel은 소프트웨어 빌드 및 테스트를 자동화하는 도구입니다. 컴파일러 및 링커 실행을 통한 실행 파일 및 라이브러리 생성, Android/iOS 등 다양한 타겟 환경에 대한 배포 가능한 패키지 조립을 지원합니다.

Summary

  • 무엇인가? Google 개발 소프트웨어 빌드 및 테스트 자동화 도구
  • 왜 필요한가? 복잡한 빌드 의존성 관리, 캐싱, 분산 빌드 지원
  • 언제 사용하는가? 대규모 코드베이스, 다중 언어 프로젝트, CI/CD 파이프라인

---

Purpose

이 문서가 존재하는 이유

  • Goal: Bazel 설치 방법, 출력 경로 설정,常见问题 해결 가이드 제공
  • Scope: Bazel 버전별 설치, --output_base/--output_user_root, server terminated 오류
  • Non-goals: BUILD 파일 작성, Bazel 규칙 상세, Starlanguag 언어

---

Key Concepts

Concept Description Related
Bazel Google 개발 빌드 및 테스트 자동화 도구 Linux
--output_base 빌드 출력 기본 디렉토리 재지정 Bazel
--output_user_root 설치 기본 및 출력 디렉토리 재지정 Bazel
bazel clean 출력 경로 및 action_cache 디렉토리 정리 Bazel
--expunge 전체 outputBase 정리 Bazel
--jobs 동시 빌드 작업 수 제한 Bazel
--local_ram_resources 로컬 RAM 리소스 제한 Bazel

---

Architecture

Bazel 빌드 아키텍처:

graph TD
    A[BUILD 파일] --> B[Bazel 분석기]
    B --> C[의존성 그래프 생성]
    C --> D[빌드 실행]
    D --> E[컴파일/링크]
    E --> F[출력 디렉토리]
    F --> G[output_base]
    F --> H[output_user_root]

---

Workflow

Bazel 기본 워크플로우:

  1. Bazel 설치
  2. wget https://github.com/bazelbuild/bazel/releases/download/VERSION/bazel-VERSION-installer-linux-x86_64.sh
  3. chmod +x bazel-VERSION-installer-linux-x86_64.sh
  4. ./bazel-VERSION-installer-linux-x86_64.sh [--user]
  1. 빌드 실행
  2. bazel build //...
  1. 출력 경로 재지정
  2. bazel --output_base=/path/to/dir build //...

---

Detailed Explanation

Bazel 설치

Bazel 설치 페이지(https://bazel.build/install)에는 여러 설치 방법이 설명되어 있습니다. 다음은 다양한 Bazel 버전을 사용하는 자동화 빌드 스크립트에 선호하는 방법입니다.

# 예제 버전 6.3.2
export _version=6.3.2
wget https://github.com/bazelbuild/bazel/releases/download/$_version/bazel-$_version-installer-linux-x86_64.sh
chmod +x bazel-$_version-installer-linux-x86_64.sh

# 사용자 전용 설치
./bazel-$_version-installer-linux-x86_64.sh --user

# 시스템 전체 설치
./bazel-$_version-installer-linux-x86_64.sh

출력 경로 재지정

기본 출력 경로는 /tmp이지만, 버전이나 기본 .bazelrc에 따라 다른 출력 경로일 수 있습니다. 출력 경로를 재지정하려면 --output_base 또는 --output_user_root를 설정하여 모든 출력을 비기본 디렉토리에 배치합니다.

  • --output_base — 기본 출력 디렉토리 재지정 시작 옵션
  • --output_user_root — 기본 설치 디렉토리 및 출력 디렉토리 재지정 시작 옵션
bazel --output_base=/dir/path/you/want/to build //<whatever>
bazel --output_user_root=/dir/path/you/want/to build //<whatever>

bazel cleanoutputPathaction_cache 디렉토리에 대해 rm -rf를 수행합니다. 또한 워크스페이스 심볼릭 링크도 제거합니다. --expunge 옵션은 전체 outputBase를 정리합니다.

Server terminated abruptly

이러한 종류의 문제(즉, jvm.out 없이)를 볼 때 가장 흔한 원인은 메모리 부족으로 OOM killer가 Bazel 서버 프로세스를 종료하는 것입니다.

  • --jobs를 낮추는 것이 가장 직접적인 제한 방법
  • --local_ram_resources는 이론적으로 도움이 되지만, Bazel은 각 컴파일 명령어가 얼마나 많은 RAM을 사용하는지 잘 모르기 때문에 매우 대략적입니다.

---

Configuration

Bazel 빌드 옵션

# 출력 경로 재지정
bazel --output_base=/custom/path build //...

# 작업 수 제한
bazel --jobs=2 build //...

# RAM 리소스 제한
bazel --local_ram_resources=4096 build //...

# 전체 정리
bazel clean --expunge

---

Examples

Example 1: Bazel 설치

입력:

export _version=6.3.2
wget https://github.com/bazelbuild/bazel/releases/download/$_version/bazel-$_version-installer-linux-x86_64.sh
chmod +x bazel-$_version-installer-linux-x86_64.sh
./bazel-$_version-installer-linux-x86_64.sh --user

Example 2: 출력 경로 재지정 빌드

입력:

bazel --output_base=/tmp/bazel-builds/myproject build //src/...

---

Best Practices

  • 버전별 설치 — 프로젝트별로 다른 Bazel 버전 필요 시 버전별 설치 권장
  • --output_base 사용 — 빌드 출력 전용 디렉토리 분리 (디스크 관리 용이)
  • --jobs 제한 — 메모리 부족 방지 위해 동시 작업 수 제한
  • bazel clean --expunge — 전체 출력 정리 시 --expunge 옵션 사용
  • --local_ram_resources — 시스템 RAM에 맞게 리소스 제한 설정

---

Limitations

  • Bazel 서버는 메모리를 많이 사용 — OOM 발생 가능
  • --local_ram_resources는 정확한 RAM 사용량 추정이 어려움
  • --output_base 변경 시 기존 빌드 캐시 손실 가능
  • Bazel 학습 곡선이 가파름

---

References

---

Related Pages

---