빌드 규칙 가이드
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
소개
샌드박스 API (SAPI)는 Google의 Bazel 빌드 시스템 또는 인기 있는 CMake 메타 빌드 시스템과 함께 사용할 수 있습니다.
이 페이지에서는 Bazel에 중점을 두지만 CMake에서도 동일한 기능을 사용할 수 있습니다. Bazel은 권장되는 빌드 시스템이며 통합하기 가장 쉽습니다.
BUILD.bazel 파일에는 호스트 코드를 빌드하는 빌드 규칙이 있습니다. 호스트 코드가 샌드박스 처리된 라이브러리 버전을 사용하려면 호스트 코드가 사용할 빌드 타겟을 준비해야 합니다.
SAPI 빌드 규칙
sapi_library
sapi_library(name, deps, srcs, hdrs, embed, functions, lib, lib_name, input_files, namespace, header, add_default_deps, limit_scan_depth, visibility)
출력 타겟
sapi_library()
빌드 규칙은 다음 타겟을 생성합니다.
- name-sapi: 샌드박스 라이브러리로, 호스트 코드 타겟으로 일반 cc_library를 대체합니다.
zlib_sapi.bin
및 샌드박스 종속 항목으로 구성됩니다.
- name.interface: 생성된 라이브러리 인터페이스입니다.
- name.embed: 바이너리에 Sandboxee를 삽입하는 데 사용되는
cc_embed_data()
타겟입니다. bazel/embed_data.bzl을 참고하세요.
- name.bin: 샌드박스 처리된 바이너리로, 작은 통신 스텁과 샌드박스 처리되는 라이브러리로 구성됩니다.
인수
속성 |
이름 |
이름: 필수
이 타겟의 고유한 이름입니다. 샌드박스 처리된 C/C++ 라이브러리를 식별합니다. name-sapi 출력 타겟을 참고하세요.
|
deps |
라벨 목록입니다(선택사항).
샌드박스 C/C++ 라이브러리에 연결할 다른 라이브러리 목록입니다.
|
srcs |
라벨 목록입니다(선택사항).
샌드박스 C/C++ 라이브러리를 만들기 위해 처리되는 C 및 C++ 파일 목록입니다. 생성되지 않은 (일반 소스 코드) 또는 생성된 C/C++ 소스 및 헤더 파일입니다.
자세한 내용은
cc_library 문서의 srcs 속성 설명을 참고하세요.
|
hdrs |
라벨 목록입니다(선택사항).
샌드박스 C/C++ 라이브러리를 만들기 위해 처리되는 헤더 파일 목록입니다.
여기에 샌드박스 정의 (sandbox.h)가 있어야 합니다. 삽입된 SAPI 라이브러리가 사용되고 기본 샌드박스 정책이 충분한 경우 비워 두세요.
|
소스 |
불리언, 선택사항, 기본값은 True
True인 경우 샌드박스 라이브러리가 호스트 코드 내에 삽입되어야 합니다. 이렇게 하면 SAPI 샌드박스를 ::sapi::Sandbox::Sandbox(FileToc*) 생성자로 초기화할 수 있습니다.
|
함수 |
함수 이름 목록입니다(선택사항).
샌드박스 처리된 버전이 생성되고 호스트 코드에서 사용할 수 있는 C/C++ 라이브러리의 함수 목록입니다.
빈 목록은 라이브러리에서 찾은 모든 함수를 내보내고 래핑하려고 시도합니다.
|
lib |
문자열, 필수
샌드박스 처리된 라이브러리가 될 C/C++ 라이브러리 타겟의 이름입니다.
이렇게 하면 프로젝트에 C/C++ 라이브러리의 cc_library 빌드 규칙이 있다고 가정합니다.
|
lib_name |
문자열, 필수
함수 속성에서 라이브러리 함수를 프록시하는 데 사용되는 SAPI 객체의 이름입니다. 샌드박스 라이브러리의 함수 호출은 SAPI 객체를 통해 이루어집니다.
|
input_files |
라벨 목록입니다(선택사항).
sapi_interface 규칙의 내부 실행 중에 처리되는 C 및 C++ 파일 목록입니다. 생성기는 이러한 파일에서 C/C++ 라이브러리의 함수 선언을 검색합니다.
C/C++ 라이브러리의 내보낸 헤더는 항상 스캔되므로 대부분 필요하지 않습니다.
|
네임스페이스 |
문자열, 선택사항, 기본값은 sapigen
lib_name으로 정의된 SAPI 객체를 배치할 C++ 네임스페이스 식별자입니다.
기본 네임스페이스는 sapigen입니다.
|
문자열, 선택사항
생성된 헤더 파일 대신 사용할 헤더 파일의 이름입니다.
코드를 자동 생성하려면 이 속성을 사용하지 마세요.
|
add_default_deps |
불리언, 선택사항, 기본값은 True
지원 중단됨
|
limit_scan_depth |
불리언, 선택사항, 기본값은 False
복잡한 라이브러리의 경우 Bazel의 파일 수가 제한에 도달하여 빌드 프로세스가 성공하지 못할 수 있습니다. 이 속성은 이러한 복잡한 상황을 위한 비상구입니다. 필요한 경우가 아니라면 사용하지 마세요.
|
tags |
태그는 Bazel 문서를 참고하세요.
|
공개 상태 |
공개 상태는 Bazel 문서를 참고하세요.
|
사용 예
zlib 예시는 sapi_library 빌드 규칙이 사용되는 방법을 보여주는 좋은 참조 프로젝트입니다.
load(
"//sandboxed_api/tools/generator:sapi_generator.bzl",
"sapi_library",
)
sapi_library(
name = "zlib-sapi",
srcs = [], # Extra code compiled with the SAPI library
hdrs = [], # Leave empty if embedded SAPI libraries are used, and the
# default sandbox policy is sufficient.
embed = True, # This is the default
functions = [
"deflateInit_",
"deflate",
"deflateEnd",
],
lib = "@zlib//:zlibonly",
lib_name = "Zlib",
namespace = "sapi::zlib",
)
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eSandboxed API (SAPI) integrates with Bazel and CMake, with Bazel being the recommended build system.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esapi_library\u003c/code\u003e rule in Bazel is used to build sandboxed versions of libraries.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003esapi_library\u003c/code\u003e generates targets like \u003ccode\u003ename-sapi\u003c/code\u003e for the sandboxed library and \u003ccode\u003ename.embed\u003c/code\u003e for embedding the Sandboxee.\u003c/p\u003e\n"],["\u003cp\u003eSeveral arguments in \u003ccode\u003esapi_library\u003c/code\u003e allow customization such as \u003ccode\u003efunctions\u003c/code\u003e to specify functions to sandbox and \u003ccode\u003elib\u003c/code\u003e to define the library target.\u003c/p\u003e\n"],["\u003cp\u003eAn example using zlib demonstrates the practical application of the \u003ccode\u003esapi_library\u003c/code\u003e rule.\u003c/p\u003e\n"]]],[],null,["Introduction\n\nSandboxed API (SAPI) can be used with Google's [Bazel](https://bazel.build/)\nbuild system, or with the popular [CMake](https://cmake.org/) meta build system.\nThis page focuses on Bazel, but the same features are available for CMake. Bazel\nis the recommended build system and the easiest to integrate with.\n\nIn your BUILD.bazel file you will have a build rule to build your Host Code. For\nthe Host Code to use the sandboxed version of a library, you need to prepare a\nbuild target that your Host Code will make use of.\n\nSAPI Build Rules\n\n- sapi_library\n\nsapi_library \n\n```\nsapi_library(name, deps, srcs, hdrs, embed, functions, lib, lib_name, input_files, namespace, header, add_default_deps, limit_scan_depth, visibility)\n```\n\nOutput Targets\n\nThe `sapi_library()` build rule generates the following targets:\n\n- *name-sapi* : Sandboxed library, substitutes the normal cc_library as the Host Code target. Consists of `zlib_sapi.bin` and sandbox dependencies.\n- *name*.interface: Generated library interface.\n- *name* .embed: `cc_embed_data()` target used to embed the Sandboxee in the binary. See [bazel/embed_data.bzl](https://github.com/google/sandboxed-api/blob/main/sandboxed_api/bazel/embed_data.bzl).\n - *name*.bin: Sandboxee binary, consists of a small communication stub and the library that is being sandboxed.\n\nArguments\n\n| Attributes ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| name | [Name](https://docs.bazel.build/versions/main/build-ref.html#name); required A unique name for this target. This will identify the sandboxed C/C++ library, see the name-sapi output target. |\n| deps | List of [labels](https://docs.bazel.build/versions/main/build-ref.html#labels); optional A list of other libraries to be linked into the sandboxed C/C++ library. |\n| srcs | List of [labels](https://docs.bazel.build/versions/main/build-ref.html#labels); optional A list of C and C++ files that are processed to create the sandboxed C/C++ library. These are C/C++ source and header files, either non-generated (normal source code) or generated. For more information, see the explanation of the attribute srcs in the [cc_library documentation](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.srcs). |\n| hdrs | List of [labels](https://docs.bazel.build/versions/main/build-ref.html#labels); optional A list of header files that are processed to create the sandboxed C/C++ library. This is where the sandbox definition (sandbox.h) should go; leave empty if the embedded SAPI library is used, and the default sandbox policy is sufficient. |\n| embed | Boolean; optional; default is True If True, the sandboxed library should be embedded inside the host code. This allows the SAPI Sandbox to be initialized with the `::sapi::Sandbox::Sandbox(FileToc*)` constructor. |\n| functions | List of function names; optional A list of functions from the C/C++ library for which a sandboxed version is generated and that can then be used in the Host Code. An empty list will try to export and wrap all functions found in the library. |\n| lib | String; required The name of the C/C++ library target which is going to be the sandboxed library. This expects that you have a cc_library build rule for the C/C++ library in the project. |\n| lib_name | String; required The name of the SAPI object which is used to proxy the library functions from the functions attribute. Any call to the function in the sandboxed library will happen via the SAPI Object. |\n| input_files | List of [labels](https://docs.bazel.build/versions/main/build-ref.html#labels); optional A list of C and C++ files that are processed during the internal run of the sapi_interface rule. The generator scans these files for the C/C++ library's function declarations. This is mostly not needed as the C/C++ library's exported headers are always scanned. |\n| namespace | String; optional; default is sapigen A C++ namespace identifier to place the SAPI object defined by *lib_name* into. The default namespace is *sapigen*. |\n| header | String; optional The name of the header file to use instead of the generated header file. If you want to auto-generate the code, **do not use** this attribute |\n| add_default_deps | Boolean; optional; default is True **DEPRECATED** |\n| limit_scan_depth | Boolean; optional; default is False For complex libraries, the file-count for Bazel might be reached and the build process will not succeed. This attribute is an escape hatch for these complex situations. **Do not use** unless necessary. |\n| tags | See Bazel documentation for [tags](https://docs.bazel.build/versions/main/be/common-definitions.html#common.tags). |\n| visibility | See Bazel documentation for [visibility](https://docs.bazel.build/versions/main/be/common-definitions.html#common.visibility) |\n\nExample Use\n\nThe zlib example is a good reference project demonstrating how the sapi_library\nbuild rule is used: \n\n load(\n \"//sandboxed_api/tools/generator:sapi_generator.bzl\",\n \"sapi_library\",\n )\n\n sapi_library(\n name = \"zlib-sapi\",\n srcs = [], # Extra code compiled with the SAPI library\n hdrs = [], # Leave empty if embedded SAPI libraries are used, and the\n # default sandbox policy is sufficient.\n embed = True, # This is the default\n functions = [\n \"deflateInit_\",\n \"deflate\",\n \"deflateEnd\",\n ],\n lib = \"@zlib//:zlibonly\",\n lib_name = \"Zlib\",\n namespace = \"sapi::zlib\",\n )"]]