blob: 86302db48056ffb24437bb965bb255a14f87df56 [file] [log] [blame]
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
{namespace cgo_libraru}
/***/
{template .soyweb}
{call buck.page}
{param title: 'cgo_library()' /}
{param navid: 'rule_cgo_library' /}
{param prettify: true /}
{param description}
A cgo_library() rule builds a native C/C++ object with cgo utility.
{/param}
{param content}
{call buck.rule}
{param status: 'UNFROZEN' /}
{param overview}
A cgo_library() rule builds an object from the supplied set of Go/C source files and
dependencies. The outputs are linked into go executable in the last step (compile).
The 'go build' command would collect the cgo directives from the source files, however
with buck the flags needs to be passed in the cgo_library manually
This rule borrows from {call buck.cxx_binary /} since C/C++ sources are being compiled.
{/param}
{param args}
{call buck.name_arg /}
{call go_common.package_name_arg /}
{call buck.arg}
{param name : 'srcs' /}
{param default : '[]' /}
{param desc}
The set of source files to be compiled by this rule. .go files will be compiled with the CGO
compiler. Each file needs to have <code>import "C"</code> declared.
{/param}
{/call}
{call buck.arg}
{param name : 'go_srcs' /}
{param desc}
The set of source files to be compiled by this rule. Go (<code>.go</code>) files are compiled with the Go
compiler. In contrast to the <code>srcs</code> argument, these files <em>cannot</em> have <code>import "C"</code> declared.
{/param}
{/call}
{call cxx_common.headers_arg /}
{call cxx_common.preprocessor_flags_arg /}
{call cxx_common.platform_preprocessor_flags_arg /}
{call go_common.cgo_compiler_flags_arg /}
{call cxx_common.compiler_flags_arg /}
{call cxx_common.platform_compiler_flags_arg /}
{call cxx_common.linker_extra_outputs_arg /}
{call cxx_common.linker_flags_arg /}
{call cxx_common.platform_linker_flags_arg /}
{call native_common.link_style }
{param default: 'static_pic' /}
{/call}
{call cxx_common.raw_headers_arg /}
{call buck.arg}
{param name : 'go_compiler_flags' /}
{param default : '[]' /}
{param desc}
The set of additional compiler flags to pass to <code>go tool compile</code>.
{/param}
{/call}
{call buck.arg}
{param name : 'go_assembler_flags' /}
{param default : '[]' /}
{param desc}
The set of additional assembler flags to pass to <code>go tool asm</code>.
{/param}
{/call}
{/param} // close args
{param examples}
{literal}<pre class="prettyprint lang-py">
# A rule that builds a Go native executable with linked cgo library based on
# C/C++ util library.
go_binary(
name = "bin",
srcs = ["main.go"],
deps = [":lib"]
)
cgo_library(
name = "lib",
srcs = ["cgo_source.go"],
deps = [":util"],
)
cxx_library(
name = "util",
srcs = ["util.c"],
headers = ["util.h"],
)
</pre>{/literal}
{/param}
{/call} // close buck.rule
{/param}
{/call}
{/template}