Bazel: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Add categories: Linux, Reference)
(Phase 6.1: LLM-Optimized Wiki Template 적용)
Line 1: Line 1:
Bazel is a tool that '''automates software builds and tests'''. Supported build tasks include running compilers and linkers to produce executable programs and libraries, and assembling deployable packages for Android, iOS and other target environments<ref>https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwix_f67rJqCAxUErlYBHc29CNkQFnoECAkQAw&url=https%3A%2F%2Fbazel.build%2Fabout%2Ffaq&usg=AOvVaw2LTedC5jnCi-zPHaBwVp9D&opi=89978449</ref>
{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-16
|review=Pending
}}


== Install specific version of bazel ==
{{TOC}}
[https://bazel.build/install Bazel install page] describes multiple way to install bazel,  following is our preferred method for automated build scripts that uses various version of bazel depending on the projects.<syntaxhighlight lang="bash">
#example version 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


# to install user only
== Overview ==
$./bazel-$_version-installer-linux-x86_64.sh --user


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


=== Summary ===
* 무엇인가? Google 개발 소프트웨어 빌드 및 테스트 자동화 도구
* 왜 필요한가? 복잡한 빌드 의존성 관리, 캐싱, 분산 빌드 지원
* 언제 사용하는가? 대규모 코드베이스, 다중 언어 프로젝트, CI/CD 파이프라인
---
== Purpose ==
이 문서가 존재하는 이유
* Goal: Bazel 설치 방법, 출력 경로 설정,常见问题 해결 가이드 제공
* Scope: Bazel 버전별 설치, --output_base/--output_user_root, server terminated 오류
* Non-goals: BUILD 파일 작성, Bazel 규칙 상세, Starlanguag 언어
---
== Key Concepts ==
{| class="wikitable"
! 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 빌드 아키텍처:
<syntaxhighlight lang="mermaid">
graph TD
    A[BUILD 파일] --> B[Bazel 분석기]
    B --> C[의존성 그래프 생성]
    C --> D[빌드 실행]
    D --> E[컴파일/링크]
    E --> F[출력 디렉토리]
    F --> G[output_base]
    F --> H[output_user_root]
</syntaxhighlight>
---
== Workflow ==
Bazel 기본 워크플로우:
# Bazel 설치
# 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 build //...
# 출력 경로 재지정
# bazel --output_base=/path/to/dir build //...
---
== Detailed Explanation ==
=== Bazel 설치 ===
Bazel 설치 페이지(https://bazel.build/install)에는 여러 설치 방법이 설명되어 있습니다. 다음은 다양한 Bazel 버전을 사용하는 자동화 빌드 스크립트에 선호하는 방법입니다.
<syntaxhighlight lang="bash">
# 예제 버전 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
</syntaxhighlight>
=== 출력 경로 재지정 ===
기본 출력 경로는 /tmp이지만, 버전이나 기본 .bazelrc에 따라 다른 출력 경로일 수 있습니다. 출력 경로를 재지정하려면 <code>--output_base</code> 또는 <code>--output_user_root</code>를 설정하여 모든 출력을 비기본 디렉토리에 배치합니다.
* <code>--output_base</code> — 기본 출력 디렉토리 재지정 시작 옵션
* <code>--output_user_root</code> — 기본 설치 디렉토리 및 출력 디렉토리 재지정 시작 옵션
<syntaxhighlight lang="bash">
bazel --output_base=/dir/path/you/want/to build //<whatever>
bazel --output_user_root=/dir/path/you/want/to build //<whatever>
</syntaxhighlight>
<code>bazel clean</code>은 <code>outputPath</code> 및 <code>action_cache</code> 디렉토리에 대해 <code>rm -rf</code>를 수행합니다. 또한 워크스페이스 심볼릭 링크도 제거합니다. <code>--expunge</code> 옵션은 전체 outputBase를 정리합니다.
=== Server terminated abruptly ===
이러한 종류의 문제(즉, <code>jvm.out</code> 없이)를 볼 때 가장 흔한 원인은 메모리 부족으로 OOM killer가 Bazel 서버 프로세스를 종료하는 것입니다.
* <code>--jobs</code>를 낮추는 것이 가장 직접적인 제한 방법
* <code>--local_ram_resources</code>는 이론적으로 도움이 되지만, Bazel은 각 컴파일 명령어가 얼마나 많은 RAM을 사용하는지 잘 모르기 때문에 매우 대략적입니다.
---
== Configuration ==
=== Bazel 빌드 옵션 ===
<syntaxhighlight lang="bash">
# 출력 경로 재지정
bazel --output_base=/custom/path build //...
# 작업 수 제한
bazel --jobs=2 build //...
# RAM 리소스 제한
bazel --local_ram_resources=4096 build //...
# 전체 정리
bazel clean --expunge
</syntaxhighlight>
</syntaxhighlight>


== Tips and tricks ==
---
 
== Examples ==
 
=== Example 1: Bazel 설치 ===


=== How to override the use of output when building with Bazel ===
입력:
* The default output path is /tmp but depending on the version or default .bazelrc can be different output path, to override output path set <code>--output_base</code> or --output_user_root to put all output in a non-default directory
** <code>--output_base</code> startup option to override the default output base directory
** <code>--output_user_root</code> startup option to override the default install base and output base
* <code>bazel --output_base=/dir/path/you/want/to build //<whatever></code>
* <code>bazel --output_user_root=/dir/path/you/want/to build //<whatever></code>


* <code>bazel clean</code> does an <code>rm -rf</code> on the <code>outputPath</code> and the <code>action_cache</code> directory. It also removes the workspace symlinks. The <code>--expunge</code> option will clean the entire outputBase.<ref>https://bazel.build/remote/output-directories</ref>
<syntaxhighlight lang="bash">
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
</syntaxhighlight>


=== Server terminated abruptly<ref>https://stackoverflow.com/questions/65605663/cannot-build-with-error-server-terminated-abruptly</ref> ===
=== Example 2: 출력 경로 재지정 빌드 ===


* The most common cause we've seen for this kind of thing (can't say for sure without the <code>jvm.out</code>) is running out of memory which results in the OOM killer terminating the bazel server process.
입력:
** Using a lower <code>--jobs</code> is the most direct way to limit that.
 
** <code>--local_ram_resources</code> will help in theory, but bazel doesn't have a very good idea how much RAM each compilation command uses so it's very approximate.
<syntaxhighlight lang="bash">
bazel --output_base=/tmp/bazel-builds/myproject build //src/...
</syntaxhighlight>
 
---
 
== 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 ==
== References ==
<references />
 
* https://bazel.build/install
* https://bazel.build/remote/output-directories
* https://stackoverflow.com/questions/65605663/cannot-build-with-error-server-terminated-abruptly
 
---
 
== Related Pages ==
 
* [[Cmake tips and tricks]]
* [[Compile tips and tricks]]
* [[Bash script]]
* [[Linux]]
 
---
 
[[Category:Linux]]
[[Category:Linux]]
[[Category:Reference]]
[[Category:Reference]]

Revision as of 14:34, 16 July 2026

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

---