กฎ
- 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, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, 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, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, 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, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, licenses, 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, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, exports, features, import_prefix, licenses, restricted_to, strip_import_prefix, tags, target_compatible_with, testonly, toolchains, visibility)
หากใช้ Bazel โปรดโหลดกฎจาก https://github.com/bazelbuild/rules_proto
ใช้ 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
การจัดระเบียบโค้ดที่แนะนำ
- กฎ 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 rule ที่มี proto_library อื่นอย่างน้อย 1 รายการในdepsคุณสามารถใช้รูปแบบนี้เพื่อส่งออก API สาธารณะภายใต้ชื่อถาวรได้ เป็นต้น | 
| allow_exports | ป้ายกำกับ ค่าเริ่มต้นคือ  | 
| exports | รายการป้ายกำกับ ค่าเริ่มต้นคือ  | 
| import_prefix | สตริง ค่าเริ่มต้นคือ  เมื่อตั้งค่าแล้ว ไฟล์ต้นฉบับ .proto ในแอตทริบิวต์  ระบบจะนำคำนำหน้าในแอตทริบิวต์  | 
| strip_import_prefix | สตริง ค่าเริ่มต้นคือ  เมื่อตั้งค่าแล้ว ไฟล์ต้นฉบับ .proto ในแอตทริบิวต์  หากเป็นเส้นทางแบบสัมพัทธ์ (ไม่ได้ขึ้นต้นด้วยเครื่องหมายทับ) ระบบจะถือว่าเป็นเส้นทางแบบสัมพัทธ์ของแพ็กเกจ หากเป็นเส้นทางสัมบูรณ์ ระบบจะถือว่าเป็นเส้นทางสัมพัทธ์ของที่เก็บ ระบบจะเพิ่มคำนำหน้าในแอตทริบิวต์  | 
py_proto_library
ดูแหล่งที่มาของกฎpy_proto_library(name, deps, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
อาร์กิวเมนต์
| Attributes | |
|---|---|
| name | ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ | 
| deps | รายการป้ายกำกับ ค่าเริ่มต้นคือ  | 
proto_lang_toolchain
ดูแหล่งที่มาของกฎproto_lang_toolchain(name, allowlist_different_package, blacklisted_protos, command_line, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, mnemonic, output_files, 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 ที่เราแนบมา โดยจะ
ส่งเป็น Flag บรรทัดคำสั่งไปยัง 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, command_line, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, mnemonic, output_files, progress_message, proto_compiler, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
อาร์กิวเมนต์
| Attributes | |
|---|---|
| name | ชื่อ (ต้องระบุ) ชื่อที่ไม่ซ้ำกันสำหรับเป้าหมายนี้ | 
| command_line | สตริง ค่าเริ่มต้นคือ  | 
| mnemonic | สตริง ค่าเริ่มต้นคือ  | 
| output_files | สตริง ค่าเริ่มต้นคือ  | 
| progress_message | สตริง ค่าเริ่มต้นคือ  | 
| proto_compiler | ป้ายกำกับ ค่าเริ่มต้นคือ  |