กฎ
- cc_proto_library
- java_lite_proto_library
- java_proto_library
- proto_library
- py_proto_library
- proto_lang_toolchain
- proto_toolchain
cc_proto_library
ดูแหล่งที่มาของกฎcc_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
cc_proto_library
สร้างโค้ด C++ จากไฟล์ .proto
deps
ต้องชี้ไปยังกฎ proto_library
ตัวอย่าง
cc_library(
name = "lib",
deps = [":foo_cc_proto"],
)
cc_proto_library(
name = "foo_cc_proto",
deps = [":foo_proto"],
)
proto_library(
name = "foo_proto",
)
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
deps
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ proto_library
กฎที่จะใช้สร้างโค้ด C++
|
java_lite_proto_library
ดูแหล่งที่มาของกฎjava_lite_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
java_lite_proto_library
สร้างโค้ด Java จากไฟล์ .proto
deps
ต้องชี้ไปยังกฎ proto_library
ตัวอย่าง
java_library(
name = "lib",
runtime_deps = [":foo"],
)
java_lite_proto_library(
name = "foo",
deps = [":bar"],
)
proto_library(
name = "bar",
)
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
deps
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ proto_library
กฎที่จะใช้สร้างโค้ด Java
|
java_proto_library
ดูแหล่งที่มาของกฎjava_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, licenses, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
java_proto_library
สร้างโค้ด Java จากไฟล์ .proto
deps
ต้องชี้ไปยังกฎ proto_library
ตัวอย่าง
java_library(
name = "lib",
runtime_deps = [":foo_java_proto"],
)
java_proto_library(
name = "foo_java_proto",
deps = [":foo_proto"],
)
proto_library(
name = "foo_proto",
)
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
deps
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ proto_library
กฎที่จะใช้สร้างโค้ด Java
|
proto_library
ดูแหล่งที่มาของกฎproto_library(name, deps, srcs, data, allow_exports, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, exports, features, import_prefix, licenses, package_metadata, restricted_to, strip_import_prefix, tags, target_compatible_with, testonly, toolchains, visibility)
ใช้ proto_library
เพื่อกำหนดไลบรารีของ Protocol Buffer ซึ่ง
อาจใช้ได้จากหลายภาษา proto_library
อาจแสดงอยู่ในdeps
ของกฎที่รองรับ เช่น
java_proto_library
เมื่อคอมไพล์ในบรรทัดคำสั่ง proto_library
จะสร้างไฟล์
ชื่อ foo-descriptor-set.proto.bin
ซึ่งเป็นชุดตัวอธิบายสำหรับ
ข้อความที่กฎ srcs ไฟล์เป็น
FileDescriptorSet
ที่แปลงเป็นอนุกรม ซึ่งอธิบายไว้ใน
https://developers.google.com/protocol-buffers/docs/techniques#self-description
โดยจะมีเฉพาะข้อมูลเกี่ยวกับ.proto
ไฟล์ที่กฎproto_library
กล่าวถึงโดยตรง
เท่านั้น ส่วนการรวบรวมชุดตัวอธิบายแบบทรานซิทีฟ
จะใช้ได้ผ่าน[ProtoInfo].transitive_descriptor_sets
ผู้ให้บริการ Starlark
ดูเอกสารประกอบใน proto_info.bzl
การจัดระเบียบโค้ดที่แนะนำ
- กฎ 1 ข้อ
proto_library
ต่อไฟล์.proto
- ไฟล์ชื่อ
foo.proto
จะอยู่ในกฎชื่อfoo_proto
ซึ่งอยู่ในแพ็กเกจเดียวกัน [language]_proto_library
ที่ครอบproto_library
ชื่อfoo_proto
ควรเรียกว่าfoo_[language]_proto
และอยู่ในแพ็กเกจเดียวกัน
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
deps
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ proto_library กฎอื่นๆ ที่เป้าหมายขึ้นอยู่ด้วย
proto_library จะขึ้นอยู่กับเป้าหมาย proto_library
อื่นๆ เท่านั้น และต้องไม่ขึ้นอยู่กับไลบรารีเฉพาะภาษา
|
srcs
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ .proto และ .protodevel ที่
ประมวลผลเพื่อสร้างเป้าหมาย ซึ่งโดยปกติแล้วจะเป็นรายการที่ไม่ว่าง กรณีการใช้งานหนึ่งที่ srcs อาจว่างเปล่าคือไลบรารีชื่อแทน นี่คือ
กฎ proto_library ที่มี proto_library อื่นอย่างน้อย 1 รายการใน deps
รูปแบบนี้สามารถใช้เพื่อส่งออก API สาธารณะภายใต้ชื่อถาวรได้ เป็นต้น
|
allow_exports
|
ป้ายกำกับ ค่าเริ่มต้นคือ |
exports
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ |
import_prefix
|
สตริง ค่าเริ่มต้นคือ เมื่อตั้งค่าแล้ว ไฟล์ต้นฉบับ .proto ในแอตทริบิวต์ ระบบจะนำคำนำหน้าในแอตทริบิวต์ |
strip_import_prefix
|
สตริง ค่าเริ่มต้นคือ เมื่อตั้งค่าแล้ว ไฟล์ต้นฉบับ .proto ในแอตทริบิวต์ หากเป็นเส้นทางแบบสัมพัทธ์ (ไม่ได้ขึ้นต้นด้วยเครื่องหมายทับ) ระบบจะถือว่าเป็นเส้นทางแบบสัมพัทธ์ของแพ็กเกจ หากเป็นเส้นทางสัมบูรณ์ ระบบจะถือว่าเป็นเส้นทางสัมพัทธ์ของที่เก็บ ระบบจะเพิ่มคำนำหน้าในแอตทริบิวต์ |
py_proto_library
ดูแหล่งที่มาของกฎpy_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
deps
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ |
proto_lang_toolchain
ดูแหล่งที่มาของกฎproto_lang_toolchain(name, allowlist_different_package, aspect_hints, blacklisted_protos, command_line, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, mnemonic, output_files, package_metadata, plugin, plugin_format_flag, progress_message, protoc_minimal_do_not_use, restricted_to, runtime, tags, target_compatible_with, testonly, toolchain_type, toolchains, visibility)
หากใช้ Bazel โปรดโหลดกฎจาก https://github.com/bazelbuild/rules_proto
ระบุวิธีกำหนดกฎ LANG_proto_library (เช่น java_proto_library
) ควรเรียกใช้
โปรโตคอมไพเลอร์
กฎ LANG_proto_library บางอย่างอนุญาตให้ระบุ Toolchain ที่จะใช้โดยใช้แฟล็กบรรทัดคำสั่ง
โปรดดูเอกสารประกอบ
โดยปกติแล้ว คุณไม่ควรเขียนกฎประเภทดังกล่าว เว้นแต่ต้องการปรับแต่งคอมไพเลอร์ Java
ไม่มีคอมไพเลอร์ คอมไพเลอร์โปรโตมาจากกฎ proto_library ที่เราแนบมา โดยจะ
ส่งเป็นแฟล็กบรรทัดคำสั่งไปยัง Blaze
ฟีเจอร์หลายอย่างต้องเรียกใช้โปรแกรมคอมไพเลอร์ Proto ในกฎ proto_library เอง
การบังคับให้คอมไพเลอร์ที่ LANG_proto_library ใช้เป็นคอมไพเลอร์เดียวกับที่ proto_library
ใช้จะเป็นประโยชน์
ตัวอย่าง
ตัวอย่างง่ายๆ มีดังนี้
proto_lang_toolchain(
name = "javalite_toolchain",
command_line = "--javalite_out=shared,immutable:$(OUT)",
plugin = ":javalite_plugin",
runtime = ":protobuf_lite",
)
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
allowlist_different_package
|
ป้ายกำกับ ค่าเริ่มต้นคือ |
blacklisted_protos
|
รายการป้ายกำกับ ค่าเริ่มต้นคือ srcs ของ
blacklisted_protos
ใช้สำหรับไฟล์ .proto ที่ลิงก์กับรันไทม์ของ Proto อยู่แล้ว เช่น
any.proto
|
command_line
|
สตริง; ต้องระบุ ค่านี้จะส่งไปยังโปรโตคอมไพเลอร์เพื่อสร้างโค้ด รวมเฉพาะส่วนที่ เกี่ยวข้องกับเครื่องมือสร้างโค้ด/ปลั๊กอินนี้ (เช่น อย่ารวมพารามิเตอร์ -I)
|
mnemonic
|
สตริง ค่าเริ่มต้นคือ |
output_files
|
สตริง ค่าเริ่มต้นคือ $(OUT) ใน command_line ไม่ว่าจะโดย
เส้นทางไปยังไฟล์เดียวหรือไดเรกทอรีเอาต์พุตในกรณีที่มีหลายไฟล์
ค่าที่เป็นไปได้คือ "single", "multiple"
|
plugin
|
ป้ายกำกับ ค่าเริ่มต้นคือ --plugin=protoc-gen-PLUGIN=<executable>.
|
plugin_format_flag
|
สตริง ค่าเริ่มต้นคือ --plugin=protoc-gen-PLUGIN=<executable>.
|
progress_message
|
สตริง ค่าเริ่มต้นคือ |
protoc_minimal_do_not_use
|
ป้ายกำกับ ค่าเริ่มต้นคือ |
runtime
|
ป้ายกำกับ ค่าเริ่มต้นคือ |
toolchain_type
|
ป้ายกำกับ ค่าเริ่มต้นคือ |
proto_toolchain
ดูแหล่งที่มาของกฎproto_toolchain(name, aspect_hints, command_line, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, mnemonic, output_files, package_metadata, progress_message, proto_compiler, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
อาร์กิวเมนต์
Attributes | |
---|---|
name |
ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ |
command_line
|
สตริง ค่าเริ่มต้นคือ |
mnemonic
|
สตริง ค่าเริ่มต้นคือ |
output_files
|
สตริง ค่าเริ่มต้นคือ |
progress_message
|
สตริง ค่าเริ่มต้นคือ |
proto_compiler
|
ป้ายกำกับ ค่าเริ่มต้นคือ |