विषय पर बढ़ें

अंतिम अद्यतन:2026-10-12

Bazel से C++ प्रोजेक्ट बिल्ड करना

इस साइट के प्रोजेक्ट्स (CPlusPlusThings सहित) पहले ही Bazel बिल्ड पर आ चुके हैं; यहाँ शून्य से इंस्टॉल करके कंपाइल होने तक की पूरी प्रक्रिया दर्ज है — सभी कदम वास्तव में चलाकर परखे गए हैं।

1. इंस्टॉलेशन

Linux का उदाहरण लें तो, आधिकारिक सिफारिश installer स्क्रिप्ट से यूज़र-स्तरीय इंस्टॉल है (root की ज़रूरत नहीं): gpadmin@gpadmin:~$ ./bazel-6.1.1-installer-linux-x86_64.sh --user Bazel installer


Bazel is bundled with software licensed under the GPLv2 with Classpath exception. You can find the sources next to the installer on our release page: https://github.com/bazelbuild/bazel/releases

Build information

  • Commit Uncompressing......WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file). Extracting Bazel installation... .

Bazel is now installed!

Make sure you have "/home/gpadmin/bin" in your path.

For bash completion, add the following line to your : source /home/gpadmin/.bazel/bin/bazel-complete.bash

For fish shell completion, link this file into your /home/gpadmin/.config/fish/completions/ directory: ln -s /home/gpadmin/.bazel/bin/bazel.fish /home/gpadmin/.config/fish/completions/bazel.fish

See http://bazel.build/docs/getting-started.html to start a new project!

安装完默认放在 `~/bin`,可以先确认一下:
gpadmin@gpadmin:~$ ls ~/bin/ bazel
## 2.配置 PATH

安装器会提醒你把 `~/bin` 加进 PATH。编辑 `~/.bashrc`,在文件末尾加一行:
export PATH="\(PATH:\)HOME/bin"
然后重新加载使其生效:
source ~/.bashrc
## 3.验证与第一个构建
bazel --version
能打印版本号就说明装好了。接着到任意一个带 WORKSPACE/MODULE.bazel 的项目目录里跑:
bazel build //... ```

Bazel अपने-आप dependencies खींचता है और build artifacts कैश करता है, इसलिए दूसरी बार build लगभग सेकंडों में होती है—— Make से तेज़ होने का मूल कारण यही है: content-hash आधारित remote/local cache + सख़्त dependency closure।

इस साइट के प्रोजेक्ट को बिल्ड करने की पूरी व्यावहारिक जानकारी के लिए Bilibili वीडियो देखें: एपिसोड 1: Step By Step इस प्रोजेक्ट को कंपाइल करना, इस लेख के साथ मिलाकर और बेहतर। प्रश्न हों तो कमेंट सेक्शन में आपका स्वागत है~

संबंधित विषय

टिप्पणियाँ