├── tests ├── bcr │ ├── WORKSPACE │ ├── .bazelversion │ ├── other_module │ │ ├── WORKSPACE │ │ ├── bar.txt │ │ ├── BUILD.bazel │ │ └── MODULE.bazel │ ├── .bazelrc │ ├── lib.go │ ├── mockable_test.go │ ├── mockable.go │ ├── main.go │ ├── test.go │ ├── proto │ │ ├── foo_proto_test.go │ │ └── foo.proto │ └── runfiles │ │ └── BUILD.bazel ├── core │ ├── go_test │ │ ├── x │ │ ├── y │ │ ├── z │ │ ├── x_defs │ │ │ ├── foo.go │ │ │ ├── qux.go │ │ │ ├── baz.go │ │ │ ├── bar.go │ │ │ └── foo_test.go │ │ ├── indirect_import_lib.go │ │ ├── external_importmap_lib.go │ │ ├── same_package_test.go │ │ ├── tags_good_test.go │ │ ├── indirect_import_i_test.go │ │ ├── tags_bad_test.go │ │ ├── testmain_import_indirect_test.go │ │ ├── only_testmain_test.go │ │ ├── indirect_import_dep.go │ │ ├── testmain_import_main_test.go │ │ ├── external_importmap_dep.go │ │ ├── external_importmap_test.go │ │ ├── indirect_import_x_test.go │ │ ├── pwd_test.go │ │ ├── example_test.go │ │ ├── data_test_dep.go │ │ ├── data_test_embed.go │ │ ├── lib.go │ │ ├── wrapped_test.go │ │ ├── internal_test.go │ │ └── external_test.go │ ├── go_path │ │ ├── extra.txt │ │ ├── pkg │ │ │ └── lib │ │ │ │ ├── data.txt │ │ │ │ ├── testdata │ │ │ │ └── testdata.txt │ │ │ │ ├── embedded_src.txt │ │ │ │ ├── embed_test.go │ │ │ │ ├── internal_test.go │ │ │ │ ├── vendored.go │ │ │ │ ├── external_test.go │ │ │ │ ├── template │ │ │ │ └── index.html.tmpl │ │ │ │ ├── transitive.go │ │ │ │ └── lib.go │ │ ├── cmd │ │ │ └── bin │ │ │ │ ├── bin.go │ │ │ │ └── BUILD.bazel │ │ └── README.rst │ ├── go_library │ │ ├── inc_foo.s │ │ ├── embedsrcs_static │ │ │ ├── file │ │ │ ├── no │ │ │ ├── dir │ │ │ │ ├── _no │ │ │ │ └── f │ │ │ ├── glob │ │ │ │ ├── f │ │ │ │ └── _hidden │ │ │ └── contains_hidden │ │ │ │ ├── .hidden │ │ │ │ ├── .hidden_dir │ │ │ │ ├── .env │ │ │ │ └── visible_file │ │ │ │ ├── _hidden_dir │ │ │ │ ├── .bashrc │ │ │ │ ├── _hidden_file │ │ │ │ └── visible_file │ │ │ │ └── visible │ │ │ │ ├── visible_file │ │ │ │ └── .bzr │ │ │ │ └── file-under-version-control │ │ ├── inc.go │ │ ├── empty_baz.s │ │ ├── inc_asmhdr.s │ │ ├── inc_bar.s │ │ ├── empty_bar.go │ │ ├── empty_foo.go │ │ ├── empty_main.go │ │ ├── package_height_embedder.go │ │ ├── package_height_dep_shallow.go │ │ ├── package_height_dep_deep.go │ │ ├── package_height_embeddee.go │ │ ├── embedsrcs_simple_test.go │ │ ├── package_height.go │ │ ├── def.bzl │ │ ├── import_alias_b.go │ │ ├── import_alias_a_v2.go │ │ └── embedsrcs_gen_test.go.in │ ├── runfiles │ │ ├── local_file.txt │ │ ├── local_group.txt │ │ ├── runfiles_remote_test │ │ │ ├── remote_file.txt │ │ │ ├── remote_group.txt │ │ │ ├── WORKSPACE │ │ │ └── BUILD.bazel │ │ ├── empty_bin.go │ │ └── bin.go │ ├── output_groups │ │ ├── lib.go │ │ ├── lib_test.go │ │ ├── bin.go │ │ ├── README.rst │ │ └── BUILD.bazel │ ├── go_binary │ │ ├── tags_lib_good.go │ │ ├── prefix │ │ │ ├── prefix.go │ │ │ └── BUILD.bazel │ │ ├── custom_bin.go │ │ ├── stamp_embed.go │ │ ├── tags_lib_bad.go │ │ ├── tags_main_bad.go │ │ ├── stamp_dep.go │ │ ├── hello.go │ │ ├── static_pure_bin.go │ │ ├── tags_main_good.go │ │ ├── static_bin.go │ │ ├── static_cgo_bin.go │ │ ├── broken_cgo.go │ │ ├── out_test.go │ │ ├── stamp_bin.go │ │ ├── stamp_test.go │ │ └── pie_darwin_test.go │ ├── cgo │ │ ├── imported.c │ │ ├── objc │ │ │ ├── add_darwin.h │ │ │ ├── add_darwin.go │ │ │ ├── sub_darwin.go │ │ │ ├── README.rst │ │ │ ├── objc_darwin_test.go │ │ │ ├── sub.m │ │ │ ├── add_darwin.m │ │ │ └── BUILD.bazel │ │ ├── pure.go │ │ ├── tag_pure_err.c │ │ ├── native_dep.h │ │ ├── split_import_c.c │ │ ├── race_off.c │ │ ├── race_on.c │ │ ├── split_import_a.go │ │ ├── race_on.go │ │ ├── foo.c │ │ ├── race_off.go │ │ ├── bar.go │ │ ├── foo.go │ │ ├── tag_cgo_err.go │ │ ├── tag_pure_err.go │ │ ├── split_import_c.h │ │ ├── native_dep.c │ │ ├── use_c_symbol_through_go.c │ │ ├── tag_pure.go │ │ ├── bar.cc │ │ ├── dylib_client.go │ │ ├── add.h │ │ ├── tag_cgo.go │ │ ├── split_import_i_test.go │ │ ├── transitive_dep.go │ │ ├── use_external_symbol.go │ │ ├── split_import_cgo.go │ │ ├── direct_dep.go │ │ ├── dylib_test.go │ │ ├── split_import_b.go │ │ ├── adder.go │ │ ├── split_import_x_test.go │ │ ├── use_transitive_symbol.go │ │ ├── provide_external_symbol.go │ │ ├── add.m │ │ ├── add.mm │ │ ├── adder_test.go │ │ ├── add.c │ │ ├── add.cpp │ │ ├── cgo_link_dep.c │ │ ├── cgo_ref.go │ │ ├── tag_test.go │ │ ├── cgo_link_test.go │ │ └── cc_libs_common.go │ ├── c_linkmodes │ │ ├── add_sandwich.h │ │ ├── empty.go │ │ ├── skip.c │ │ ├── add_sandwich.c │ │ ├── add.go │ │ ├── crypto.go │ │ ├── add_sandwich.go │ │ ├── add_test_archive.c │ │ ├── add_test_shared.c │ │ ├── add_test_sandwich.c │ │ ├── crypto_test_dl.c │ │ ├── c-archive_empty_hdr_test.c │ │ ├── go_with_cgo_dep_caller.cc │ │ └── go_with_cgo_dep.go │ ├── cross │ │ ├── lib_linux.go │ │ ├── lib_darwin.go │ │ ├── lib_windows.go │ │ └── main.go │ ├── go_proto_library │ │ ├── extra.go │ │ ├── adjusted_c.proto │ │ ├── no_go_package.proto │ │ ├── adjusted_b.proto │ │ ├── proxy_a.proto │ │ ├── proxy_b.proto │ │ ├── protos_a.proto │ │ ├── protos_b.proto │ │ ├── foo.proto │ │ ├── adjusted_a.proto │ │ ├── bar.proto │ │ └── grpc.proto │ ├── starlark │ │ ├── packagedriver │ │ │ ├── fixtures │ │ │ │ ├── a │ │ │ │ │ ├── a.go │ │ │ │ │ └── BUILD.bazel │ │ │ │ ├── b │ │ │ │ │ ├── b.go │ │ │ │ │ └── BUILD.bazel │ │ │ │ └── c │ │ │ │ │ ├── c_test.go │ │ │ │ │ ├── c.go │ │ │ │ │ └── BUILD.bazel │ │ │ └── BUILD.bazel │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── nogo │ │ ├── BUILD.bazel │ │ ├── deps │ │ │ ├── BUILD.bazel │ │ │ └── README.rst │ │ ├── vet │ │ │ ├── BUILD.bazel │ │ │ └── README.rst │ │ ├── config │ │ │ ├── BUILD.bazel │ │ │ └── README.rst │ │ ├── custom │ │ │ ├── BUILD.bazel │ │ │ ├── flags │ │ │ │ ├── BUILD.bazel │ │ │ │ └── README.rst │ │ │ └── README.rst │ │ ├── generate │ │ │ ├── BUILD.bazel │ │ │ └── README.rst │ │ ├── generics │ │ │ ├── BUILD.bazel │ │ │ └── README.rst │ │ ├── coverage │ │ │ ├── BUILD.bazel │ │ │ └── README.rst │ │ └── README.rst │ ├── go_plugin │ │ ├── plugin.go │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── all_test.go │ ├── go_plugin_with_proto_library │ │ ├── validate.proto │ │ ├── plugin.go │ │ ├── README.rst │ │ ├── all_test.go │ │ └── BUILD.bazel │ ├── race │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── go_proto_library_importmap │ │ ├── foo.proto │ │ ├── README.rst │ │ ├── importmap_test.go │ │ └── BUILD.bazel │ ├── boringcrypto │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── build_stdlib │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── go_download_sdk │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── stdlib │ │ ├── BUILD.bazel │ │ ├── reproduce_test.sh │ │ └── README.rst │ ├── go_bazel_test │ │ ├── README.rst │ │ └── BUILD.bazel │ ├── transition │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── importmap │ │ ├── README.rst │ │ ├── lib.go │ │ └── import.go │ └── coverage │ │ └── README.rst ├── legacy │ ├── providers │ │ ├── test.go │ │ ├── test.sh │ │ ├── test.bzl │ │ └── BUILD.bazel │ ├── test_chdir │ │ ├── data.txt │ │ ├── BUILD.bazel │ │ ├── remote.bzl │ │ └── data_test.go │ ├── transitive_data │ │ ├── c_data.txt │ │ ├── cgo_data.txt │ │ ├── go_data.txt │ │ ├── empty.go │ │ ├── empty_cgo.go │ │ ├── transitive_data_test.go │ │ └── BUILD.bazel │ ├── cgo_pure │ │ ├── cgo.c │ │ ├── pure.go │ │ ├── cgo_no_tag.go │ │ ├── cgo.go │ │ ├── cgo_pure_test.go │ │ └── BUILD.bazel │ ├── cgo_sys_hdr │ │ ├── sub │ │ │ └── foo.h │ │ ├── foo.go │ │ ├── foo_test.go │ │ └── BUILD.bazel │ ├── asm_include │ │ ├── foo_amd64.h │ │ ├── foo_amd64.go │ │ ├── foo_amd64.s │ │ ├── foo_test.go │ │ └── foo_other.go │ ├── empty_package │ │ ├── cgo.c │ │ ├── mixed_pure.go │ │ ├── cgo.go │ │ ├── mixed_cgo.go │ │ └── empty_package_test.go │ ├── cgo_select │ │ ├── linux.c │ │ ├── darwin.c │ │ ├── windows.c │ │ ├── cgo_darwin.go │ │ ├── cgo_linux.go │ │ ├── cgo_windows.go │ │ └── cgo_select_test.go │ ├── examples │ │ ├── bindata │ │ │ ├── data │ │ │ │ └── message.txt │ │ │ └── BUILD.bazel │ │ ├── cgo │ │ │ ├── skip_go_library │ │ │ │ ├── types.go │ │ │ │ ├── cgo_foo.go │ │ │ │ └── BUILD.bazel │ │ │ ├── pure_go.go │ │ │ ├── cc_dependency │ │ │ │ ├── c_version.h │ │ │ │ ├── version.h │ │ │ │ ├── c_version.c │ │ │ │ └── BUILD.bazel │ │ │ ├── export_example.go │ │ │ ├── use_exported.c │ │ │ ├── use_exported.h │ │ │ ├── example_command │ │ │ │ ├── main.go │ │ │ │ ├── generate_test.bzl │ │ │ │ └── BUILD.bazel │ │ │ ├── generated.go.tpl │ │ │ ├── sub │ │ │ │ └── floor.go │ │ │ ├── cgo_lib_test.go │ │ │ └── import_example.go │ │ ├── lib │ │ │ ├── deep │ │ │ │ ├── thought.go │ │ │ │ ├── doc.go │ │ │ │ └── BUILD.bazel │ │ │ ├── add_amd64.s │ │ │ ├── sub_amd64.s │ │ │ ├── asm.go │ │ │ ├── add_arm64.s │ │ │ ├── sub_arm64.s │ │ │ └── lib_test.go │ │ ├── proto │ │ │ ├── embed │ │ │ │ ├── embed.go │ │ │ │ └── embed.proto │ │ │ ├── dep │ │ │ │ ├── useful.proto │ │ │ │ └── BUILD.bazel │ │ │ ├── gostyle │ │ │ │ ├── gostyle.proto │ │ │ │ └── BUILD.bazel │ │ │ ├── lib │ │ │ │ ├── lib.proto │ │ │ │ ├── lib2.proto │ │ │ │ └── BUILD.bazel │ │ │ ├── gogo │ │ │ │ ├── values.proto │ │ │ │ ├── gogo_test.go │ │ │ │ └── BUILD.bazel │ │ │ ├── gs.go │ │ │ └── grpc │ │ │ │ └── my_svc.proto │ │ ├── stamped_bin │ │ │ └── BUILD.bazel │ │ ├── external │ │ │ └── BUILD.bazel │ │ ├── monobuild │ │ │ ├── lib1 │ │ │ │ ├── BUILD.bazel │ │ │ │ └── lib1.go │ │ │ ├── lib2 │ │ │ │ ├── BUILD.bazel │ │ │ │ └── lib2.go │ │ │ └── cmd │ │ │ │ ├── BUILD.bazel │ │ │ │ └── mycmd.go │ │ ├── vendor │ │ │ └── github.com │ │ │ │ └── user │ │ │ │ └── vendored │ │ │ │ ├── BUILD.bazel │ │ │ │ └── vendored.go │ │ └── bin │ │ │ └── BUILD.bazel │ ├── binary_test_outputs │ │ ├── test.go │ │ ├── bin.go │ │ └── BUILD.bazel │ ├── visibility │ │ ├── foo.go │ │ └── BUILD.bazel │ ├── build_constraints │ │ ├── cgo_linux.c │ │ ├── cgo_group_linux.c │ │ ├── asm_linux_amd64.s │ │ ├── cgo_unknown.c │ │ ├── suffix_linux.go │ │ ├── cgo_group_unknown.c │ │ ├── tag_l.go │ │ ├── asm_unknown.s │ │ ├── tag_unknown.go │ │ ├── suffix_unknown.go │ │ ├── cgo_linux.go │ │ ├── cgo_unknown.go │ │ └── asm_arm64.s │ ├── cgo_trans_deps │ │ ├── dep │ │ │ ├── dep.go │ │ │ └── BUILD.bazel │ │ ├── cgo_lib.go │ │ ├── cgo_test.go │ │ └── BUILD.bazel │ ├── extldflags_rpath │ │ ├── main.go │ │ ├── BUILD.bazel │ │ ├── extldflags_rpath_test.sh │ │ └── README.md │ ├── cgo_filtered │ │ ├── pure.go │ │ ├── pure_test.go │ │ └── BUILD.bazel │ ├── package_named_build │ │ └── build │ │ │ ├── build.go │ │ │ ├── build_test.go │ │ │ └── BUILD.bazel │ ├── slash_names │ │ ├── a │ │ │ └── pkg │ │ │ │ └── pkg.go │ │ ├── b │ │ │ └── pkg │ │ │ │ └── pkg.go │ │ ├── slash_test.go │ │ └── BUILD.bazel │ ├── cgo_multi_dir │ │ ├── bar │ │ │ └── bar.go │ │ ├── foo │ │ │ └── foo.go │ │ ├── cgo_multi_dir_test.go │ │ └── BUILD.bazel │ ├── cgo_opts │ │ ├── cgo_opts.go │ │ ├── cgo_opts_test.go │ │ └── BUILD.bazel │ ├── info │ │ ├── BUILD.bazel │ │ └── info_test.sh │ ├── no_prefix │ │ └── BUILD.bazel │ ├── test_rundir │ │ ├── rundir_test.go │ │ └── BUILD.bazel │ ├── test_build_constraints │ │ ├── baz_linux_test.go │ │ ├── foo_linux_test.go │ │ ├── bar_l_test.go │ │ ├── bar_unknown_test.go │ │ ├── baz_unknown_test.go │ │ ├── foo_unknown_test.go │ │ └── BUILD.bazel │ ├── README.rst │ ├── cgo_pthread_flag │ │ ├── cgo_pthread_flag_test.go │ │ ├── BUILD.bazel │ │ └── cgo_pthread_flag.go │ └── proto_ignore_go_package_option │ │ ├── a.proto │ │ └── b.proto ├── runfiles │ └── test.txt ├── extras │ ├── go_embed_data │ │ ├── error.c │ │ └── README.rst │ └── gomock │ │ ├── client_test.go │ │ ├── client.go │ │ └── BUILD.bazel ├── integration │ ├── go_bin_runner │ │ └── BUILD.bazel │ ├── reproducibility │ │ ├── BUILD.bazel │ │ └── README.rst │ ├── gazelle │ │ ├── README.rst │ │ └── BUILD.bazel │ ├── googleapis │ │ └── README.rst │ └── README.rst ├── BUILD.bazel └── examples │ ├── executable_name │ ├── name_test.sh │ ├── BUILD.bazel │ ├── README.rst │ └── main.go │ └── README.rst ├── go ├── tools │ ├── bazel │ │ ├── empty.txt │ │ └── BUILD.bazel │ ├── bzltestutil │ │ └── testdata │ │ │ ├── empty.json │ │ │ └── empty.xml │ ├── bazel_benchmark │ │ ├── BUILD.bazel.in │ │ ├── hello.go.in │ │ ├── BUILD.bazel │ │ └── WORKSPACE.in │ ├── builders │ │ ├── path.go │ │ ├── path_windows.go │ │ ├── nogo_typeparams_go117.go │ │ └── nogo_typeparams_go118.go │ ├── gazelle │ │ └── README.rst │ ├── go_bin_runner │ │ ├── process_unix.go │ │ └── process.go │ ├── BUILD.bazel │ ├── coverdata │ │ └── BUILD.bazel │ ├── internal │ │ └── txtar │ │ │ └── BUILD.bazel │ ├── gopackagesdriver │ │ └── BUILD.bazel │ ├── fetch_repo │ │ └── BUILD.bazel │ └── bazel_testing │ │ └── BUILD.bazel ├── nogo_logo.png ├── extensions.bzl ├── extras.rst ├── private │ ├── BUILD.nogo.bazel │ ├── skylib │ │ ├── README.rst │ │ └── lib │ │ │ └── BUILD.bazel │ └── tools │ │ └── BUILD.bazel └── toolchain │ └── BUILD.bazel ├── CODEOWNERS ├── .bazelignore ├── .bcr ├── config.yml ├── source.template.json ├── metadata.template.json └── presubmit.yml ├── examples └── basic-gazelle │ ├── .gitignore │ ├── README.md │ ├── CONTRIBUTING.md │ ├── go.mod │ ├── cmd │ └── BUILD.bazel │ ├── pkg │ └── roll │ │ ├── BUILD.bazel │ │ └── roll_dice_test.go │ └── main.go ├── .gitignore ├── tools └── gopackagesdriver.sh ├── third_party ├── BUILD.bazel ├── README.txt └── go_googleapis-directives.patch ├── .vscode └── extensions.json ├── docs ├── go │ ├── extras │ │ └── BUILD.bazel │ └── core │ │ └── BUILD.bazel └── BUILD.bazel ├── extras └── gomock │ └── BUILD.bazel ├── go.mod └── AUTHORS /tests/bcr/WORKSPACE: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_test/x: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_test/y: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_test/z: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go/tools/bazel/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_path/extra.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @go-maintainers 2 | -------------------------------------------------------------------------------- /tests/bcr/.bazelversion: -------------------------------------------------------------------------------- 1 | 6.0.0 2 | -------------------------------------------------------------------------------- /tests/bcr/other_module/WORKSPACE: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/inc_foo.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/legacy/providers/test.go: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/legacy/test_chdir/data.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/runfiles/test.txt: -------------------------------------------------------------------------------- 1 | hi! 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/data.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/runfiles/local_file.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/runfiles/local_group.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | tests/bcr 2 | examples 3 | -------------------------------------------------------------------------------- /tests/bcr/other_module/bar.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/no: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/c_data.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/cgo_data.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/go_data.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/bcr/.bazelrc: -------------------------------------------------------------------------------- 1 | common --enable_bzlmod 2 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/dir/_no: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/dir/f: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/glob/f: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/inc.go: -------------------------------------------------------------------------------- 1 | package inc 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/testdata/testdata.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/foo.go: -------------------------------------------------------------------------------- 1 | package foo 2 | -------------------------------------------------------------------------------- /tests/core/output_groups/lib.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/go_binary/tags_lib_good.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/glob/_hidden: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/embedded_src.txt: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/core/output_groups/lib_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/cgo.c: -------------------------------------------------------------------------------- 1 | const int value = 2; 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_sys_hdr/sub/foo.h: -------------------------------------------------------------------------------- 1 | int x = 42; 2 | -------------------------------------------------------------------------------- /go/tools/bzltestutil/testdata/empty.json: -------------------------------------------------------------------------------- 1 | {"Action":"fail"} -------------------------------------------------------------------------------- /tests/core/cgo/imported.c: -------------------------------------------------------------------------------- 1 | int foo() { return 42; } 2 | -------------------------------------------------------------------------------- /tests/core/go_library/empty_baz.s: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | -------------------------------------------------------------------------------- /tests/core/go_library/inc_asmhdr.s: -------------------------------------------------------------------------------- 1 | #include "go_asm.h" 2 | -------------------------------------------------------------------------------- /tests/core/go_library/inc_bar.s: -------------------------------------------------------------------------------- 1 | #include "inc_foo.s" 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/embed_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/remote_file.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/remote_group.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/legacy/asm_include/foo_amd64.h: -------------------------------------------------------------------------------- 1 | #define FOOVAL 42 2 | -------------------------------------------------------------------------------- /tests/legacy/empty_package/cgo.c: -------------------------------------------------------------------------------- 1 | const int value = 2; 2 | -------------------------------------------------------------------------------- /tests/legacy/providers/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exit 0 -------------------------------------------------------------------------------- /tests/legacy/transitive_data/empty.go: -------------------------------------------------------------------------------- 1 | package go_lib 2 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/add_darwin.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | -------------------------------------------------------------------------------- /tests/core/cgo/pure.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_pure_err.c: -------------------------------------------------------------------------------- 1 | #error should not be compiled 2 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/.hidden: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/internal_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/vendored.go: -------------------------------------------------------------------------------- 1 | package vendored 2 | -------------------------------------------------------------------------------- /tests/extras/go_embed_data/error.c: -------------------------------------------------------------------------------- 1 | #error do not compile 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/linux.c: -------------------------------------------------------------------------------- 1 | const char* goos = "linux"; 2 | -------------------------------------------------------------------------------- /tests/bcr/other_module/BUILD.bazel: -------------------------------------------------------------------------------- 1 | exports_files(["bar.txt"]) 2 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add_sandwich.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | -------------------------------------------------------------------------------- /tests/core/cgo/native_dep.h: -------------------------------------------------------------------------------- 1 | extern void native_greeting(void); 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/external_test.go: -------------------------------------------------------------------------------- 1 | package lib_test 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/darwin.c: -------------------------------------------------------------------------------- 1 | const char* goos = "darwin"; 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/windows.c: -------------------------------------------------------------------------------- 1 | const char* goos = "windows"; 2 | -------------------------------------------------------------------------------- /tests/legacy/examples/bindata/data/message.txt: -------------------------------------------------------------------------------- 1 | Some embedded data -------------------------------------------------------------------------------- /tests/core/c_linkmodes/empty.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/skip.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_c.c: -------------------------------------------------------------------------------- 1 | int half(int x) { return x/2; } 2 | 3 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/template/index.html.tmpl: -------------------------------------------------------------------------------- 1 | {{ .Content }} 2 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/qux.go: -------------------------------------------------------------------------------- 1 | package qux 2 | 3 | var Qux string 4 | -------------------------------------------------------------------------------- /tests/core/output_groups/bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/runfiles/empty_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/legacy/binary_test_outputs/test.go: -------------------------------------------------------------------------------- 1 | package binary_test_outputs 2 | -------------------------------------------------------------------------------- /tests/legacy/visibility/foo.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | const Foo = 1 4 | -------------------------------------------------------------------------------- /tests/core/cgo/race_off.c: -------------------------------------------------------------------------------- 1 | // +build !race 2 | 3 | int race_enabled = 0; 4 | -------------------------------------------------------------------------------- /tests/core/cgo/race_on.c: -------------------------------------------------------------------------------- 1 | // +build race 2 | 3 | int race_enabled = 1; 4 | -------------------------------------------------------------------------------- /tests/core/go_binary/prefix/prefix.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/empty_bar.go: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | 3 | package bar 4 | -------------------------------------------------------------------------------- /tests/core/go_library/empty_foo.go: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | 3 | package foo 4 | -------------------------------------------------------------------------------- /tests/core/go_library/empty_main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_linux.c: -------------------------------------------------------------------------------- 1 | const char* cgoC = "linux"; 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_trans_deps/dep/dep.go: -------------------------------------------------------------------------------- 1 | package dep 2 | 3 | var X = 42 4 | -------------------------------------------------------------------------------- /tests/legacy/extldflags_rpath/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/go_binary/custom_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_path/cmd/bin/bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /tests/legacy/asm_include/foo_amd64.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | func foo() int32 4 | -------------------------------------------------------------------------------- /tests/legacy/binary_test_outputs/bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func Main() {} 4 | -------------------------------------------------------------------------------- /tests/legacy/cgo_filtered/pure.go: -------------------------------------------------------------------------------- 1 | package cgo_filtered 2 | 3 | var Value = 42 4 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/empty_cgo.go: -------------------------------------------------------------------------------- 1 | package go_lib 2 | 3 | import "C" 4 | -------------------------------------------------------------------------------- /.bcr/config.yml: -------------------------------------------------------------------------------- 1 | fixedReleaser: 2 | login: fmeum 3 | email: fabian@meumertzhe.im 4 | -------------------------------------------------------------------------------- /go/nogo_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replit/rules_go/master/go/nogo_logo.png -------------------------------------------------------------------------------- /tests/core/cgo/split_import_a.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | func Answer() int { return 42 } 4 | -------------------------------------------------------------------------------- /tests/core/cross/lib_linux.go: -------------------------------------------------------------------------------- 1 | package platform_lib 2 | 3 | const Platform = "linux" 4 | -------------------------------------------------------------------------------- /tests/core/go_binary/stamp_embed.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var Embed = "redacted" 4 | -------------------------------------------------------------------------------- /tests/core/go_library/package_height_embedder.go: -------------------------------------------------------------------------------- 1 | package embed 2 | 3 | var X = T{} 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_group_linux.c: -------------------------------------------------------------------------------- 1 | const char* cgoCGroup = "linux"; 2 | -------------------------------------------------------------------------------- /tests/bcr/lib.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | func Name() string { 4 | return "bzlmod" 5 | } 6 | -------------------------------------------------------------------------------- /tests/bcr/mockable_test.go: -------------------------------------------------------------------------------- 1 | package mockable 2 | 3 | var _ Client = (*MockClient)(nil) 4 | -------------------------------------------------------------------------------- /tests/core/cross/lib_darwin.go: -------------------------------------------------------------------------------- 1 | package platform_lib 2 | 3 | const Platform = "darwin" 4 | -------------------------------------------------------------------------------- /tests/core/cross/lib_windows.go: -------------------------------------------------------------------------------- 1 | package platform_lib 2 | 3 | const Platform = "windows" 4 | -------------------------------------------------------------------------------- /tests/core/go_library/package_height_dep_shallow.go: -------------------------------------------------------------------------------- 1 | package dep 2 | 3 | type T struct{} 4 | -------------------------------------------------------------------------------- /tests/legacy/package_named_build/build/build.go: -------------------------------------------------------------------------------- 1 | package build 2 | 3 | const Foo = 42 4 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/transitive.go: -------------------------------------------------------------------------------- 1 | package transitive 2 | 3 | var ( 4 | _ = "" 5 | ) 6 | -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "runfiles_remote_test") 2 | -------------------------------------------------------------------------------- /tests/extras/gomock/client_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | var _ Client = (*MockClient)(nil) 4 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/pure.go: -------------------------------------------------------------------------------- 1 | //+build !cgo 2 | 3 | package cgo_pure 4 | 5 | var Value = 1 6 | -------------------------------------------------------------------------------- /go/extensions.bzl: -------------------------------------------------------------------------------- 1 | load("//go/private:extensions.bzl", _go_sdk = "go_sdk") 2 | 3 | go_sdk = _go_sdk 4 | -------------------------------------------------------------------------------- /tests/core/cgo/race_on.go: -------------------------------------------------------------------------------- 1 | // +build race 2 | 3 | package race 4 | 5 | const goRaceEnabled = true 6 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/extra.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | func Extra() int { 4 | return 42 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/go_test/indirect_import_lib.go: -------------------------------------------------------------------------------- 1 | package indirect_import 2 | 3 | var X string = "not set" 4 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/a/a.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | func A() { 4 | return 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/b/b.go: -------------------------------------------------------------------------------- 1 | package b 2 | 3 | func B() { 4 | return 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/cgo/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo() { 4 | printf("foo\n"); 5 | } 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/core/cgo/race_off.go: -------------------------------------------------------------------------------- 1 | // +build !race 2 | 3 | package race 4 | 5 | const goRaceEnabled = false 6 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/asm_linux_amd64.s: -------------------------------------------------------------------------------- 1 | TEXT ·asm(SB),$0-0 2 | MOVQ $12,RET(FP) 3 | RET 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_unknown.c: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | const char* cgoC = "unknown"; 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/suffix_linux.go: -------------------------------------------------------------------------------- 1 | package build_constraints 2 | 3 | var suffix = "linux" 4 | -------------------------------------------------------------------------------- /tests/legacy/empty_package/mixed_pure.go: -------------------------------------------------------------------------------- 1 | //+build !cgo 2 | 3 | package mixed 4 | 5 | var Value = 1 6 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/skip_go_library/types.go: -------------------------------------------------------------------------------- 1 | package skip_go_library 2 | 3 | type Type struct{} 4 | -------------------------------------------------------------------------------- /tests/legacy/slash_names/a/pkg/pkg.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | func Name() string { 4 | return "A" 5 | } 6 | -------------------------------------------------------------------------------- /tests/legacy/slash_names/b/pkg/pkg.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | func Name() string { 4 | return "B" 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/go_binary/tags_lib_bad.go: -------------------------------------------------------------------------------- 1 | // +build !good 2 | 3 | package lib 4 | 5 | var Does Not = Compile 6 | -------------------------------------------------------------------------------- /tests/core/go_binary/tags_main_bad.go: -------------------------------------------------------------------------------- 1 | // +build !good 2 | 3 | package main 4 | 5 | var Does Not = Compile 6 | -------------------------------------------------------------------------------- /tests/core/starlark/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":common_tests.bzl", "common_test_suite") 2 | 3 | common_test_suite() 4 | -------------------------------------------------------------------------------- /go/extras.rst: -------------------------------------------------------------------------------- 1 | .. _extras.md: /docs/go/extras/extras.md 2 | 3 | This file has moved, please find it at extras.md_. 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_group_unknown.c: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | const char* cgoCGroup = "unknown"; 4 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/pure_go.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | func PrintCXXVersion() { 4 | printCXXVersion() 5 | } 6 | -------------------------------------------------------------------------------- /tests/bcr/other_module/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module(name = "other_module") 2 | 3 | bazel_dep(name = "rules_go", version = "") 4 | -------------------------------------------------------------------------------- /tests/core/cgo/bar.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // void bar(); 4 | import "C" 5 | 6 | func main() { 7 | C.bar() 8 | } 9 | -------------------------------------------------------------------------------- /tests/core/cgo/foo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // void foo(); 4 | import "C" 5 | 6 | func main() { 7 | C.foo() 8 | } 9 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_cgo_err.go: -------------------------------------------------------------------------------- 1 | // +build !cgo 2 | 3 | package main 4 | 5 | // this file should not be compiled 6 | !!! 7 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_pure_err.go: -------------------------------------------------------------------------------- 1 | // +build cgo 2 | 3 | package main 4 | 5 | // this file should not be compiled 6 | !!! 7 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/tag_l.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package build_constraints 4 | 5 | var tag = "linux" 6 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add_sandwich.c: -------------------------------------------------------------------------------- 1 | #include "add_sandwich.h" 2 | 3 | int add(int a, int b) { 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_c.h: -------------------------------------------------------------------------------- 1 | #ifndef split_import_c 2 | #define split_import_c 3 | 4 | int half(int); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /tests/core/go_binary/stamp_dep.go: -------------------------------------------------------------------------------- 1 | package stamp_dep 2 | 3 | var ( 4 | DepSelf = "redacted" 5 | DepBin = "redacted" 6 | ) 7 | -------------------------------------------------------------------------------- /tests/legacy/asm_include/foo_amd64.s: -------------------------------------------------------------------------------- 1 | #include "foo_amd64.h" 2 | 3 | TEXT ·foo(SB),$0-0 4 | MOVQ $FOOVAL,RET(FP) 5 | RET 6 | -------------------------------------------------------------------------------- /tests/core/cgo/native_dep.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void native_greeting(void) { 4 | printf("Hello, world!\n"); 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/go_binary/hello.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hello, world!") 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_binary/static_pure_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "net" 5 | _ "os" 6 | ) 7 | 8 | func main() {} 9 | -------------------------------------------------------------------------------- /tests/core/go_library/package_height_dep_deep.go: -------------------------------------------------------------------------------- 1 | package dep 2 | 3 | import "os" 4 | 5 | type T struct { 6 | F *os.File 7 | } 8 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/asm_unknown.s: -------------------------------------------------------------------------------- 1 | // +build !linux,amd64 2 | 3 | TEXT ·asm(SB),$0-0 4 | MOVQ $34,RET(FP) 5 | RET 6 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/tag_unknown.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package build_constraints 4 | 5 | var tag = "unknown" 6 | -------------------------------------------------------------------------------- /tests/core/go_binary/tags_main_good.go: -------------------------------------------------------------------------------- 1 | // +build good 2 | 3 | package main 4 | 5 | import _ "tags_lib" 6 | 7 | func main() { 8 | } 9 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/suffix_unknown.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package build_constraints 4 | 5 | var suffix = "unknown" 6 | -------------------------------------------------------------------------------- /tests/legacy/cgo_multi_dir/bar/bar.go: -------------------------------------------------------------------------------- 1 | package cgo_multi_dir 2 | 3 | // int bar = 34; 4 | import "C" 5 | 6 | var bar = int(C.bar) 7 | -------------------------------------------------------------------------------- /tests/legacy/cgo_multi_dir/foo/foo.go: -------------------------------------------------------------------------------- 1 | package cgo_multi_dir 2 | 3 | // int foo = 12; 4 | import "C" 5 | 6 | var foo = int(C.foo) 7 | -------------------------------------------------------------------------------- /tests/bcr/mockable.go: -------------------------------------------------------------------------------- 1 | package mockable 2 | 3 | import "net/url" 4 | 5 | type Client interface { 6 | Connect(addr string) url.URL 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/adjusted_c.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package adjusted.c; 4 | 5 | message C { 6 | int64 c = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_test/external_importmap_lib.go: -------------------------------------------------------------------------------- 1 | package external_importmap 2 | 3 | type Object interface { 4 | DeepCopyObject() Object 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/go_test/same_package_test.go: -------------------------------------------------------------------------------- 1 | package same_package 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func OkTest(t *testing.T) {} 8 | -------------------------------------------------------------------------------- /tests/legacy/cgo_sys_hdr/foo.go: -------------------------------------------------------------------------------- 1 | package cgo_sys_hdr 2 | 3 | /* 4 | #include 5 | */ 6 | import "C" 7 | 8 | var x = int(C.x) 9 | -------------------------------------------------------------------------------- /tests/core/cgo/use_c_symbol_through_go.c: -------------------------------------------------------------------------------- 1 | #include "tests/core/cgo/use_transitive_symbol.h" 2 | 3 | int main() { 4 | PrintGreeting(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/go_library/package_height_embeddee.go: -------------------------------------------------------------------------------- 1 | package embed 2 | 3 | import "package_height/dep" 4 | 5 | type T struct { 6 | F dep.T 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/no_go_package.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package protopkg; 4 | 5 | message Foo { 6 | int64 x = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_test/tags_good_test.go: -------------------------------------------------------------------------------- 1 | // +build good 2 | 3 | package tags_test 4 | 5 | import "testing" 6 | 7 | func Test(t *testing.T) {} 8 | -------------------------------------------------------------------------------- /tests/legacy/empty_package/cgo.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | /* 4 | extern const int value; 5 | */ 6 | import "C" 7 | 8 | var Value = int(C.value) 9 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/deep/thought.go: -------------------------------------------------------------------------------- 1 | package deep 2 | 3 | // Thought emulates Deep Thought. 4 | func Thought() int { 5 | return 42 6 | } 7 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_pure.go: -------------------------------------------------------------------------------- 1 | // +build !cgo 2 | 3 | package main 4 | 5 | import "fmt" 6 | 7 | func main() { 8 | fmt.Println("pure") 9 | } 10 | -------------------------------------------------------------------------------- /examples/basic-gazelle/.gitignore: -------------------------------------------------------------------------------- 1 | # We added this file as part of the tutorial 2 | /bazel-basic-gazelle 3 | /bazel-bin 4 | /bazel-out 5 | /bazel-testlogs 6 | -------------------------------------------------------------------------------- /go/tools/bazel_benchmark/BUILD.bazel.in: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_binary") 2 | 3 | go_binary( 4 | name = "hello", 5 | srcs = ["hello.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /go/tools/builders/path.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package main 4 | 5 | func processPath(path string) (string, error) { 6 | return path, nil 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/cgo/bar.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" { 4 | 5 | void bar() { 6 | std::cout << "bar" << std::endl; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/nogo/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "rules_go_deps", 3 | srcs = [":common.bzl"], 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/cc_dependency/c_version.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" void PrintCVersion(); 3 | #else 4 | void PrintCVersion(); 5 | #endif 6 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/embed/embed.go: -------------------------------------------------------------------------------- 1 | package embed 2 | 3 | func OtherThing() *EmbedExample { 4 | return &EmbedExample{ 5 | A: 42, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /go/private/BUILD.nogo.bazel: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | alias( 4 | name = "nogo", 5 | actual = "{{nogo}}", 6 | ) 7 | -------------------------------------------------------------------------------- /go/tools/gazelle/README.rst: -------------------------------------------------------------------------------- 1 | Gazelle has moved to a new repository: 2 | `github.com/bazelbuild/bazel-gazelle `_ 3 | -------------------------------------------------------------------------------- /tests/core/go_plugin/plugin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const HelloWorld = "Hello, world!" 4 | 5 | func Hi() string { return HelloWorld } 6 | 7 | func main() {} 8 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/cgo_no_tag.go: -------------------------------------------------------------------------------- 1 | package cgo_pure 2 | 3 | /* 4 | extern const int value; 5 | */ 6 | import "C" 7 | 8 | var AnotherValue = int(C.value) 9 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/cgo_darwin.go: -------------------------------------------------------------------------------- 1 | package cgo_select 2 | 3 | /* 4 | extern const char* goos; 5 | */ 6 | import "C" 7 | 8 | var goos = C.GoString(C.goos) 9 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/cgo_linux.go: -------------------------------------------------------------------------------- 1 | package cgo_select 2 | 3 | /* 4 | extern const char* goos; 5 | */ 6 | import "C" 7 | 8 | var goos = C.GoString(C.goos) 9 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/cgo_windows.go: -------------------------------------------------------------------------------- 1 | package cgo_select 2 | 3 | /* 4 | extern const char* goos; 5 | */ 6 | import "C" 7 | 8 | var goos = C.GoString(C.goos) 9 | -------------------------------------------------------------------------------- /tests/legacy/cgo_trans_deps/cgo_lib.go: -------------------------------------------------------------------------------- 1 | package cgo_trans_deps 2 | 3 | import "C" 4 | 5 | import _ "github.com/bazelbuild/rules_go/tests/cgo_trans_deps/dep" 6 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/skip_go_library/cgo_foo.go: -------------------------------------------------------------------------------- 1 | package skip_go_library 2 | 3 | /* 4 | #include 5 | */ 6 | import "C" 7 | 8 | var _ = Type{} 9 | -------------------------------------------------------------------------------- /go/tools/bazel_benchmark/hello.go.in: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const incr = "INCR" 6 | 7 | func main() { 8 | fmt.Println(incr) 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_simple_test.go: -------------------------------------------------------------------------------- 1 | package embedsrcs_simple_test 2 | 3 | import _ "embed" 4 | 5 | //go:embed embedsrcs_static/no 6 | var no []byte 7 | -------------------------------------------------------------------------------- /tests/core/go_library/package_height.go: -------------------------------------------------------------------------------- 1 | package height 2 | 3 | import "package_height/embed" 4 | import "package_height/dep" 5 | 6 | var X = embed.T{F: dep.T{}} 7 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/c/c_test.go: -------------------------------------------------------------------------------- 1 | package c 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestC(t *testing.T) { 8 | C() 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bazel-* 2 | /tests/core/cgo/libimported.* 3 | /tests/core/cgo/libversioned.* 4 | /tests/bcr/bazel-* 5 | /examples/*/bazel-* 6 | /.ijwb/ 7 | /tests/bcr/.ijwb/ 8 | -------------------------------------------------------------------------------- /go/tools/bzltestutil/testdata/empty.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/core/cgo/dylib_client.go: -------------------------------------------------------------------------------- 1 | package dylib 2 | 3 | /* 4 | extern int foo(); 5 | */ 6 | import "C" 7 | 8 | func Foo() int { 9 | return int(C.foo()) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/go_plugin_with_proto_library/validate.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | package validate; 3 | 4 | message MessageRules { 5 | required string name = 1; 6 | } 7 | -------------------------------------------------------------------------------- /tests/core/go_test/indirect_import_i_test.go: -------------------------------------------------------------------------------- 1 | package indirect_import 2 | 3 | import "testing" 4 | 5 | func TestMain(m *testing.M) { 6 | X = "set by TestMain" 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_test/tags_bad_test.go: -------------------------------------------------------------------------------- 1 | // +build !good 2 | 3 | package tags_test 4 | 5 | import "testing" 6 | 7 | func Test(t *testing.T) { 8 | t.Fail() 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/baz.go: -------------------------------------------------------------------------------- 1 | package baz 2 | 3 | import "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/qux" 4 | 5 | var Baz string 6 | var Qux = qux.Qux 7 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.zip" 5 | } 6 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/cgo.go: -------------------------------------------------------------------------------- 1 | //+build cgo 2 | 3 | package cgo_pure 4 | 5 | /* 6 | extern const int value; 7 | */ 8 | import "C" 9 | 10 | var Value = int(C.value) 11 | -------------------------------------------------------------------------------- /tests/bcr/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "example.com/lib" 7 | ) 8 | 9 | func main() { 10 | fmt.Printf("Hello %s!", lib.Name()) 11 | } 12 | -------------------------------------------------------------------------------- /tests/bcr/test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestName(t *testing.T) { 8 | if Name() != "bzlmod" { 9 | t.Fail() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/core/go_binary/static_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "golang.org/x/sys/unix" // See https://github.com/bazelbuild/rules_go/issues/2168 5 | ) 6 | 7 | func main() {} 8 | -------------------------------------------------------------------------------- /tests/core/go_test/testmain_import_indirect_test.go: -------------------------------------------------------------------------------- 1 | package test_main_test 2 | 3 | import "example.com/imports/test_main" 4 | 5 | func init() { 6 | test_main.Updated = true 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":go_pkg_info_aspect_test.bzl", "package_driver_suite") 2 | 3 | package_driver_suite( 4 | name = "package_driver_test", 5 | ) 6 | -------------------------------------------------------------------------------- /tests/legacy/cgo_opts/cgo_opts.go: -------------------------------------------------------------------------------- 1 | package cgo_opts 2 | 3 | /* 4 | #cgo CFLAGS: -DFOO=1 -DBAR=2 -g -O2 5 | int x = FOO + BAR; 6 | */ 7 | import "C" 8 | 9 | var x = int(C.x) 10 | -------------------------------------------------------------------------------- /tools/gopackagesdriver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export GOPACKAGESDRIVER_RULES_GO_REPOSITORY_NAME= 3 | exec bazel run --tool_tag=gopackagesdriver -- //go/tools/gopackagesdriver "${@}" 4 | -------------------------------------------------------------------------------- /tests/core/cgo/add.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | int add_c(int a, int b); 6 | int add_cpp(int a, int b); 7 | 8 | #ifdef __cplusplus 9 | } 10 | #endif 11 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_cgo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // const char *msg = "cgo"; 4 | import "C" 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | fmt.Println(C.GoString(C.msg)) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/go_test/only_testmain_test.go: -------------------------------------------------------------------------------- 1 | package only_testmain 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func TestMain(m *testing.M) { 9 | os.Exit(m.Run()) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/c/c.go: -------------------------------------------------------------------------------- 1 | package c 2 | 3 | import ( 4 | "example.com/a" 5 | "example.com/b" 6 | ) 7 | 8 | func C() { 9 | a.A() 10 | b.B() 11 | } 12 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/add_amd64.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·add(SB),NOSPLIT,$0 4 | MOVQ x+0(FP), BX 5 | MOVQ y+8(FP), BP 6 | ADDQ BP, BX 7 | MOVQ BX, ret+16(FP) 8 | RET 9 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/sub_amd64.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·sub(SB),NOSPLIT,$0 4 | MOVQ x+0(FP), BX 5 | MOVQ y+8(FP), BP 6 | SUBQ BP, BX 7 | MOVQ BX, ret+16(FP) 8 | RET 9 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_i_test.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | import "testing" 4 | 5 | func TestInternal(t *testing.T) { 6 | if Answer() != 42 { 7 | t.Error("wrong answer") 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/race/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "race_test", 5 | srcs = ["race_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/deps/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "deps_test", 5 | srcs = ["deps_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/vet/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "vet_test", 5 | srcs = ["vet_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/legacy/cgo_opts/cgo_opts_test.go: -------------------------------------------------------------------------------- 1 | package cgo_opts 2 | 3 | import "testing" 4 | 5 | func TestCOpts(t *testing.T) { 6 | if x != 3 { 7 | t.Errorf("got %d; want 3", x) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/adjusted_b.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "adjusted/adjusted_c.proto"; 4 | 5 | package adjusted.b; 6 | 7 | message B { 8 | adjusted.c.C b = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/proxy_a.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/proxy"; 4 | 5 | message A { 6 | int64 a = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/proxy_b.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/proxy"; 4 | 5 | message B { 6 | int64 b = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_proto_library_importmap/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library_importmap;foo"; 4 | 5 | message Foo { 6 | }; 7 | -------------------------------------------------------------------------------- /tests/legacy/cgo_sys_hdr/foo_test.go: -------------------------------------------------------------------------------- 1 | package cgo_sys_hdr 2 | 3 | import "testing" 4 | 5 | func TestFoo(t *testing.T) { 6 | if x != 42 { 7 | t.Errorf("got %d; want %d", x, 42) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/deep/doc.go: -------------------------------------------------------------------------------- 1 | // Package deep provides an emulator of a computer which calculates 2 | // answer to the ultimate question of Life, the Universe, and Everything. 3 | package deep 4 | -------------------------------------------------------------------------------- /examples/basic-gazelle/README.md: -------------------------------------------------------------------------------- 1 | # Go Rules Tutorial 2 | 3 | This is the source code for the Go Rules tutorial that is available here: 4 | https://bazel-contrib.github.io/SIG-rules-authors/go-tutorial.html 5 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/add_darwin.go: -------------------------------------------------------------------------------- 1 | package objc 2 | 3 | /* 4 | #include "add_darwin.h" 5 | */ 6 | import "C" 7 | 8 | func Add(a, b int32) int32 { 9 | return int32(C.add(C.int(a), C.int(b))) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/sub_darwin.go: -------------------------------------------------------------------------------- 1 | package objc 2 | 3 | /* 4 | int sub(int a, int b); 5 | */ 6 | import "C" 7 | 8 | func Sub(a, b int32) int32 { 9 | return int32(C.sub(C.int(a), C.int(b))) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/cgo/transitive_dep.go: -------------------------------------------------------------------------------- 1 | package transitive_dep 2 | 3 | /* 4 | #include "tests/core/cgo/native_dep.h" 5 | */ 6 | import "C" 7 | 8 | func PrintGreeting() { 9 | C.native_greeting(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/cgo/use_external_symbol.go: -------------------------------------------------------------------------------- 1 | package use_external_symbol 2 | 3 | /* 4 | void external_symbol(); 5 | */ 6 | import "C" 7 | 8 | func UseExternalSymbol() { 9 | C.external_symbol() 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/protos_a.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/protos"; 4 | 5 | message A { 6 | int64 a = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/protos_b.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/protos"; 4 | 5 | message B { 6 | int64 b = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/nogo/config/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "config_test", 5 | srcs = ["config_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/custom/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "custom_test", 5 | srcs = ["custom_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/custom/flags/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "flags_test", 5 | srcs = ["flags_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/generate/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "empty_test", 5 | srcs = ["empty_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/export_example.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | import ( 4 | "C" 5 | "runtime" 6 | ) 7 | 8 | //export goVersion 9 | func goVersion() string { 10 | return runtime.Version() 11 | } 12 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // #define CGO_EXPORT_H_EXISTS 4 | import "C" 5 | 6 | //export GoAdd 7 | func GoAdd(a, b int) int { 8 | return a + b 9 | } 10 | 11 | func main() {} 12 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_cgo.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | /* 4 | #include "tests/core/cgo/split_import_c.h" 5 | */ 6 | import "C" 7 | 8 | func Half(x int) int { 9 | return int(C.half(C.int(x))) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/nogo/generics/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "generics_test", 5 | srcs = ["generics_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/integration/go_bin_runner/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "go_bin_runner_test", 5 | srcs = ["go_bin_runner_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/legacy/asm_include/foo_test.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | import "testing" 4 | 5 | func TestFoo(t *testing.T) { 6 | x := foo() 7 | if x != 42 { 8 | t.Errorf("got %d; want %d", x, 42) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/legacy/info/BUILD.bazel: -------------------------------------------------------------------------------- 1 | sh_test( 2 | name = "info", 3 | srcs = ["info_test.sh"], 4 | args = ["$(location @io_bazel_rules_go//:go_info)"], 5 | data = ["@io_bazel_rules_go//:go_info"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/legacy/no_prefix/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "no_prefix_test", 5 | srcs = ["no_prefix_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /third_party/BUILD.bazel: -------------------------------------------------------------------------------- 1 | exports_files(glob(["*.patch"])) 2 | 3 | filegroup( 4 | name = "all_files", 5 | testonly = True, 6 | srcs = glob(["**"]), 7 | visibility = ["//visibility:public"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/core/boringcrypto/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "boringcrypto_test", 5 | srcs = ["boringcrypto_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/build_stdlib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "build_stdlib_test", 5 | srcs = ["build_stdlib_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/go_plugin_with_proto_library/plugin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "go_plugin_with_proto_library/validate" 4 | 5 | var testValue = "test" 6 | 7 | var SomeProto = validate.MessageRules{Name: &testValue} 8 | -------------------------------------------------------------------------------- /tests/core/go_test/indirect_import_dep.go: -------------------------------------------------------------------------------- 1 | package indirect_import_dep 2 | 3 | import "github.com/bazelbuild/rules_go/tests/core/go_test/indirect_import" 4 | 5 | func GetX() string { 6 | return indirect_import.X 7 | } 8 | -------------------------------------------------------------------------------- /tests/legacy/examples/stamped_bin/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "stamped_test", 5 | srcs = ["stamped_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/cgo/direct_dep.go: -------------------------------------------------------------------------------- 1 | package direct_dep 2 | 3 | import ( 4 | "github.com/bazelbuild/rules_go/tests/core/cgo/transitive_dep" 5 | ) 6 | 7 | func PrintGreeting() { 8 | transitive_dep.PrintGreeting() 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/go_test/testmain_import_main_test.go: -------------------------------------------------------------------------------- 1 | package test_main 2 | 3 | import "testing" 4 | 5 | var Updated bool 6 | 7 | func TestShouldPass(t *testing.T) { 8 | if !Updated { 9 | t.Fail() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/legacy/empty_package/mixed_cgo.go: -------------------------------------------------------------------------------- 1 | //+build cgo 2 | 3 | package mixed 4 | 5 | import ( 6 | "github.com/bazelbuild/rules_go/tests/empty_package/cgo" 7 | ) 8 | 9 | var Value = cgo.Value 10 | var Expect = "" 11 | -------------------------------------------------------------------------------- /tests/core/cgo/dylib_test.go: -------------------------------------------------------------------------------- 1 | package dylib 2 | 3 | import "testing" 4 | 5 | func TestFoo(t *testing.T) { 6 | want := 42 7 | if got := Foo(); got != want { 8 | t.Errorf("got %d ; want %d", got, want) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/go_binary/static_cgo_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | #include 5 | 6 | void say_hello() { 7 | printf("hello\n"); 8 | } 9 | */ 10 | import "C" 11 | 12 | func main() { 13 | C.say_hello() 14 | } 15 | -------------------------------------------------------------------------------- /tests/core/go_download_sdk/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "go_download_sdk_test", 5 | srcs = ["go_download_sdk_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/go_binary/broken_cgo.go: -------------------------------------------------------------------------------- 1 | // +build cgo 2 | 3 | // This file will not compile and its inclusion in a build is used to ensure 4 | // that a binary was built in pure mode. 5 | package main 6 | 7 | import "non/existent/pkg" 8 | -------------------------------------------------------------------------------- /tests/integration/reproducibility/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "reproducibility_test", 5 | srcs = ["reproducibility_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/use_exported.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "_cgo_export.h" 4 | 5 | void PrintGoVersion() { 6 | GoString version = goVersion(); 7 | printf("Go version: %.*s\n", (int)version.n, version.p); 8 | } 9 | -------------------------------------------------------------------------------- /tests/legacy/cgo_filtered/pure_test.go: -------------------------------------------------------------------------------- 1 | package cgo_filtered 2 | 3 | import "testing" 4 | 5 | func TestFoo(t *testing.T) { 6 | if got, want := Value, 42; got != want { 7 | t.Errorf("got %d; want %d", got, want) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/embed/embed.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package embed; 4 | 5 | option go_package = "github.com/bazelbuild/rules_go/examples/proto/embed"; 6 | 7 | message EmbedExample { 8 | int32 a = 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/legacy/asm_include/foo_other.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | // Other architectures are not supported for this test. This function just 4 | // returns what the assembly function was supposed to return. 5 | func foo() int32 { 6 | return 42 7 | } 8 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/use_exported.h: -------------------------------------------------------------------------------- 1 | #ifndef BAZEL_RULES_GO_EXAMPLES_CGO_USE_EXPORTED_H_ 2 | #define BAZEL_RULES_GO_EXAMPLES_CGO_USE_EXPORTED_H_ 3 | 4 | void PrintGoVersion(); 5 | 6 | #endif // BAZEL_RULES_GO_EXAMPLES_CGO_USE_EXPORTED_H_ 7 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "bazelbuild.vscode-bazel", 6 | "golang.go", 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /tests/core/go_binary/out_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func TestCustomBinaryName(t *testing.T) { 9 | _, err := os.Stat("alt_bin") 10 | if err != nil { 11 | t.Error(err) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.core.go_proto_library.foo; 4 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/foo"; 5 | 6 | message Foo { 7 | int64 value = 1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/legacy/test_rundir/rundir_test.go: -------------------------------------------------------------------------------- 1 | package test_rundir 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func TestRunDir(t *testing.T) { 9 | if _, err := os.Stat("AUTHORS"); err != nil { 10 | t.Error(err) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /go/tools/go_bin_runner/process_unix.go: -------------------------------------------------------------------------------- 1 | //go:build unix 2 | 3 | package main 4 | 5 | import ( 6 | "golang.org/x/sys/unix" 7 | ) 8 | 9 | func ReplaceWithProcess(args, env []string) error { 10 | return unix.Exec(args[0], args, env) 11 | } 12 | -------------------------------------------------------------------------------- /tests/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":buildifier_test.bzl", "buildifier_test") 2 | 3 | buildifier_test( 4 | name = "buildifier_test", 5 | size = "small", 6 | data = [ 7 | ":buildifier_test.bzl", 8 | "//:all_files", 9 | ], 10 | ) 11 | -------------------------------------------------------------------------------- /tests/core/go_download_sdk/README.rst: -------------------------------------------------------------------------------- 1 | go_download_sdk 2 | =============== 3 | 4 | go_download_sdk_test 5 | -------------------- 6 | Verifies that ``go_downlaod_sdk`` can be used to download a specific version 7 | or a set of archives for various platforms. 8 | -------------------------------------------------------------------------------- /tests/integration/gazelle/README.rst: -------------------------------------------------------------------------------- 1 | Gazelle functionality 2 | ===================== 3 | 4 | Tests that ensure rules_go still works with Gazelle. 5 | 6 | gazelle_test 7 | ------------ 8 | Checks that Gazelle can be run in a test workspace. 9 | 10 | -------------------------------------------------------------------------------- /tests/legacy/cgo_multi_dir/cgo_multi_dir_test.go: -------------------------------------------------------------------------------- 1 | package cgo_multi_dir 2 | 3 | import "testing" 4 | 5 | func TestMultiDir(t *testing.T) { 6 | if got, want := foo+bar, 46; got != want { 7 | t.Errorf("got %d; want %d", got, want) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/legacy/info/info_test.sh: -------------------------------------------------------------------------------- 1 | for t in "go version" "GOROOT=" "GOPATH=" "GOARCH=" "GOOS=" "GOBIN="; do 2 | if ! grep -q "$t" $1; then 3 | cat "$1" 4 | echo 5 | echo 6 | echo "Failed to find $t in $1" 7 | exit 1 8 | fi 9 | done 10 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/adjusted_a.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "adjusted/adjusted_b.proto"; 4 | import "adjusted/adjusted_c.proto"; 5 | 6 | package adjusted.a; 7 | 8 | message A { 9 | adjusted.b.B x = 1; 10 | adjusted.c.C y = 2; 11 | } 12 | -------------------------------------------------------------------------------- /tests/legacy/test_rundir/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_test") 2 | 3 | go_test( 4 | name = "go_default_test", 5 | size = "small", 6 | srcs = ["rundir_test.go"], 7 | data = ["//:AUTHORS"], 8 | rundir = ".", 9 | ) 10 | -------------------------------------------------------------------------------- /tests/extras/gomock/client.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "google.golang.org/genproto/googleapis/bytestream" 5 | "google.golang.org/grpc" 6 | ) 7 | 8 | type Client interface { 9 | Connect(grpc.ClientConnInterface) *bytestream.ByteStreamClient 10 | } 11 | -------------------------------------------------------------------------------- /tests/bcr/proto/foo_proto_test.go: -------------------------------------------------------------------------------- 1 | package proto_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "example.com/foo_proto" 7 | ) 8 | 9 | func TestFoo(t *testing.T) { 10 | msg := &foo_proto.Foo{ 11 | Value: 1, 12 | } 13 | if msg.Value != 1 { 14 | t.Fail() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/cgo_select_test.go: -------------------------------------------------------------------------------- 1 | package cgo_select 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | ) 7 | 8 | func TestGoos(t *testing.T) { 9 | if got, want := goos, runtime.GOOS; got != want { 10 | t.Errorf("got %s; want %s\n", got, want) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/dep/useful.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package very.useful; 4 | 5 | import "google/protobuf/duration.proto"; 6 | 7 | message VeryUseful { 8 | string very = 1; 9 | int32 useful = 2; 10 | google.protobuf.Duration timing = 3; 11 | } 12 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/README.rst: -------------------------------------------------------------------------------- 1 | Objective C / cgo functionality 2 | =============================== 3 | 4 | objc_test 5 | --------- 6 | 7 | Checks that a Go target with Objective C code (both embedded and in an 8 | ``objc_library`` ``cdeps`` dependency) compiles, links, and executes. 9 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_b.go: -------------------------------------------------------------------------------- 1 | package b 2 | 3 | import ( 4 | "github.com/bazelbuild/rules_go/tests/core/cgo/split_import/a" 5 | "github.com/bazelbuild/rules_go/tests/core/cgo/split_import/cgo" 6 | ) 7 | 8 | func HalfAnswer() int { 9 | return cgo.Half(a.Answer()) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/bar.go: -------------------------------------------------------------------------------- 1 | package bar 2 | 3 | import ( 4 | "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/baz" 5 | _ "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/foo" 6 | ) 7 | 8 | var Bar string 9 | var Qux = baz.Qux 10 | var Baz = baz.Baz 11 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/crypto.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "C" 4 | 5 | import ( 6 | "crypto/rand" 7 | 8 | "golang.org/x/crypto/nacl/box" 9 | ) 10 | 11 | //export GoFn 12 | func GoFn() { 13 | box.GenerateKey(rand.Reader) 14 | return 15 | } 16 | 17 | func main() { 18 | } 19 | -------------------------------------------------------------------------------- /tests/core/cgo/adder.go: -------------------------------------------------------------------------------- 1 | package objc 2 | 3 | /* 4 | #include "add.h" 5 | */ 6 | import "C" 7 | 8 | func AddC(a, b int32) int32 { 9 | return int32(C.add_c(C.int(a), C.int(b))) 10 | } 11 | 12 | func AddCPP(a, b int32) int32 { 13 | return int32(C.add_cpp(C.int(a), C.int(b))) 14 | } 15 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/baz_linux_test.go: -------------------------------------------------------------------------------- 1 | package test_build_constraints 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | ) 7 | 8 | func TestBazLinux(t *testing.T) { 9 | if runtime.GOOS != "linux" { 10 | t.Errorf("got %s; want linux", runtime.GOOS) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/foo_linux_test.go: -------------------------------------------------------------------------------- 1 | package test_build_constraints 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | ) 7 | 8 | func TestFooLinux(t *testing.T) { 9 | if runtime.GOOS != "linux" { 10 | t.Errorf("got %s; want linux", runtime.GOOS) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_x_test.go: -------------------------------------------------------------------------------- 1 | package a_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bazelbuild/rules_go/tests/core/cgo/split_import/b" 7 | ) 8 | 9 | func TestExternal(t *testing.T) { 10 | if b.HalfAnswer() != 21 { 11 | t.Error("wrong answer") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/core/cgo/use_transitive_symbol.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "C" 4 | 5 | import ( 6 | "github.com/bazelbuild/rules_go/tests/core/cgo/direct_dep" 7 | ) 8 | 9 | //export PrintGreeting 10 | func PrintGreeting() { 11 | direct_dep.PrintGreeting() 12 | } 13 | 14 | func main() {} 15 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/a/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["a.go"], 6 | importpath = "example.com/a", 7 | visibility = ["//tests/core/starlark/packagedriver:__subpackages__"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/b/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["b.go"], 6 | importpath = "example.com/b", 7 | visibility = ["//tests/core/starlark/packagedriver:__subpackages__"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/asm.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "fmt" 4 | 5 | func add(x, y int64) int64 6 | func sub(x, y int64) int64 7 | 8 | func AddTwoNumbers() { 9 | fmt.Println("2 + 3 =", add(2, 3)) 10 | } 11 | 12 | func SubTwoNumbers() { 13 | fmt.Println("2 - 3 =", sub(2, 3)) 14 | } -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/example_command/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/bazelbuild/rules_go/examples/cgo" 7 | ) 8 | 9 | func main() { 10 | fmt.Println("floor(sqrt(10)) = ", cgo.Nsqrt(10)) 11 | cgo.PrintGoVersion() 12 | cgo.PrintCXXVersion() 13 | } 14 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/generated.go.tpl: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | import ( 4 | //#cgo LDFLAGS: -lm 5 | //#include 6 | "C" 7 | "math" 8 | ) 9 | 10 | // Ncbrt returns the cube root of n. 11 | func Ncbrt(n int) int { 12 | return int(math.Floor(float64(C.cbrt(C.double(n))))) 13 | } 14 | -------------------------------------------------------------------------------- /tests/legacy/examples/external/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | 3 | go_binary( 4 | name = "record_log", 5 | srcs = [ 6 | "main.go", 7 | ], 8 | deps = [ 9 | "@com_github_golang_glog//:go_default_library", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/core/cgo/provide_external_symbol.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "C" 4 | 5 | import "github.com/bazelbuild/rules_go/tests/core/cgo/use_external_symbol" 6 | 7 | //export external_symbol 8 | func external_symbol() {} 9 | 10 | func main() { 11 | use_external_symbol.UseExternalSymbol() 12 | } 13 | -------------------------------------------------------------------------------- /tests/core/go_test/external_importmap_dep.go: -------------------------------------------------------------------------------- 1 | package external_importmap_dep 2 | 3 | import ( 4 | "github.com/bazelbuild/rules_go/tests/core/go_test/external_importmap" 5 | ) 6 | 7 | type Impl struct{} 8 | 9 | func (_ *Impl) DeepCopyObject() external_importmap.Object { 10 | return nil 11 | } 12 | -------------------------------------------------------------------------------- /tests/examples/executable_name/name_test.sh: -------------------------------------------------------------------------------- 1 | result="$(${TEST_SRCDIR}/io_bazel_rules_go/tests/examples/executable_name/the_binary)" 2 | expect="The executable ran!" 3 | if [ "$result" != "$expect" ]; then 4 | echo "error: unexpected bazel exit code: want '$expect', got '$result'" >&2 5 | exit 1 6 | fi 7 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add_sandwich.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | #define CGO_EXPORT_H_EXISTS 5 | #include "tests/core/c_linkmodes/add_sandwich.h" 6 | */ 7 | import "C" 8 | 9 | //export GoAdd 10 | func GoAdd(a, b int) int { 11 | return int(C.add(C.int(a), C.int(b))) 12 | } 13 | 14 | func main() {} 15 | -------------------------------------------------------------------------------- /tests/core/go_binary/prefix/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "prefix", 5 | srcs = ["prefix.go"], 6 | importpath = "github.com/bazelbuild/rules_go/tests/core/go_binary/prefix", 7 | visibility = ["//tests/core/go_binary:__pkg__"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/core/go_proto_library_importmap/README.rst: -------------------------------------------------------------------------------- 1 | go_proto_library importmap 2 | ========================== 3 | 4 | importmap_test 5 | -------------- 6 | 7 | Checks that the ``importmap`` attribute of ``go_proto_library`` works correctly. 8 | The test uses reflection information for a type in the generated file. 9 | -------------------------------------------------------------------------------- /tests/examples/README.rst: -------------------------------------------------------------------------------- 1 | Go rules examples 2 | =================== 3 | 4 | This contains examples of how to apply the go rules to common problems. 5 | 6 | Contents 7 | -------- 8 | 9 | .. Child list start 10 | 11 | * `Executable name `_ 12 | 13 | .. Child list end 14 | 15 | -------------------------------------------------------------------------------- /tests/legacy/cgo_trans_deps/cgo_test.go: -------------------------------------------------------------------------------- 1 | package cgo_trans_deps 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bazelbuild/rules_go/tests/cgo_trans_deps/dep" 7 | ) 8 | 9 | func TestCgoTransDeps(t *testing.T) { 10 | if dep.X != 42 { 11 | t.Errorf("got %d; want %d", dep.X, 42) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/legacy/cgo_trans_deps/dep/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["dep.go"], 6 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_trans_deps/dep", 7 | visibility = ["//visibility:public"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/core/starlark/README.rst: -------------------------------------------------------------------------------- 1 | Starlark unit tests 2 | ======================= 3 | 4 | common_test_suite 5 | --------- 6 | 7 | Checks that ``has_shared_lib_extension`` from ``//go/private:common.bzl`` 8 | correctly matches shared library filenames, which may optionally have a version 9 | number at the end. 10 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/bar_l_test.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package test_build_constraints 4 | 5 | import ( 6 | "runtime" 7 | "testing" 8 | ) 9 | 10 | func TestBarLinux(t *testing.T) { 11 | if runtime.GOOS != "linux" { 12 | t.Errorf("got %s; want linux", runtime.GOOS) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add_test_archive.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tests/core/c_linkmodes/adder_archive.h" 3 | 4 | #ifndef CGO_EXPORT_H_EXISTS 5 | #error cgo header did not include define 6 | #endif 7 | 8 | int main(int argc, char** argv) { 9 | assert(GoAdd(42, 42) == 84); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add_test_shared.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tests/core/c_linkmodes/adder_shared.h" 3 | 4 | #ifndef CGO_EXPORT_H_EXISTS 5 | #error cgo header did not include define 6 | #endif 7 | 8 | int main(int argc, char** argv) { 9 | assert(GoAdd(42, 42) == 84); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/core/nogo/coverage/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "coverage_test", 5 | srcs = ["coverage_test.go"], 6 | ) 7 | 8 | go_bazel_test( 9 | name = "gen_code_test", 10 | srcs = ["gen_code_test.go"], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/bcr/runfiles/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@my_rules_go//go:def.bzl", "go_test") 2 | 3 | go_test( 4 | name = "runfiles_test", 5 | srcs = ["runfiles_test.go"], 6 | args = ["$(rlocationpath @other_module//:bar.txt)"], 7 | data = ["@other_module//:bar.txt"], 8 | deps = ["@my_rules_go//go/runfiles"], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/core/stdlib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_test") 2 | load(":stdlib_files.bzl", "stdlib_files") 3 | 4 | go_test( 5 | name = "buildid_test", 6 | srcs = ["buildid_test.go"], 7 | data = [":stdlib_files"], 8 | rundir = ".", 9 | ) 10 | 11 | stdlib_files(name = "stdlib_files") 12 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/bar_unknown_test.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package test_build_constraints 4 | 5 | import ( 6 | "runtime" 7 | "testing" 8 | ) 9 | 10 | func TestBarUnknown(t *testing.T) { 11 | if runtime.GOOS == "linux" { 12 | t.Errorf("got %s; want not linux", runtime.GOOS) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/baz_unknown_test.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package test_build_constraints 4 | 5 | import ( 6 | "runtime" 7 | "testing" 8 | ) 9 | 10 | func TestBazUnknown(t *testing.T) { 11 | if runtime.GOOS == "linux" { 12 | t.Errorf("got %s; want not linux", runtime.GOOS) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/foo_unknown_test.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package test_build_constraints 4 | 5 | import ( 6 | "runtime" 7 | "testing" 8 | ) 9 | 10 | func TestFooUnknown(t *testing.T) { 11 | if runtime.GOOS == "linux" { 12 | t.Errorf("got %s; want not linux", runtime.GOOS) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/add_test_sandwich.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tests/core/c_linkmodes/adder_sandwich_archive.h" 3 | 4 | #ifndef CGO_EXPORT_H_EXISTS 5 | #error cgo header did not include define 6 | #endif 7 | 8 | int main(int argc, char** argv) { 9 | assert(GoAdd(42, 42) == 84); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/integration/gazelle/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "gazelle_test", 5 | size = "medium", 6 | srcs = ["gazelle_test.go"], 7 | rule_files = [ 8 | "//:all_files", 9 | "@bazel_gazelle//:all_files", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/legacy/README.rst: -------------------------------------------------------------------------------- 1 | Legacy tests 2 | ============ 3 | 4 | This is all the tests that were written before we became structured about 5 | testing methodology. 6 | 7 | They are mostly useful, but need restructuring, breaking up and documenting 8 | before adding to the main test suite. 9 | 10 | Help in here is very welcome! -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_linux.go: -------------------------------------------------------------------------------- 1 | package build_constraints 2 | 3 | /* 4 | const char* cgoGo = "linux"; 5 | extern const char* cgoC; 6 | extern const char* cgoCGroup; 7 | */ 8 | import "C" 9 | 10 | var cgoGo = C.GoString(C.cgoGo) 11 | var cgoC = C.GoString(C.cgoC) 12 | var cgoCGroup = C.GoString(C.cgoCGroup) 13 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/lib.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "C" 5 | _ "embed" // for go:embed 6 | ) 7 | 8 | //go:embed embedded_src.txt 9 | var embeddedSource string 10 | 11 | //go:embed renamed_embedded_src.txt 12 | var renamedEmbeddedSource string 13 | 14 | //go:embed template/index.html.tmpl 15 | var indexTmpl string 16 | -------------------------------------------------------------------------------- /tests/integration/googleapis/README.rst: -------------------------------------------------------------------------------- 1 | Functionality related to @go_googleapis 2 | ======================================= 3 | 4 | color_service_test 5 | ------------------ 6 | 7 | Verifies that a simple gRPC client and server can be built and run. .proto 8 | files are compiled at build time and depend on libraries in ``@go_googleapis``. 9 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/sub/floor.go: -------------------------------------------------------------------------------- 1 | package sub 2 | 3 | import ( 4 | //#cgo LDFLAGS: -lm 5 | //#include 6 | "C" 7 | ) 8 | 9 | // Floor calculates floor of the given number 10 | // with the implementation in the standard C library. 11 | func Floor(f float64) float64 { 12 | return float64(C.floor(C.double(f))) 13 | } 14 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/bar.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.core.go_proto_library.bar; 4 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/bar"; 5 | 6 | import "tests/core/go_proto_library/foo.proto"; 7 | 8 | message Bar { 9 | tests.core.go_proto_library.foo.Foo value = 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/gostyle/gostyle.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gostyle; 4 | 5 | option go_package = "github.com/bazelbuild/rules_go/examples/proto/gostyle"; 6 | 7 | import "google/protobuf/ano.proto"; 8 | 9 | message GoStyleObject { 10 | int32 go_not_bazel = 2; 11 | google.protobuf.Any anything = 3; 12 | } 13 | -------------------------------------------------------------------------------- /tests/legacy/providers/test.bzl: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "GoLibrary") 2 | 3 | def _test_impl(ctx): 4 | pass 5 | 6 | test_source = rule( 7 | implementation = _test_impl, 8 | attrs = { 9 | "srcs": attr.label( 10 | mandatory = True, 11 | providers = [GoLibrary], 12 | ), 13 | }, 14 | ) 15 | -------------------------------------------------------------------------------- /tests/core/go_bazel_test/README.rst: -------------------------------------------------------------------------------- 1 | go_bazel_test macro functionality 2 | ================================= 3 | 4 | Tests to ensure the go_bazel_test is functioning correctly. 5 | 6 | dataargtest_test 7 | ---------------- 8 | 9 | Tests that `data` and `args` provided to `go_bazel_test` are provided to the go 10 | test framework correctly. 11 | -------------------------------------------------------------------------------- /tests/extras/go_embed_data/README.rst: -------------------------------------------------------------------------------- 1 | go_embed_data 2 | ============= 3 | 4 | .. _go_embed_data: /docs/go/extras/extras.md#go-embed-data 5 | 6 | Tests to ensure basic features of `go_embed_data`_ are working correctly. 7 | 8 | embed_test 9 | ---------- 10 | 11 | Depends on multiple ``go_embed_data`` targets and verifies their contents. 12 | -------------------------------------------------------------------------------- /tests/legacy/package_named_build/build/build_test.go: -------------------------------------------------------------------------------- 1 | package build_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bazelbuild/rules_go/tests/package_named_build/build" 7 | ) 8 | 9 | func TestBuildValue(t *testing.T) { 10 | if got, want := build.Foo, 42; got != want { 11 | t.Errorf("got %d; want %d", got, want) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/bcr/proto/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.bcr.proto; 4 | option go_package = "example.com/foo_proto"; 5 | 6 | import "google/protobuf/empty.proto"; 7 | 8 | message Foo { 9 | int64 value = 1; 10 | google.protobuf.Empty empty = 2; 11 | } 12 | 13 | service Fooer { 14 | rpc RoundTripFoo (Foo) returns (Foo) {} 15 | } 16 | -------------------------------------------------------------------------------- /tests/core/transition/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "cmdline_test", 5 | size = "medium", 6 | srcs = ["cmdline_test.go"], 7 | ) 8 | 9 | go_bazel_test( 10 | name = "hermeticity_test", 11 | size = "medium", 12 | srcs = ["hermeticity_test.go"], 13 | ) 14 | -------------------------------------------------------------------------------- /tests/core/go_binary/stamp_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "example.com/stamp_dep" 7 | ) 8 | 9 | var Bin = "redacted" 10 | 11 | func main() { 12 | fmt.Printf("Bin=%s\n", Bin) 13 | fmt.Printf("Embed=%s\n", Embed) 14 | fmt.Printf("DepSelf=%s\n", stamp_dep.DepSelf) 15 | fmt.Printf("DepBin=%s\n", stamp_dep.DepBin) 16 | } 17 | -------------------------------------------------------------------------------- /tests/core/nogo/generate/README.rst: -------------------------------------------------------------------------------- 1 | nogo test with generated code 2 | ======================= 3 | 4 | .. _nogo: /go/nogo.rst 5 | 6 | Tests to ensure `nogo`_ interaction with generated code. 7 | 8 | empty_test 9 | ------------- 10 | Checks that `nogo`_ is not running over the `_empty.go` file that was 11 | generated as part of GoCompilePkg. 12 | 13 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_unknown.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package build_constraints 4 | 5 | /* 6 | const char* cgoGo = "unknown"; 7 | extern const char* cgoC; 8 | extern const char* cgoCGroup; 9 | */ 10 | import "C" 11 | 12 | var cgoGo = C.GoString(C.cgoGo) 13 | var cgoC = C.GoString(C.cgoC) 14 | var cgoCGroup = C.GoString(C.cgoCGroup) 15 | -------------------------------------------------------------------------------- /tests/legacy/test_chdir/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_test") 2 | 3 | go_test( 4 | name = "go_default_test", 5 | size = "small", 6 | srcs = ["data_test.go"], 7 | data = ["data.txt"], 8 | ) 9 | 10 | test_suite( 11 | name = "remote_test", 12 | tests = ["@test_chdir_remote//sub:go_default_test"], 13 | ) 14 | -------------------------------------------------------------------------------- /tests/legacy/examples/monobuild/lib1/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | package(default_visibility = ["//tests/legacy/examples/monobuild/cmd:__pkg__"]) 4 | 5 | go_library( 6 | name = "go_default_library", 7 | srcs = [ 8 | "lib1.go", 9 | ], 10 | importpath = "full/import/path/to/lib1", 11 | ) 12 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/grpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.core.go_proto_library.grpc; 4 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/grpc"; 5 | 6 | message HelloRequest { 7 | } 8 | 9 | message HelloReply { 10 | } 11 | 12 | service RPC { 13 | rpc Hello (HelloRequest) returns (HelloReply) {} 14 | } 15 | -------------------------------------------------------------------------------- /tests/core/race/README.rst: -------------------------------------------------------------------------------- 1 | race instrumentation 2 | ==================== 3 | 4 | race_test 5 | --------- 6 | 7 | Embeds a library that triggers a data race inside a binary and a test. 8 | Verifies that no race is reported by default and a race is reported when either 9 | target is build with the ``race = "on"`` attribute or the ``--features=race`` 10 | flag. 11 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/lib/lib.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examples.lib; 4 | 5 | option go_package = "github.com/bazelbuild/rules_go/examples/proto/lib/lib_proto"; 6 | 7 | import "tests/legacy/examples/proto/dep/useful.proto"; 8 | 9 | message LibObject { 10 | very.useful.VeryUseful very_useful = 1; 11 | int32 are_you_sure = 2; 12 | } 13 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/cc_dependency/version.h: -------------------------------------------------------------------------------- 1 | #ifndef BAZEL_RULES_GO_EXAMPLES_CGO_CC_DEPENDENCY_VERSION_H_ 2 | #define BAZEL_RULES_GO_EXAMPLES_CGO_CC_DEPENDENCY_VERSION_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" void PrintCXXVersion(); 6 | #else 7 | void PrintCXXVersion(); 8 | #endif 9 | 10 | #endif // BAZEL_RULES_GO_EXAMPLES_CGO_CC_DEPENDENCY_VERSION_H_ 11 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/cgo_lib_test.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | import ( 4 | "math" 5 | "testing" 6 | ) 7 | 8 | func TestNsqrt(t *testing.T) { 9 | for _, n := range []int{1, 2, 10, 100, 1000} { 10 | got, want := Nsqrt(n), int(math.Floor(math.Sqrt(float64(n)))) 11 | if got != want { 12 | t.Errorf("Nsqrt(n) = %d; want %d", got, want) 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/legacy/examples/monobuild/lib2/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | package(default_visibility = ["//tests/legacy/examples/monobuild/cmd:__pkg__"]) 4 | 5 | go_library( 6 | name = "go_default_library", 7 | srcs = [ 8 | "lib2.go", 9 | ], 10 | importpath = "totally/different/import/for/lib2", 11 | ) 12 | -------------------------------------------------------------------------------- /tests/legacy/examples/vendor/github.com/user/vendored/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | go_library( 8 | name = "go_default_library", 9 | srcs = [ 10 | "vendored.go", 11 | ], 12 | importpath = "github.com/user/vendored", 13 | ) 14 | -------------------------------------------------------------------------------- /examples/basic-gazelle/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Go Rules Tutorial 2 | 3 | ## Updates 4 | 5 | Please update both the source code here and the tutorial that is on the gh-pages branch here: 6 | https://github.com/bazel-contrib/SIG-rules-authors/tree/gh-pages. 7 | 8 | Updates to this tutorial require two PRs, as there are code block in the gh-pages tutorial mentioned 9 | above. 10 | -------------------------------------------------------------------------------- /tests/core/go_test/external_importmap_test.go: -------------------------------------------------------------------------------- 1 | package external_importmap_test 2 | 3 | import ( 4 | "github.com/bazelbuild/rules_go/tests/core/go_test/external_importmap" 5 | "github.com/bazelbuild/rules_go/tests/core/go_test/external_importmap_dep" 6 | ) 7 | 8 | var _ external_importmap.Object = &external_importmap_dep.Impl{} 9 | 10 | // Test passes if it compiles. 11 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/cgo_pure_test.go: -------------------------------------------------------------------------------- 1 | package cgo_pure_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/bazelbuild/rules_go/tests/cgo_pure" 8 | ) 9 | 10 | var Expect = "" 11 | 12 | func TestValue(t *testing.T) { 13 | got := fmt.Sprintf("%d", cgo_pure.Value) 14 | if got != Expect { 15 | t.Errorf("got %q; want %q", got, Expect) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /go/private/skylib/README.rst: -------------------------------------------------------------------------------- 1 | This directory is a partial copy of github.com/bazelbuild/bazel-skylib/lib. 2 | Version 0.5.0, retrieved on 2018-11-26. 3 | Only versions.bzl is included. 4 | 5 | versions.bzl is needed by repository rules imported from //go:deps.bzl. 6 | Uses of Skylib outside of files loaded by //go:deps.bzl should use 7 | the external Skylib repository, @bazel_skylib. 8 | -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_go", 3 | "maintainers": [ 4 | { 5 | "email": "fabian@meumertzhe.im", 6 | "github": "fmeum", 7 | "name": "Fabian Meumertzheim" 8 | } 9 | ], 10 | "repository": [ 11 | "github:bazelbuild/rules_go" 12 | ], 13 | "versions": [], 14 | "yanked_versions": {} 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic-gazelle/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_go/examples/basic-gazelle 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/spf13/cobra v1.5.0 7 | k8s.io/klog/v2 v2.80.1 8 | ) 9 | 10 | require ( 11 | github.com/go-logr/logr v1.2.0 // indirect 12 | github.com/inconshreveable/mousetrap v1.0.0 // indirect 13 | github.com/spf13/pflag v1.0.5 // indirect 14 | ) 15 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/objc_darwin_test.go: -------------------------------------------------------------------------------- 1 | package objc 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "testing" 7 | ) 8 | 9 | func TestObjcMethod(t *testing.T) { 10 | a := rand.Int31() 11 | b := rand.Int31() 12 | expected := a + b 13 | if result := Add(a, b); result != expected { 14 | t.Error(fmt.Errorf("wrong result: expected %d, got %d", expected, result)) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/go/extras/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | exports_files([ 4 | "extras.md", 5 | "extras.bzl", 6 | ]) 7 | 8 | bzl_library( 9 | name = "extras", 10 | srcs = ["extras.bzl"], 11 | visibility = ["//visibility:public"], 12 | deps = [ 13 | "//extras:embed_data", 14 | "//extras:gomock", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /tests/core/go_test/indirect_import_x_test.go: -------------------------------------------------------------------------------- 1 | package indirect_import_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bazelbuild/rules_go/tests/core/go_test/indirect_import_dep" 7 | ) 8 | 9 | func Test(t *testing.T) { 10 | got := indirect_import_dep.GetX() 11 | want := "set by TestMain" 12 | if got != want { 13 | t.Errorf("got %q; want %q", got, want) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/legacy/empty_package/empty_package_test.go: -------------------------------------------------------------------------------- 1 | package empty_package_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/bazelbuild/rules_go/tests/empty_package/mixed" 8 | ) 9 | 10 | var Expect = "" 11 | 12 | func TestValue(t *testing.T) { 13 | got := fmt.Sprintf("%d", mixed.Value) 14 | if got != Expect { 15 | t.Errorf("got %q; want %q", got, Expect) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/deep/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | package(default_visibility = ["//tests/legacy/examples/lib:__pkg__"]) 4 | 5 | go_library( 6 | name = "go_default_library", 7 | srcs = [ 8 | "doc.go", 9 | "thought.go", 10 | ], 11 | importpath = "github.com/bazelbuild/rules_go/examples/lib/deep", 12 | ) 13 | -------------------------------------------------------------------------------- /tests/legacy/visibility/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | package_group( 4 | name = "vis", 5 | packages = [ 6 | "//...", 7 | ], 8 | ) 9 | 10 | go_library( 11 | name = "go_default_library", 12 | srcs = ["foo.go"], 13 | importpath = "github.com/bazelbuild/rules_go/tests/visibility", 14 | visibility = [":vis"], 15 | ) 16 | -------------------------------------------------------------------------------- /tests/core/go_bazel_test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "dataargtest_test", 5 | srcs = ["dataargtest_test.go"], 6 | args = ["-binaryPath=$(location //tests/core/go_binary:hello)"], 7 | data = ["//tests/core/go_binary:hello"], 8 | deps = ["//go/tools/bazel:go_default_library"], 9 | ) 10 | -------------------------------------------------------------------------------- /tests/core/go_plugin/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test") 2 | 3 | test_suite(name = "go_plugin") 4 | 5 | go_test( 6 | name = "go_default_test", 7 | srcs = ["all_test.go"], 8 | data = [":plugin"], 9 | ) 10 | 11 | go_binary( 12 | name = "plugin", 13 | srcs = ["plugin.go"], 14 | out = "plugin.so", 15 | linkmode = "plugin", 16 | ) 17 | -------------------------------------------------------------------------------- /tests/core/output_groups/README.rst: -------------------------------------------------------------------------------- 1 | output_groups functionality 2 | =========================== 3 | 4 | Tests to ensure the supported `output_groups` are working as expected. 5 | 6 | compilation_outputs_test 7 | ------------------------ 8 | 9 | Checks that the `compilation_outputs` output group is populated with the 10 | compiled archives from `go_library`, `go_test`, and `go_binary` targets. 11 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/cc_dependency/c_version.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "tests/legacy/examples/cgo/cc_dependency/c_version.h" 4 | 5 | void PrintCVersion() { 6 | #ifdef __STDC__ 7 | # ifdef __STDC_VERSION__ 8 | printf("C version: %ld\n", __STDC_VERSION__); 9 | # else 10 | printf("C version: C89\n"); 11 | # endif 12 | #else 13 | printf("C version: maybe K&R\n"); 14 | #endif 15 | } 16 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/sub.m: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | @interface Subber : NSObject 4 | 5 | - (int)sub:(int)num1 andNum2:(int)num2; 6 | 7 | @end 8 | 9 | @implementation Subber 10 | 11 | - (int)sub:(int)num1 andNum2:(int)num2{ 12 | return num1 - num2; 13 | } 14 | 15 | @end 16 | 17 | int sub(int a, int b) { 18 | Subber* subber = [[Subber alloc] init]; 19 | return [subber sub:a andNum2:b]; 20 | } 21 | -------------------------------------------------------------------------------- /tests/core/go_test/pwd_test.go: -------------------------------------------------------------------------------- 1 | package pwd 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "strings" 7 | "testing" 8 | ) 9 | 10 | func TestPwd(t *testing.T) { 11 | pwd := os.Getenv("PWD") 12 | suffix := filepath.FromSlash("tests/core/go_test") 13 | if !strings.HasSuffix(pwd, filepath.FromSlash(suffix)) { 14 | t.Errorf("PWD not set. got %q; want something ending with %q", pwd, suffix) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pthread_flag/cgo_pthread_flag_test.go: -------------------------------------------------------------------------------- 1 | package cgo_pthread_flag 2 | 3 | import "testing" 4 | 5 | // Checks that we can build and run pthread code without explicitly giving 6 | // any flags to cgo. -pthread should be passed to the C compiler by default. 7 | func TestCgoPthread(t *testing.T) { 8 | x := int(callFFromGo()) 9 | if x != 42 { 10 | t.Errorf("got %d; want 42", x) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/skip_go_library/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | go_library( 6 | name = "go_default_library", 7 | srcs = [ 8 | "cgo_foo.go", 9 | "types.go", 10 | ], 11 | cgo = True, 12 | importpath = "github.com/bazelbuild/rules_go/examples/cgo/skip_go_library", 13 | ) 14 | -------------------------------------------------------------------------------- /tests/core/boringcrypto/README.rst: -------------------------------------------------------------------------------- 1 | Boringcrypto 2 | =========== 3 | 4 | Tests to ensure that support for building with boringcrypto is working as expected. 5 | 6 | boringcrypto_test 7 | -------------- 8 | 9 | Test that the build is failed if a non-local Go version less than 1.19 is requested to be built with 10 | boringcrypto. Test that binaries built with boringcrypto stdlib have X:boringcrypto in version 11 | information. -------------------------------------------------------------------------------- /tests/legacy/examples/proto/gogo/values.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package gogo; 4 | 5 | import "google/protobuf/duration.proto"; 6 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 7 | 8 | option go_package = "github.com/bazelbuild/rules_go/examples/proto/gogo"; 9 | option (gogoproto.gostring_all) = true; 10 | 11 | message Value { 12 | int32 item = 1; 13 | google.protobuf.Duration timing = 3; 14 | } 15 | -------------------------------------------------------------------------------- /tests/core/go_path/README.rst: -------------------------------------------------------------------------------- 1 | Basic go_path functionality 2 | =========================== 3 | 4 | .. _go_path: /docs/go/core/rules.md#_go_path 5 | 6 | Tests to ensure the basic features of `go_path`_ are working as expected. 7 | 8 | go_path_test 9 | ------------ 10 | 11 | Consumes `go_path`_ rules built for the same set of packages in archive, copy, 12 | and link modes and verifies that expected files are present in each mode. 13 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/transitive_data_test.go: -------------------------------------------------------------------------------- 1 | package transitive_data 2 | 3 | import ( 4 | "flag" 5 | "os" 6 | "testing" 7 | ) 8 | 9 | func TestFiles(t *testing.T) { 10 | filenames := flag.Args() 11 | if len(filenames) == 0 { 12 | t.Fatal("no filenames given") 13 | } 14 | 15 | for _, filename := range flag.Args() { 16 | if _, err := os.Stat(filename); err != nil { 17 | t.Error(err) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/core/go_proto_library_importmap/importmap_test.go: -------------------------------------------------------------------------------- 1 | package importmap_test 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | 7 | foo "github.com/bazelbuild/rules_go/tests/core/go_proto_library_importmap" 8 | ) 9 | 10 | func TestImportMap(t *testing.T) { 11 | got := reflect.TypeOf(foo.Foo{}).PkgPath() 12 | want := "never/gonna/give/you/up" 13 | if got != want { 14 | t.Errorf("got %q; want %q", got, want) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/legacy/examples/monobuild/cmd/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | go_binary( 8 | name = "mycmd", 9 | srcs = ["mycmd.go"], 10 | deps = [ 11 | "//tests/legacy/examples/monobuild/lib1:go_default_library", 12 | "//tests/legacy/examples/monobuild/lib2:go_default_library", 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /tests/core/build_stdlib/README.rst: -------------------------------------------------------------------------------- 1 | Building with standard libraries with missing .a files 2 | =========== 3 | 4 | Tests to ensure that building with Go 1.20 and later versions of Go, which no longer 5 | include precompiled standard library .a files, continues to work 6 | 7 | build_stdlib_test 8 | -------------- 9 | 10 | Test that a simple binary depending on a simple library can build when the WORKSPACE's 11 | go version is set to 1.20rc1. -------------------------------------------------------------------------------- /go/tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "all_files", 3 | testonly = True, 4 | srcs = [ 5 | "//go/tools/bazel:all_files", 6 | "//go/tools/bazel_testing:all_files", 7 | "//go/tools/builders:all_files", 8 | "//go/tools/bzltestutil:all_files", 9 | "//go/tools/coverdata:all_files", 10 | "//go/tools/go_bin_runner:all_files", 11 | ], 12 | visibility = ["//visibility:public"], 13 | ) 14 | -------------------------------------------------------------------------------- /tests/legacy/cgo_filtered/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_test( 4 | name = "go_default_test", 5 | size = "small", 6 | srcs = ["pure_test.go"], 7 | embed = [":go_default_library"], 8 | ) 9 | 10 | go_library( 11 | name = "go_default_library", 12 | srcs = ["pure.go"], 13 | cgo = True, 14 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_filtered", 15 | ) 16 | -------------------------------------------------------------------------------- /tests/legacy/providers/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_source") 2 | load("//tests/legacy/providers:test.bzl", "test_source") 3 | 4 | go_source( 5 | name = "srcs", 6 | srcs = [ 7 | "test.go", 8 | ], 9 | ) 10 | 11 | test_source( 12 | name = "foo", 13 | srcs = ":srcs", 14 | ) 15 | 16 | sh_test( 17 | name = "source_test", 18 | srcs = ["test.sh"], 19 | data = [ 20 | ":foo", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/add_darwin.m: -------------------------------------------------------------------------------- 1 | @import Foundation; 2 | 3 | #include "add_darwin.h" 4 | 5 | @interface Adder : NSObject 6 | 7 | - (int)add:(int)num1 andNum2:(int)num2; 8 | 9 | @end 10 | 11 | @implementation Adder 12 | 13 | - (int)add:(int)num1 andNum2:(int)num2{ 14 | return num1 + num2; 15 | } 16 | 17 | @end 18 | 19 | int add(int a, int b) { 20 | Adder* adder = [[Adder alloc] init]; 21 | return [adder add:a andNum2:b]; 22 | } 23 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/lib/lib2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examples.lib; 4 | 5 | option go_package = "github.com/bazelbuild/rules_go/examples/proto/lib/lib_proto"; 6 | 7 | import "tests/legacy/examples/proto/dep/useful.proto"; 8 | import "tests/legacy/examples/proto/lib/lib.proto"; 9 | 10 | message LibObject2 { 11 | very.useful.VeryUseful very_useful = 1; 12 | int32 are_you_sure = 2; 13 | LibObject lib_object = 4; 14 | } 15 | -------------------------------------------------------------------------------- /tests/legacy/slash_names/slash_test.go: -------------------------------------------------------------------------------- 1 | package slash 2 | 3 | import ( 4 | "testing" 5 | 6 | a "github.com/bazelbuild/rules_go/tests/slash_names/a/pkg" 7 | b "github.com/bazelbuild/rules_go/tests/slash_names/b/pkg" 8 | ) 9 | 10 | func TestSlash(t *testing.T) { 11 | if name := a.Name(); name != "A" { 12 | t.Errorf("got %s; want A", name) 13 | } 14 | if name := b.Name(); name != "B" { 15 | t.Errorf("got %s; want B", name) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /go/tools/coverdata/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go/private/rules:library.bzl", "go_tool_library") 2 | 3 | go_tool_library( 4 | name = "coverdata", 5 | srcs = ["coverdata.go"], 6 | importpath = "github.com/bazelbuild/rules_go/go/tools/coverdata", 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | filegroup( 11 | name = "all_files", 12 | testonly = True, 13 | srcs = glob(["**"]), 14 | visibility = ["//visibility:public"], 15 | ) 16 | -------------------------------------------------------------------------------- /tests/core/cgo/add.m: -------------------------------------------------------------------------------- 1 | #include "add.h" 2 | #include 3 | #include 4 | 5 | #if !defined(RULES_GO_C) || !defined(RULES_GO_CPP) || defined(RULES_GO_CXX) 6 | #error This is an Objective-C file, only RULES_GO_C and RULES_GO_CPP should be defined. 7 | #endif 8 | 9 | #if !defined(GENERATED_COPTS) || !defined(GENERATED_CPPOPTS) || defined(GENERATED_CXXOPTS) 10 | #error Generated headers should be correctly included 11 | #endif 12 | -------------------------------------------------------------------------------- /tests/legacy/proto_ignore_go_package_option/a.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // This is a fake go_package that would be ignored by specifying 4 | // ignore_go_package_option = 1. 5 | option go_package = "foo.com/bar/bla;boo"; 6 | 7 | // Importing google proto is not affected by ignore_go_package_option. 8 | import "google/protobuf/struct.proto"; 9 | 10 | package foo; 11 | 12 | message Foo { 13 | int32 a = 1; 14 | google.protobuf.Struct s = 2; 15 | } 16 | -------------------------------------------------------------------------------- /go/tools/bazel_benchmark/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_binary", "go_library") 2 | 3 | go_binary( 4 | name = "bazel_benchmark", 5 | embed = [":bazel_benchmark_lib"], 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | go_library( 10 | name = "bazel_benchmark_lib", 11 | srcs = ["bazel_benchmark.go"], 12 | importpath = "github.com/bazelbuild/rules_go/go/tools/bazel_benchmark", 13 | visibility = ["//visibility:private"], 14 | ) 15 | -------------------------------------------------------------------------------- /tests/core/cgo/add.mm: -------------------------------------------------------------------------------- 1 | #include "add.h" 2 | #include 3 | #include 4 | 5 | #if !defined(RULES_GO_CPP) || !defined(RULES_GO_CXX) || defined(RULES_GO_C) 6 | #error This is an Objective-C++ file, only RULES_GO_CXX and RULES_GO_CPP should be defined. 7 | #endif 8 | 9 | #if !defined(GENERATED_CPPOPTS) || !defined(GENERATED_CXXOPTS) || defined(GENERATED_COPTS) 10 | #error Generated headers should be correctly included 11 | #endif 12 | -------------------------------------------------------------------------------- /tests/core/nogo/vet/README.rst: -------------------------------------------------------------------------------- 1 | Vet check 2 | ========= 3 | 4 | .. _go_library: /docs/go/core/rules.md#_go_library 5 | 6 | Tests to ensure that vet runs and detects errors. 7 | 8 | .. contents:: 9 | 10 | vet_test 11 | -------- 12 | Verifies that vet errors are emitted on a `go_library`_ with problems when built 13 | with a ``nogo`` binary with ``vet = True``. No errors should be emitted when 14 | analyzing error-free source code. Vet should not be enabled by default. 15 | -------------------------------------------------------------------------------- /extras/gomock/BUILD.bazel: -------------------------------------------------------------------------------- 1 | alias( 2 | name = "gomock", 3 | actual = "@com_github_golang_mock//gomock", 4 | visibility = ["//visibility:public"], 5 | ) 6 | 7 | alias( 8 | name = "mockgen", 9 | actual = "@com_github_golang_mock//mockgen", 10 | visibility = ["//visibility:public"], 11 | ) 12 | 13 | alias( 14 | name = "mockgen_model", 15 | actual = "@com_github_golang_mock//mockgen/model", 16 | visibility = ["//visibility:public"], 17 | ) 18 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pthread_flag/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["cgo_pthread_flag.go"], 6 | cgo = True, 7 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_pthread_flag", 8 | ) 9 | 10 | go_test( 11 | name = "go_default_test", 12 | size = "small", 13 | srcs = ["cgo_pthread_flag_test.go"], 14 | embed = [":go_default_library"], 15 | ) 16 | -------------------------------------------------------------------------------- /tests/legacy/package_named_build/build/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["build.go"], 6 | importpath = "github.com/bazelbuild/rules_go/tests/package_named_build/build", 7 | ) 8 | 9 | go_test( 10 | name = "go_default_xtest", 11 | size = "small", 12 | srcs = ["build_test.go"], 13 | deps = [ 14 | ":go_default_library", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/basic-gazelle/cmd/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "cmd", 5 | srcs = [ 6 | "roll.go", 7 | "root.go", 8 | ], 9 | importpath = "github.com/bazelbuild/rules_go/examples/basic-gazelle/cmd", 10 | visibility = ["//visibility:public"], 11 | deps = [ 12 | "//pkg/roll", 13 | "@com_github_spf13_cobra//:cobra", 14 | "@io_k8s_klog_v2//:klog", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/basic-gazelle/pkg/roll/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "roll", 5 | srcs = ["roll_dice.go"], 6 | importpath = "github.com/bazelbuild/rules_go/examples/basic-gazelle/pkg/roll", 7 | visibility = ["//visibility:public"], 8 | deps = ["@io_k8s_klog_v2//:klog"], 9 | ) 10 | 11 | go_test( 12 | name = "roll_test", 13 | srcs = ["roll_dice_test.go"], 14 | embed = [":roll"], 15 | ) 16 | -------------------------------------------------------------------------------- /go/tools/go_bin_runner/process.go: -------------------------------------------------------------------------------- 1 | //go:build !unix 2 | 3 | package main 4 | 5 | import ( 6 | "os" 7 | "os/exec" 8 | ) 9 | 10 | func ReplaceWithProcess(args, env []string) error { 11 | cmd := exec.Command(args[0], args[1:]...) 12 | cmd.Stdout = os.Stdout 13 | cmd.Stderr = os.Stderr 14 | cmd.Env = env 15 | err := cmd.Run() 16 | if exitErr, ok := err.(*exec.ExitError); ok { 17 | os.Exit(exitErr.ExitCode()) 18 | } else if err == nil { 19 | os.Exit(0) 20 | } 21 | return err 22 | } 23 | -------------------------------------------------------------------------------- /tests/core/nogo/README.rst: -------------------------------------------------------------------------------- 1 | Core Go rules tests 2 | =================== 3 | 4 | This contains tests of the nogo build-time code analysis tool. 5 | 6 | Contents 7 | -------- 8 | 9 | .. Child list start 10 | 11 | * `Vet check `_ 12 | * `Nogo configuration `_ 13 | * `nogo analyzers with dependencies `_ 14 | * `Custom nogo analyzers `_ 15 | * `nogo test with coverage `_ 16 | 17 | .. Child list end 18 | 19 | -------------------------------------------------------------------------------- /tests/examples/executable_name/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | 3 | go_binary( 4 | name = "some_binary", 5 | srcs = ["main.go"], 6 | ) 7 | 8 | genrule( 9 | name = "normalised_binary", 10 | srcs = [":some_binary"], 11 | outs = ["the_binary"], 12 | cmd = "cp $(SRCS) $@", 13 | ) 14 | 15 | sh_test( 16 | name = "executable_name", 17 | size = "small", 18 | srcs = ["name_test.sh"], 19 | data = [":normalised_binary"], 20 | ) 21 | -------------------------------------------------------------------------------- /tests/legacy/cgo_sys_hdr/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = [ 6 | "foo.go", 7 | "sub/foo.h", 8 | ], 9 | cgo = True, 10 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_sys_hdr", 11 | ) 12 | 13 | go_test( 14 | name = "go_default_test", 15 | size = "small", 16 | srcs = ["foo_test.go"], 17 | embed = [":go_default_library"], 18 | ) 19 | -------------------------------------------------------------------------------- /tests/legacy/examples/bin/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | go_binary( 8 | name = "bin", 9 | srcs = ["bin.go"], 10 | x_defs = { 11 | "main.buildTime": "2016/05/19 09:10am", 12 | }, 13 | deps = [ 14 | "//tests/legacy/examples/lib:go_default_library", 15 | "//tests/legacy/examples/vendor/github.com/user/vendored:go_default_library", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /tests/core/cgo/adder_test.go: -------------------------------------------------------------------------------- 1 | package objc 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "testing" 7 | ) 8 | 9 | func TestCPPAdder(t *testing.T) { 10 | a := rand.Int31() 11 | b := rand.Int31() 12 | expected := a + b 13 | if result := AddC(a, b); result != expected { 14 | t.Error(fmt.Errorf("wrong result: got %d, expected %d", result, expected)) 15 | } 16 | if result := AddCPP(a, b); result != expected { 17 | t.Error(fmt.Errorf("wrong result: got %d, expected %d", result, expected)) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/legacy/cgo_opts/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["cgo_opts.go"], 6 | cgo = True, 7 | copts = ["-DFOO=1 -DBAR=2 -g -O2"], 8 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_opts", 9 | visibility = ["//visibility:public"], 10 | ) 11 | 12 | go_test( 13 | name = "go_default_test", 14 | srcs = ["cgo_opts_test.go"], 15 | embed = [":go_default_library"], 16 | ) 17 | -------------------------------------------------------------------------------- /go/private/skylib/lib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | filegroup( 4 | name = "all_rules", 5 | srcs = glob(["**/*.bzl"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | filegroup( 10 | name = "all_files", 11 | testonly = True, 12 | srcs = glob(["**"]), 13 | visibility = ["//visibility:public"], 14 | ) 15 | 16 | bzl_library( 17 | name = "versions", 18 | srcs = ["versions.bzl"], 19 | visibility = ["//go:__subpackages__"], 20 | ) 21 | -------------------------------------------------------------------------------- /tests/examples/executable_name/README.rst: -------------------------------------------------------------------------------- 1 | Executable name 2 | =============== 3 | 4 | .. _go_binary: /docs/go/core/rules.md#go_binary 5 | 6 | The filename of the executable produced by a go_binary_ rule is unpredictale, the full path includes 7 | the compilation mode amongst other things, and the rules offer no backwards compatibility guarantees 8 | about the filename. 9 | For the simple case where you know exactly what you want the output filename to be, you can use a 10 | genrule to copy it to a well known place. 11 | -------------------------------------------------------------------------------- /tests/legacy/cgo_trans_deps/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["cgo_lib.go"], 6 | cgo = True, 7 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_trans_deps", 8 | deps = ["//tests/legacy/cgo_trans_deps/dep:go_default_library"], 9 | ) 10 | 11 | go_test( 12 | name = "go_default_test", 13 | size = "small", 14 | srcs = ["cgo_test.go"], 15 | embed = [":go_default_library"], 16 | ) 17 | -------------------------------------------------------------------------------- /third_party/README.txt: -------------------------------------------------------------------------------- 1 | This directory contains patches for repositories declared by 2 | go_rules_dependencies. 3 | 4 | If you declare dependencies on different versions of these repositories, you 5 | may need to update and apply these patches yourself. 6 | 7 | For details on overriding dependencies, see 8 | https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#overriding-dependencies 9 | 10 | For details on updating these patches, see 11 | https://github.com/bazelbuild/rules_go/wiki/Updating-dependencies 12 | -------------------------------------------------------------------------------- /tests/legacy/proto_ignore_go_package_option/b.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // This is a fake go_package that would be ignored when specifying 4 | // ignore_go_package_option. 5 | option go_package = "foo.com/bar/blabla;blu"; 6 | 7 | // Mixing imports from google and local repository will work just fine. 8 | import "google/protobuf/any.proto"; 9 | import "tests/legacy/proto_ignore_go_package_option/a.proto"; 10 | 11 | package bar; 12 | 13 | message Bar { 14 | foo.Foo foo = 1; 15 | google.protobuf.Any a = 2; 16 | } 17 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_go 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/golang/mock v1.6.0 7 | github.com/golang/protobuf v1.5.2 8 | google.golang.org/protobuf v1.28.0 9 | ) 10 | 11 | require ( 12 | golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect 13 | golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect 14 | golang.org/x/text v0.3.3 // indirect 15 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 16 | google.golang.org/grpc v1.50.0 // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /tests/core/stdlib/reproduce_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eux -o pipefail 3 | 4 | function run_bazel() { 5 | bazel clean --expunge 6 | bazel test //tests/core/go_binary:all 7 | find bazel-out/ -name '*.a' | sort | uniq | grep stdlib | xargs shasum > $1 8 | } 9 | 10 | FILE1=$(mktemp) 11 | FILE2=$(mktemp) 12 | 13 | echo First run 14 | run_bazel ${FILE1} 15 | 16 | echo Second run 17 | run_bazel ${FILE2} 18 | 19 | echo Diffing runs 20 | diff ${FILE1} ${FILE2} 21 | 22 | echo Removing files 23 | rm ${FILE1} ${FILE2} 24 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This the official list of Bazel authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Benjamin Staffin 10 | Brian Silverman 11 | David Santiago 12 | Google Inc. 13 | Jake Voytko 14 | Yuki Yugui Sonoda 15 | -------------------------------------------------------------------------------- /go/tools/builders/path_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package main 4 | 5 | import ( 6 | "runtime" 7 | "syscall" 8 | ) 9 | 10 | func processPath(path string) (string, error) { 11 | if runtime.GOOS != "windows" { 12 | return path, nil 13 | } 14 | 15 | var buf [258]uint16 16 | up, err := syscall.UTF16PtrFromString(path) 17 | if err != nil { 18 | return path, err 19 | } 20 | _, err = syscall.GetShortPathName(up, &buf[0], 258) 21 | if err != nil { 22 | return path, err 23 | } 24 | return syscall.UTF16ToString(buf[:]), nil 25 | } 26 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/gs.go: -------------------------------------------------------------------------------- 1 | package proto 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/bazelbuild/rules_go/examples/proto/gostyle" 7 | lib_proto "github.com/bazelbuild/rules_go/examples/proto/lib/lib_proto" 8 | ) 9 | 10 | func DoGoStyle(g *gostyle.GoStyleObject) error { 11 | if g == nil { 12 | return fmt.Errorf("got nil") 13 | } 14 | return nil 15 | } 16 | 17 | func DoMultiProtos(a *lib_proto.LibObject, b *lib_proto.LibObject2) error { 18 | if a == nil || b == nil { 19 | return fmt.Errorf("got nil") 20 | } 21 | return nil 22 | } 23 | -------------------------------------------------------------------------------- /go/tools/internal/txtar/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "txtar", 5 | srcs = ["archive.go"], 6 | importpath = "github.com/bazelbuild/rules_go/go/tools/internal/txtar", 7 | visibility = ["//go/tools:__subpackages__"], 8 | ) 9 | 10 | go_test( 11 | name = "txtar_test", 12 | srcs = ["archive_test.go"], 13 | embed = [":txtar"], 14 | ) 15 | 16 | alias( 17 | name = "go_default_library", 18 | actual = ":txtar", 19 | visibility = ["//go/tools:__subpackages__"], 20 | ) 21 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pthread_flag/cgo_pthread_flag.go: -------------------------------------------------------------------------------- 1 | package cgo_pthread_flag 2 | 3 | /* 4 | #include 5 | 6 | void* f(void* p) { 7 | *(int*) p = 42; 8 | return NULL; 9 | } 10 | 11 | int callFInBackground() { 12 | int x; 13 | pthread_t thread; 14 | pthread_create(&thread, NULL, f, &x); 15 | pthread_join(thread, NULL); 16 | return x; 17 | } 18 | */ 19 | import "C" 20 | 21 | // Wrapper for callFInBackground. We don't support using Cgo directly from 22 | // tests yet. 23 | func callFFromGo() int { 24 | return int(C.callFInBackground()) 25 | } 26 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/example_command/generate_test.bzl: -------------------------------------------------------------------------------- 1 | def _generate_script_impl(ctx): 2 | script_file = ctx.actions.declare_file(ctx.label.name + ".bash") 3 | ctx.actions.write(output = script_file, is_executable = True, content = """ 4 | {0} 5 | """.format(ctx.file.binary.short_path)) 6 | return struct( 7 | files = depset([script_file]), 8 | ) 9 | 10 | generate_script = rule( 11 | _generate_script_impl, 12 | attrs = { 13 | "binary": attr.label( 14 | allow_single_file = True, 15 | ), 16 | }, 17 | ) 18 | -------------------------------------------------------------------------------- /tests/core/nogo/config/README.rst: -------------------------------------------------------------------------------- 1 | Nogo configuration 2 | ================== 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _go_binary: /docs/go/core/rules.md#_go_binary 6 | .. _#1850: https://github.com/bazelbuild/rules_go/issues/1850 7 | .. _#2470: https://github.com/bazelbuild/rules_go/issues/2470 8 | 9 | Tests that verify nogo_ works on targets compiled in non-default configurations. 10 | 11 | .. contents:: 12 | 13 | config_test 14 | ----------- 15 | 16 | Verifies that a `go_binary`_ can be built in non-default configurations with 17 | nogo. Verifies `#1850`_, `#2470`_. 18 | -------------------------------------------------------------------------------- /tests/core/stdlib/README.rst: -------------------------------------------------------------------------------- 1 | stdlib functionality 2 | ==================== 3 | 4 | buildid_test 5 | ------------ 6 | 7 | Checks that the ``stdlib`` rule builds archives without Go build ids. 8 | 9 | Go build ids are used for caching within ``go build``; they are not needed by 10 | Bazel, which has its own caching mechanism. The build id is influenced by 11 | all inputs to the build, including cgo environment variables. Since these 12 | variables may include sandbox paths, they can make the build id 13 | non-reproducible, even though they don't affect the final binary. 14 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/grpc/my_svc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package examples.svc; 4 | 5 | option go_package = "github.com/bazelbuild/rules_go/examples/proto/grpc/my_svc_proto"; 6 | 7 | import "tests/legacy/examples/proto/lib/lib.proto"; 8 | import "google/protobuf/any.proto"; 9 | import "google/protobuf/empty.proto"; 10 | 11 | message GetRequest { 12 | examples.lib.LibObject obj = 1; 13 | } 14 | 15 | service MyService { 16 | rpc Get(GetRequest) returns (google.protobuf.Empty); 17 | rpc Put(google.protobuf.Any) returns (examples.lib.LibObject); 18 | } 19 | -------------------------------------------------------------------------------- /tests/legacy/test_chdir/remote.bzl: -------------------------------------------------------------------------------- 1 | def _test_chdir_remote_impl(ctx): 2 | ctx.file("WORKSPACE", """workspace("test_chdir_remote")""") 3 | ctx.file("BUILD.bazel", "") 4 | for f in ["BUILD.bazel", "data_test.go", "data.txt"]: 5 | input = Label("@io_bazel_rules_go//tests/legacy/test_chdir:{}".format(f)) 6 | ctx.template("sub/" + f, input) 7 | 8 | _test_chdir_remote = repository_rule( 9 | implementation = _test_chdir_remote_impl, 10 | attrs = {}, 11 | ) 12 | 13 | def test_chdir_remote(): 14 | _test_chdir_remote(name = "test_chdir_remote") 15 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/gogo/gogo_test.go: -------------------------------------------------------------------------------- 1 | package gogo_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bazelbuild/rules_go/examples/proto/gogo" 7 | ) 8 | 9 | func TestGoString(t *testing.T) { 10 | p := gogo.Value{Item: 20} 11 | got := p.GoString() 12 | expect := "&gogo.Value{Item: 20,\n}" 13 | if got != expect { 14 | t.Errorf("got %q, expect %q", got, expect) 15 | } 16 | } 17 | 18 | func TestSize(t *testing.T) { 19 | p := gogo.Value{Item: 20} 20 | got := p.Size() 21 | expect := 2 22 | if got != expect { 23 | t.Errorf("got %v, expect %v", got, expect) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/core/go_plugin/README.rst: -------------------------------------------------------------------------------- 1 | Basic -buildmode=plugin functionality 2 | ===================================== 3 | 4 | .. _go_binary: /docs/go/core/rules.md#_go_binary 5 | 6 | Tests to ensure the basic features of go_binary with linkmode="plugin" are 7 | working as expected. 8 | 9 | all_test 10 | -------- 11 | 12 | 1. Test that a go_binary_ rule can write its shared object file with a custom 13 | name in the package directory (not the mode directory). 14 | 15 | 2. Test that a plugin built using a go_binary_ rule can be loaded by a Go 16 | program and that its symbols are working as expected. 17 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/dep/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 2 | load("@rules_proto//proto:defs.bzl", "proto_library") 3 | 4 | proto_library( 5 | name = "useful_proto", 6 | srcs = ["useful.proto"], 7 | visibility = ["//visibility:public"], 8 | deps = [ 9 | "@com_google_protobuf//:duration_proto", 10 | ], 11 | ) 12 | 13 | go_proto_library( 14 | name = "useful_go_proto", 15 | importpath = "github.com/bazelbuild/rules_go/examples/proto/dep", 16 | proto = ":useful_proto", 17 | visibility = ["//visibility:public"], 18 | ) 19 | -------------------------------------------------------------------------------- /tests/legacy/extldflags_rpath/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | 3 | go_binary( 4 | name = "extldflags_rpath", 5 | srcs = ["main.go"], 6 | gc_linkopts = [ 7 | "-linkmode", 8 | "external", 9 | "-extldflags", 10 | "-Wl,-rpath -Wl,/foo", 11 | "-extldflags", 12 | "-Wl,-rpath -Wl,/bar", 13 | ], 14 | ) 15 | 16 | sh_test( 17 | name = "extldflags_rpath_test", 18 | size = "small", 19 | srcs = ["extldflags_rpath_test.sh"], 20 | args = ["$(location :extldflags_rpath)"], 21 | data = [":extldflags_rpath"], 22 | ) 23 | -------------------------------------------------------------------------------- /tests/core/cgo/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #if !defined(RULES_GO_C) || !defined(RULES_GO_CPP) || defined(RULES_GO_CXX) 6 | #error This is a C file, only RULES_GO_C and RULES_GO_CPP should be defined. 7 | #endif 8 | 9 | #if !defined(GENERATED_COPTS) || !defined(GENERATED_CPPOPTS) || defined(GENERATED_CXXOPTS) 10 | #error Generated headers should be correctly included 11 | #endif 12 | 13 | int add_c(int a, int b) { 14 | int $ = 0; 15 | int sum = a + b; 16 | sum += DOLLAR_SIGN_C; 17 | sum += DOLLAR_SIGN_CPP; 18 | return sum; 19 | } 20 | -------------------------------------------------------------------------------- /docs/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//docs:doc_helpers.bzl", "stardoc_with_diff_test", "update_docs") 2 | 3 | # For each doc file, generate MD from bzl_library, then perform diff test 4 | stardoc_with_diff_test( 5 | bzl_library_target = "//docs/go/extras:extras", 6 | out_label = "//docs/go/extras:extras.md", 7 | rule_template = "rule_body.vm", 8 | ) 9 | 10 | stardoc_with_diff_test( 11 | bzl_library_target = "//docs/go/core:rules", 12 | out_label = "//docs/go/core:rules.md", 13 | rule_template = "rule_body.vm", 14 | ) 15 | 16 | # Update MD in local source tree 17 | update_docs( 18 | name = "update", 19 | ) 20 | -------------------------------------------------------------------------------- /tests/core/nogo/custom/README.rst: -------------------------------------------------------------------------------- 1 | Custom nogo analyzers 2 | ===================== 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _go_library: /docs/go/core/rules.md#_go_library 6 | 7 | Tests to ensure that custom `nogo`_ analyzers run and detect errors. 8 | 9 | .. contents:: 10 | 11 | custom_test 12 | ----------- 13 | Verifies that custom analyzers print errors and fail a `go_library`_ build when 14 | a configuration file is not provided, and that analyzers with the same package 15 | name do not conflict. Also checks that custom analyzers can be configured to 16 | apply only to certain file paths using a custom configuration file. 17 | -------------------------------------------------------------------------------- /tests/legacy/extldflags_rpath/extldflags_rpath_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ $# -ne 1 ]; then 4 | echo "usage: $0 binaryfile" >&1 5 | exit 1 6 | fi 7 | 8 | binaryfile=$1 9 | os=$(uname) 10 | case $os in 11 | Linux) 12 | output=$(readelf --dynamic "$binaryfile") 13 | ;; 14 | Darwin) 15 | output=$(otool -l "$binaryfile") 16 | ;; 17 | *) 18 | echo "unsupported platform: $os" >&1 19 | exit 1 20 | esac 21 | 22 | for path in /foo /bar ; do 23 | if ! echo "$output" | grep --quiet "$path" ; then 24 | echo "$binaryfile: could not find $path in rpaths" >&1 25 | exit 1 26 | fi 27 | done 28 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/foo_test.go: -------------------------------------------------------------------------------- 1 | package foo_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/bar" 7 | ) 8 | 9 | func TestBar(t *testing.T) { 10 | Equal(t, "Bar", bar.Bar) 11 | } 12 | 13 | func TestBaz(t *testing.T) { 14 | Equal(t, "Baz", bar.Baz) 15 | } 16 | 17 | func TestQux(t *testing.T) { 18 | Equal(t, "Qux", bar.Qux) 19 | } 20 | 21 | func Equal(t *testing.T, expected string, actual string) bool { 22 | if expected != actual { 23 | t.Errorf("Not equal: \n"+ 24 | "expected: %s\n"+ 25 | "actual : %s", expected, actual) 26 | } 27 | return true 28 | } 29 | -------------------------------------------------------------------------------- /docs/go/core/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | exports_files([ 4 | "rules.md", 5 | "rules.bzl", 6 | ]) 7 | 8 | bzl_library( 9 | name = "rules", 10 | srcs = ["rules.bzl"], 11 | visibility = ["//visibility:public"], 12 | deps = [ 13 | "//go/private:rpath", 14 | "//go/private/rules:binary", 15 | "//go/private/rules:cross", 16 | "//go/private/rules:library", 17 | "//go/private/rules:library.bzl", 18 | "//go/private/rules:source", 19 | "//go/private/rules:test", 20 | "//go/private/tools:path", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /tests/core/cgo/add.cpp: -------------------------------------------------------------------------------- 1 | #include "add.h" 2 | #include 3 | #include 4 | 5 | #if !defined(RULES_GO_CPP) || !defined(RULES_GO_CXX) || defined(RULES_GO_C) 6 | #error This is a C++ file, only RULES_GO_CXX and RULES_GO_CPP should be defined. 7 | #endif 8 | 9 | #if !defined(GENERATED_CPPOPTS) || !defined(GENERATED_CXXOPTS) || defined(GENERATED_COPTS) 10 | #error Generated headers should be correctly included 11 | #endif 12 | 13 | int add_cpp(int a, int b) { 14 | int $ = 0; 15 | int sum = a + b; 16 | sum += DOLLAR_SIGN_CXX; 17 | sum += DOLLAR_SIGN_CPP; 18 | return sum; 19 | } 20 | -------------------------------------------------------------------------------- /tests/core/go_plugin_with_proto_library/README.rst: -------------------------------------------------------------------------------- 1 | Go Plugin supporting protobufs 2 | ============================== 3 | 4 | .. _go_binary: /go/core.rst#_go_binary 5 | 6 | Tests to ensure a protobuf can be included into a plugin and host. 7 | 8 | all_test 9 | -------- 10 | 11 | 1. Test that a go_binary_ rule can write its shared object file with a custom 12 | name in the package directory (not the mode directory) when the plugin 13 | depends on a protobuf. 14 | 15 | 2. Test that a plugin with a protobuf dependency built using a go_binary_ rule 16 | can be loaded by a Go program and that its symbols are working as expected. 17 | -------------------------------------------------------------------------------- /tests/legacy/examples/bindata/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | load("@io_bazel_rules_go//extras:bindata.bzl", "bindata") 3 | 4 | bindata( 5 | name = "data", 6 | srcs = glob(["data/*"]), 7 | package = "bindata", 8 | strip_external = True, 9 | ) 10 | 11 | go_library( 12 | name = "go_default_library", 13 | srcs = [":data"], 14 | importpath = "github.com/bazelbuild/rules_go/examples/bindata", 15 | ) 16 | 17 | go_test( 18 | name = "go_default_test", 19 | size = "small", 20 | srcs = ["bindata_test.go"], 21 | embed = [":go_default_library"], 22 | ) 23 | -------------------------------------------------------------------------------- /tests/integration/reproducibility/README.rst: -------------------------------------------------------------------------------- 1 | Reproducibility 2 | 3 | reproducibility_test 4 | -------------------- 5 | Verifies that the files generated when building a set of targets are identical, 6 | even when built from multiple copies of the same workspace. 7 | 8 | Currently covers pure ``go_binary`` targets and a cgo ``go_binary`` with 9 | ``linkmode = "c-archive"``. 10 | 11 | TODO: cover more modes. Currently, it seems like a cgo ``go_binary`` that 12 | produces an executable is not reproducible on macOS. This is most likely 13 | due to the external linker, since all the inputs to the linker are identical. 14 | Needs investigation. 15 | -------------------------------------------------------------------------------- /tests/core/importmap/README.rst: -------------------------------------------------------------------------------- 1 | Import maps 2 | =========== 3 | 4 | .. _go_library: /docs/go/core/rules.md#_go_library 5 | 6 | Tests to ensure that importmap is working as expected. 7 | 8 | .. contents:: 9 | 10 | importmap_test 11 | -------------- 12 | 13 | Test that importmap declarations on go_library_ are propagated and obeyed. 14 | This builds libraries using `src.go `_ as multiple outputs with the differing importpaths, 15 | adds identical importmap declarations and then checks that the libraries can be correctly imported 16 | without colliding through differing intermediate libraries into `the main test `_. 17 | -------------------------------------------------------------------------------- /tests/legacy/cgo_multi_dir/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | # TODO(#746) exclude because gazelle does not recognise the rule below 4 | # gazelle:exclude bar 5 | # gazelle:exclude foo 6 | 7 | go_test( 8 | name = "go_default_test", 9 | size = "small", 10 | srcs = ["cgo_multi_dir_test.go"], 11 | embed = [":go_default_library"], 12 | ) 13 | 14 | go_library( 15 | name = "go_default_library", 16 | srcs = [ 17 | "bar/bar.go", 18 | "foo/foo.go", 19 | ], 20 | cgo = True, 21 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_multi_dir", 22 | ) 23 | -------------------------------------------------------------------------------- /tests/core/go_binary/stamp_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os/exec" 5 | "strings" 6 | "testing" 7 | 8 | "github.com/bazelbuild/rules_go/go/tools/bazel" 9 | ) 10 | 11 | func TestStamp(t *testing.T) { 12 | bin, ok := bazel.FindBinary("tests/core/go_binary", "stamp_bin") 13 | if !ok { 14 | t.Error("could not find stamp_bin") 15 | } 16 | out, err := exec.Command(bin).Output() 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | 21 | got := strings.TrimSpace(string(out)) 22 | want := `Bin=Bin 23 | Embed=Embed 24 | DepSelf=DepSelf 25 | DepBin=DepBin` 26 | if got != want { 27 | t.Errorf("got:\n%s\nwant:\n%s", got, want) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/legacy/test_chdir/data_test.go: -------------------------------------------------------------------------------- 1 | package test_chdir 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | ) 8 | 9 | const file = "data.txt" 10 | 11 | func init() { 12 | _, err := os.Stat(file) 13 | if err != nil { 14 | log.Fatalf("in init(), could not stat %s: %v", file, err) 15 | } 16 | } 17 | 18 | func TestMain(m *testing.M) { 19 | _, err := os.Stat(file) 20 | if err != nil { 21 | log.Fatalf("in TestMain(), could not stat %s: %v", file, err) 22 | } 23 | os.Exit(m.Run()) 24 | } 25 | 26 | func TestLocal(t *testing.T) { 27 | _, err := os.Stat(file) 28 | if err != nil { 29 | t.Errorf("could not stat %s: %v", file, err) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /go/private/tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | filegroup( 4 | name = "all_rules", 5 | srcs = glob(["**/*.bzl"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | filegroup( 10 | name = "all_files", 11 | testonly = True, 12 | srcs = glob(["**"]), 13 | visibility = ["//visibility:public"], 14 | ) 15 | 16 | bzl_library( 17 | name = "path", 18 | srcs = ["path.bzl"], 19 | visibility = [ 20 | "//docs:__subpackages__", 21 | "//go:__subpackages__", 22 | ], 23 | deps = [ 24 | "//go/private:common", 25 | "//go/private:providers", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /tests/core/go_test/example_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "fmt" 4 | 5 | var Expected = "Expected" 6 | 7 | func ExampleHelloWorld() { 8 | fmt.Println("Hello Example!") 9 | fmt.Println("expected: " + Expected) 10 | fmt.Println("got: " + Got) 11 | // Output: 12 | // Hello Example! 13 | // expected: Example 14 | // got: Example 15 | } 16 | 17 | func ExampleDontTestMe() { 18 | panic("Dont Test Me!") 19 | } 20 | 21 | func ExampleTestEmptyOutput() { 22 | if false { 23 | fmt.Println("Say something!") 24 | } 25 | // Output: 26 | } 27 | 28 | func ExampleTestQuoting() { 29 | fmt.Printf(`"quotes are handled"`) 30 | // Output: 31 | // "quotes are handled" 32 | } 33 | -------------------------------------------------------------------------------- /tests/core/go_plugin/all_test.go: -------------------------------------------------------------------------------- 1 | package main_test 2 | 3 | import ( 4 | "os" 5 | "plugin" 6 | "testing" 7 | ) 8 | 9 | const HelloWorld = "Hello, world!" 10 | 11 | func TestPluginCreated(t *testing.T) { 12 | _, err := os.Stat("plugin.so") 13 | if err != nil { 14 | t.Error(err) 15 | } 16 | } 17 | 18 | func TestPluginWorks(t *testing.T) { 19 | p, err := plugin.Open("plugin.so") 20 | if err != nil { 21 | t.Error(err) 22 | } 23 | 24 | f, err := p.Lookup("Hi") 25 | if err != nil { 26 | t.Error(err) 27 | } 28 | 29 | helloWorld := f.(func() string)() 30 | if helloWorld != HelloWorld { 31 | t.Errorf("expected %#v, got %#v", HelloWorld, helloWorld) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/core/go_proto_library_importmap/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_test") 2 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 3 | load("@rules_proto//proto:defs.bzl", "proto_library") 4 | 5 | proto_library( 6 | name = "foo_proto", 7 | srcs = ["foo.proto"], 8 | ) 9 | 10 | go_proto_library( 11 | name = "foo_go_proto", 12 | importmap = "never/gonna/give/you/up", 13 | importpath = "github.com/bazelbuild/rules_go/tests/core/go_proto_library_importmap", 14 | proto = ":foo_proto", 15 | ) 16 | 17 | go_test( 18 | name = "importmap_test", 19 | srcs = ["importmap_test.go"], 20 | deps = [":foo_go_proto"], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/crypto_test_dl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef SO 5 | #error No SO path defined 6 | #endif 7 | 8 | int main() { 9 | void* handle = dlopen(SO, RTLD_NOW); 10 | if (!handle) { 11 | printf("dlopen: %s\n", dlerror()); 12 | return 1; 13 | } 14 | 15 | typedef void (*gofn_t)(); 16 | gofn_t gofn = (gofn_t)dlsym(handle, "GoFn"); 17 | const char* dlsym_error = dlerror(); 18 | if (dlsym_error) { 19 | printf("dlsym: %s\n", dlerror()); 20 | dlclose(handle); 21 | return 1; 22 | } 23 | 24 | gofn(); 25 | 26 | if (dlclose(handle)) { 27 | printf("dlclose: %s\n", dlerror()); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/go_googleapis-directives.patch: -------------------------------------------------------------------------------- 1 | diff -urN b/BUILD.bazel c/BUILD.bazel 2 | --- b/BUILD.bazel 1969-12-31 16:00:00 3 | +++ c/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000 4 | @@ -0,0 +1,6 @@ 5 | +# gazelle:go_naming_convention import_alias 6 | +# gazelle:proto package 7 | +# gazelle:proto_group go_package 8 | +# gazelle:exclude gapic 9 | +# gazelle:exclude third_party 10 | +# gazelle:exclude google/example/endpointsapis/goapp 11 | diff -urN b/google/BUILD.bazel c/google/BUILD.bazel 12 | --- b/google/BUILD.bazel 1969-12-31 16:00:00 13 | +++ c/google/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000 14 | @@ -0,0 +1 @@ 15 | +# gazelle:prefix google.golang.org/genproto/googleapis 16 | -------------------------------------------------------------------------------- /tests/core/go_library/def.bzl: -------------------------------------------------------------------------------- 1 | def _embedsrcs_files_impl(ctx): 2 | name = ctx.attr.name 3 | dir = ctx.actions.declare_directory(name) 4 | args = [dir.path] + ctx.attr.files 5 | ctx.actions.run( 6 | outputs = [dir], 7 | executable = ctx.executable._gen, 8 | arguments = args, 9 | ) 10 | return [DefaultInfo(files = depset([dir]))] 11 | 12 | embedsrcs_files = rule( 13 | implementation = _embedsrcs_files_impl, 14 | attrs = { 15 | "files": attr.string_list(), 16 | "_gen": attr.label( 17 | default = ":gen_embedsrcs_files", 18 | executable = True, 19 | cfg = "exec", 20 | ), 21 | }, 22 | ) 23 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/example_command/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | load(":generate_test.bzl", "generate_script") 3 | 4 | package( 5 | default_visibility = ["//visibility:public"], 6 | ) 7 | 8 | go_binary( 9 | name = "example_command", 10 | srcs = ["main.go"], 11 | deps = [ 12 | "//tests/legacy/examples/cgo:go_default_library", 13 | ], 14 | ) 15 | 16 | generate_script( 17 | name = "example_command_script", 18 | binary = ":example_command", 19 | ) 20 | 21 | sh_test( 22 | name = "example_command_test", 23 | size = "small", 24 | srcs = [":example_command_script"], 25 | data = [":example_command"], 26 | ) 27 | -------------------------------------------------------------------------------- /tests/core/nogo/custom/flags/README.rst: -------------------------------------------------------------------------------- 1 | Custom nogo analyzer flags 2 | ===================== 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _go_library: /docs/go/core/rules.md#_go_library 6 | 7 | Tests to ensure that custom `nogo`_ analyzers that consume flags can be 8 | supplied those flags via nono config. 9 | 10 | .. contents:: 11 | 12 | flags_test 13 | ----------- 14 | Verifies that a simple custom analyzer's behavior can be modified by setting 15 | its analyzer flags in the nogo driver, and that these flags can be provided to 16 | the driver via the nogo config `analyzer_flags` field. Also checks that 17 | invalid flags as defined by the `flag` package cause the driver to immediately 18 | return an error. 19 | 20 | -------------------------------------------------------------------------------- /tests/core/importmap/lib.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib 17 | 18 | var Value = "Unstamped" 19 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/import_example.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | import ( 4 | //#cgo LDFLAGS: -lm -lversion -lc_version -L${SRCDIR}/cc_dependency 5 | //#cgo CPPFLAGS: -I${SRCDIR}/../.. 6 | //#include 7 | //#include "use_exported.h" 8 | //#include "cc_dependency/version.h" 9 | "C" 10 | 11 | "github.com/bazelbuild/rules_go/examples/cgo/sub" 12 | ) 13 | 14 | // Nsqrt returns the square root of n. 15 | func Nsqrt(n int) int { 16 | return int(sub.Floor(float64(C.sqrt(C.double(n))))) 17 | } 18 | 19 | func PrintGoVersion() { 20 | C.PrintGoVersion() 21 | } 22 | 23 | func printCXXVersion() { 24 | C.PrintCXXVersion() 25 | } 26 | 27 | func ReturnDefined() int { 28 | return int(C.DEFINED_IN_COPTS) 29 | } 30 | -------------------------------------------------------------------------------- /tests/core/cgo/cgo_link_dep.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | int f() { return 42; } 16 | -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | platform: 3 | - centos7 4 | - debian10 5 | - ubuntu2004 6 | - macos 7 | - windows 8 | tasks: 9 | verify_targets: 10 | name: Verify build targets 11 | platform: ${{ platform }} 12 | build_targets: 13 | - '@rules_go//go/tools/bzltestutil/...' 14 | bcr_test_module: 15 | module_path: tests/bcr 16 | matrix: 17 | platform: 18 | - centos7 19 | - debian10 20 | - ubuntu2004 21 | - macos 22 | - windows 23 | tasks: 24 | run_test_module: 25 | name: Run test module 26 | platform: ${{ platform }} 27 | build_targets: 28 | - //... 29 | - '@go_sdk//...' 30 | test_targets: 31 | - //... 32 | -------------------------------------------------------------------------------- /tests/core/go_test/data_test_dep.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package data_test_dep 16 | -------------------------------------------------------------------------------- /tests/core/go_test/data_test_embed.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package data_test_dep 16 | -------------------------------------------------------------------------------- /tests/core/go_test/lib.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib 17 | 18 | import "C" 19 | 20 | var Got = "Got" 21 | -------------------------------------------------------------------------------- /tests/core/runfiles/bin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | func main() {} 18 | -------------------------------------------------------------------------------- /tests/core/starlark/packagedriver/fixtures/c/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "go_default_library", 5 | srcs = ["c.go"], 6 | importpath = "example.com/c", 7 | visibility = ["//tests/core/starlark/packagedriver:__subpackages__"], 8 | deps = [ 9 | "//tests/core/starlark/packagedriver/fixtures/a:go_default_library", 10 | "//tests/core/starlark/packagedriver/fixtures/b:go_default_library", 11 | ], 12 | ) 13 | 14 | go_test( 15 | name = "go_default_test", 16 | srcs = ["c_test.go"], 17 | embed = [":go_default_library"], 18 | tags = ["manual"], 19 | visibility = ["//tests/core/starlark/packagedriver:__subpackages__"], 20 | ) 21 | -------------------------------------------------------------------------------- /go/tools/gopackagesdriver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_binary", "go_library") 2 | 3 | go_library( 4 | name = "gopackagesdriver_lib", 5 | srcs = [ 6 | "bazel.go", 7 | "bazel_json_builder.go", 8 | "build_context.go", 9 | "driver_request.go", 10 | "flatpackage.go", 11 | "json_packages_driver.go", 12 | "main.go", 13 | "packageregistry.go", 14 | "utils.go", 15 | ], 16 | importpath = "github.com/bazelbuild/rules_go/go/tools/gopackagesdriver", 17 | visibility = ["//visibility:private"], 18 | ) 19 | 20 | go_binary( 21 | name = "gopackagesdriver", 22 | embed = [":gopackagesdriver_lib"], 23 | visibility = ["//visibility:public"], 24 | ) 25 | -------------------------------------------------------------------------------- /go/tools/fetch_repo/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_binary", "go_library", "go_test") 2 | 3 | go_binary( 4 | name = "fetch_repo", 5 | embed = [":go_default_library"], 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | go_library( 10 | name = "go_default_library", 11 | srcs = ["main.go"], 12 | importpath = "github.com/bazelbuild/rules_go/go/tools/fetch_repo", 13 | visibility = ["//visibility:private"], 14 | deps = ["@org_golang_x_tools//go/vcs:go_default_library"], 15 | ) 16 | 17 | go_test( 18 | name = "go_default_test", 19 | size = "small", 20 | srcs = ["fetch_repo_test.go"], 21 | embed = [":go_default_library"], 22 | deps = ["@org_golang_x_tools//go/vcs:go_default_library"], 23 | ) 24 | -------------------------------------------------------------------------------- /tests/legacy/slash_names/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | # TODO(#746) exclude because gazelle does not recognise the rule below 4 | # gazelle:exclude a 5 | # gazelle:exclude b 6 | 7 | go_library( 8 | name = "a/pkg", 9 | srcs = ["a/pkg/pkg.go"], 10 | importpath = "github.com/bazelbuild/rules_go/tests/slash_names/a/pkg", 11 | ) 12 | 13 | go_library( 14 | name = "b/pkg", 15 | srcs = ["b/pkg/pkg.go"], 16 | importpath = "github.com/bazelbuild/rules_go/tests/slash_names/b/pkg", 17 | ) 18 | 19 | go_test( 20 | name = "go_default_test", 21 | size = "small", 22 | srcs = ["slash_test.go"], 23 | deps = [ 24 | ":a/pkg", 25 | ":b/pkg", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /tests/core/go_library/import_alias_b.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package b 16 | 17 | const B = "import_alias/b" 18 | -------------------------------------------------------------------------------- /tests/core/nogo/generics/README.rst: -------------------------------------------------------------------------------- 1 | nogo analyzers run against code using generics 2 | ============================================== 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _buildssa: https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/buildssa 6 | .. _nilness: https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/nilness 7 | 8 | Tests to ensure that `nogo`_ analyzers that run on code using generics get correct 9 | type instantiation information. 10 | 11 | .. contents:: 12 | 13 | generics_test 14 | ------------- 15 | 16 | Verifies that code using generic types gets loaded including all type instantiation 17 | information, so that analyzers based on the `buildssa`_ analyzer (such as `nilness`_) get 18 | a complete picture of all types in the code. 19 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/lib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 2 | load("@rules_proto//proto:defs.bzl", "proto_library") 3 | 4 | proto_library( 5 | name = "lib_proto", 6 | srcs = [ 7 | "lib.proto", 8 | "lib2.proto", 9 | ], 10 | visibility = ["//visibility:public"], 11 | deps = [ 12 | "//tests/legacy/examples/proto/dep:useful_proto", 13 | ], 14 | ) 15 | 16 | go_proto_library( 17 | name = "lib_go_proto", 18 | importpath = "github.com/bazelbuild/rules_go/examples/proto/lib/lib_proto", 19 | proto = ":lib_proto", 20 | visibility = ["//visibility:public"], 21 | deps = [ 22 | "//tests/legacy/examples/proto/dep:useful_go_proto", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /tests/core/go_library/import_alias_a_v2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package a 16 | 17 | const A = "import_alias/a/v2" 18 | -------------------------------------------------------------------------------- /tests/core/transition/README.rst: -------------------------------------------------------------------------------- 1 | Misc configuration transition tests 2 | =================================== 3 | 4 | .. _go_binary: /docs/go/core/rules.md#_go_binary 5 | .. _go_test: /docs/go/core/rules.md#_go_test 6 | 7 | Tests that check that configuration transitions for `go_binary`_ and `go_test`_ 8 | are working correctly. 9 | 10 | Most tests for specific attributes are in other directories, for example, 11 | ``c_linkmodes``, ``cross``, ``nogo``, ``race``. This directory covers 12 | transition-related stuff that doesn't fit anywhere else. 13 | 14 | cmdline_test 15 | ------------ 16 | Tests that build settings can be set with flags on the command line. The test 17 | builds a target with and without a command line flag and verifies the output 18 | is different. 19 | -------------------------------------------------------------------------------- /tests/legacy/examples/monobuild/lib1/lib1.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib1 17 | 18 | func Name() string { 19 | return "I am lib 1" 20 | } 21 | -------------------------------------------------------------------------------- /tests/legacy/examples/monobuild/lib2/lib2.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib2 17 | 18 | func Description() string { 19 | return "I am lib 2" 20 | } 21 | -------------------------------------------------------------------------------- /tests/core/go_binary/pie_darwin_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "debug/macho" 5 | "fmt" 6 | "os" 7 | "testing" 8 | 9 | "github.com/bazelbuild/rules_go/go/tools/bazel" 10 | ) 11 | 12 | func openMachO(dir, bin string) (*macho.File, error) { 13 | bin, ok := bazel.FindBinary(dir, bin) 14 | if !ok { 15 | return nil, fmt.Errorf("could not find binary: %s", bin) 16 | } 17 | 18 | f, err := os.Open(bin) 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | return macho.NewFile(f) 24 | } 25 | 26 | func TestPIE(t *testing.T) { 27 | m, err := openMachO("tests/core/go_binary", "hello_pie_bin") 28 | if err != nil { 29 | t.Fatal(err) 30 | } 31 | 32 | if m.Flags&macho.FlagPIE == 0 { 33 | t.Error("ELF binary is not position-independent.") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/core/go_plugin_with_proto_library/all_test.go: -------------------------------------------------------------------------------- 1 | package main_test 2 | 3 | import ( 4 | "go_plugin_with_proto_library/validate" 5 | "os" 6 | "plugin" 7 | "testing" 8 | ) 9 | 10 | const RuleName = "test" 11 | 12 | func TestPluginCreated(t *testing.T) { 13 | _, err := os.Stat("plugin.so") 14 | if err != nil { 15 | t.Error(err) 16 | } 17 | } 18 | 19 | func TestPluginWorks(t *testing.T) { 20 | p, err := plugin.Open("plugin.so") 21 | if err != nil { 22 | t.Error(err) 23 | return 24 | } 25 | 26 | symProto, err := p.Lookup("SomeProto") 27 | if err != nil { 28 | t.Error(err) 29 | return 30 | } 31 | 32 | proto := symProto.(*validate.MessageRules) 33 | if *proto.Name != RuleName { 34 | t.Errorf("expected %#v, got %#v", RuleName, proto.Name) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/asm_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // +build arm64 16 | 17 | TEXT ·asm(SB),$0-0 18 | MOVD $75,R0 19 | MOVD R0,RET(FP) 20 | RET 21 | -------------------------------------------------------------------------------- /tests/core/go_test/wrapped_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package wrapped_test 16 | 17 | import "testing" 18 | 19 | func Test(t *testing.T) {} 20 | -------------------------------------------------------------------------------- /tests/integration/README.rst: -------------------------------------------------------------------------------- 1 | Integration tests 2 | ================= 3 | 4 | This folder is intended to hold larger scale test that check that rules_go 5 | works correctly in the real world, rather than in isolated single feature 6 | tests. 7 | 8 | If the unit tests were correct and exhaustive this directory should in theory 9 | be redundant, but in practice it helps catch many issues and points to places 10 | where more unit tests are needed. 11 | 12 | Contents 13 | -------- 14 | 15 | .. Child list start 16 | 17 | * `Gazelle functionality `_ 18 | * `Popular repository tests `_ 19 | * `Reproducibility `_ 20 | * `Functionality related to @go_googleapis `_ 21 | 22 | .. Child list end 23 | 24 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/gostyle/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 2 | load("@rules_proto//proto:defs.bzl", "proto_library") 3 | 4 | genrule( 5 | name = "copy", 6 | srcs = ["gostyle.proto"], 7 | outs = ["gostyle.gen.proto"], 8 | cmd = "sed -e 's/ano.proto/any.proto/' $< > $@", 9 | ) 10 | 11 | proto_library( 12 | name = "gostyle_proto", 13 | srcs = [":copy"], 14 | visibility = ["//visibility:public"], 15 | deps = [ 16 | "@com_google_protobuf//:any_proto", 17 | ], 18 | ) 19 | 20 | go_proto_library( 21 | name = "gostyle_go_proto", 22 | importpath = "github.com/bazelbuild/rules_go/examples/proto/gostyle", 23 | proto = ":gostyle_proto", 24 | visibility = ["//visibility:public"], 25 | ) 26 | -------------------------------------------------------------------------------- /tests/core/importmap/import.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package importmap 17 | 18 | import ( 19 | "lib" 20 | ) 21 | 22 | func Get() string { 23 | return lib.Value 24 | } 25 | -------------------------------------------------------------------------------- /tests/core/cgo/cgo_ref.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cgo_link 16 | 17 | // int f(); 18 | import "C" 19 | 20 | func F() int { return int(C.f()) } 21 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "cgo_pure", 5 | srcs = [ 6 | "cgo.c", 7 | "cgo.go", 8 | "cgo_no_tag.go", 9 | "pure.go", 10 | ], 11 | cgo = True, 12 | importpath = "github.com/bazelbuild/rules_go/tests/cgo_pure", 13 | ) 14 | 15 | go_test( 16 | name = "cgo_test", 17 | size = "small", 18 | srcs = ["cgo_pure_test.go"], 19 | x_defs = { 20 | "Expect": "2", 21 | }, 22 | deps = [":cgo_pure"], 23 | ) 24 | 25 | go_test( 26 | name = "pure_test", 27 | size = "small", 28 | srcs = ["cgo_pure_test.go"], 29 | pure = "on", 30 | x_defs = { 31 | "Expect": "1", 32 | }, 33 | deps = [":cgo_pure"], 34 | ) 35 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/add_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | TEXT ·add(SB), $0 16 | MOVD x+0(FP), R0 17 | MOVD y+8(FP), R1 18 | ADD R0, R1, R0 19 | MOVD R0, ret+16(FP) 20 | RET 21 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/sub_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | TEXT ·sub(SB), $0 16 | MOVD x+0(FP), R0 17 | MOVD y+8(FP), R1 18 | SUB R0, R1, R0 19 | MOVD R0, ret+16(FP) 20 | RET 21 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/c-archive_empty_hdr_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "tests/core/c_linkmodes/c-archive_empty_hdr.h" 16 | 17 | int main() { return 0; } 18 | -------------------------------------------------------------------------------- /tests/examples/executable_name/main.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | ) 21 | 22 | func main() { 23 | fmt.Println("The executable ran!") 24 | } 25 | -------------------------------------------------------------------------------- /tests/legacy/test_build_constraints/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_test( 4 | name = "go_default_test", 5 | size = "small", 6 | srcs = [ 7 | # Filtered by filename suffix 8 | "foo_linux_test.go", 9 | # Filtered by tag 10 | "foo_unknown_test.go", 11 | "bar_unknown_test.go", 12 | ], 13 | embed = [":go_default_library"], 14 | ) 15 | 16 | # Contains more test cases. Checks that build constraints are applied to 17 | # sources found through the library attribute. 18 | go_library( 19 | name = "go_default_library", 20 | srcs = [ 21 | "baz_linux_test.go", 22 | "baz_unknown_test.go", 23 | ], 24 | importpath = "github.com/bazelbuild/rules_go/tests/test_build_constraints", 25 | ) 26 | -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_gen_test.go.in: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package embedsrcs 16 | 17 | import "embed" 18 | 19 | //go:embed embedsrcs_test.go 20 | var gen embed.FS 21 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_test( 4 | name = "go_default_test", 5 | size = "small", 6 | srcs = ["transitive_data_test.go"], 7 | args = [ 8 | "go_data.txt", 9 | "cgo_data.txt", 10 | "c_data.txt", 11 | ], 12 | deps = [":go_lib"], 13 | ) 14 | 15 | go_library( 16 | name = "go_lib", 17 | srcs = [ 18 | "empty.go", 19 | "empty_cgo.go", 20 | ], 21 | cdeps = [":c_lib"], 22 | cgo = True, 23 | data = [ 24 | "cgo_data.txt", 25 | "go_data.txt", 26 | ], 27 | importpath = "github.com/bazelbuild/rules_go/tests/transitive_data", 28 | ) 29 | 30 | cc_library( 31 | name = "c_lib", 32 | srcs = [], 33 | data = ["c_data.txt"], 34 | ) 35 | -------------------------------------------------------------------------------- /go/tools/builders/nogo_typeparams_go117.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:build !go1.18 17 | // +build !go1.18 18 | 19 | package main 20 | 21 | import "go/types" 22 | 23 | func initInstanceInfo(*types.Info) {} 24 | -------------------------------------------------------------------------------- /tests/legacy/binary_test_outputs/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # This test checks that go_binary and go_test produce a single output file. 2 | # See documentation in single_output_test.bzl. 3 | 4 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test") 5 | load("@io_bazel_rules_go//go/private/tools:single_output_test.bzl", "single_output_test") 6 | 7 | single_output_test( 8 | name = "binary_single_output_test", 9 | size = "small", 10 | dep = ":bin", 11 | ) 12 | 13 | go_binary( 14 | name = "bin", 15 | srcs = ["bin.go"], 16 | tags = ["manual"], 17 | ) 18 | 19 | single_output_test( 20 | name = "test_single_output_test", 21 | size = "small", 22 | dep = ":test", 23 | ) 24 | 25 | go_test( 26 | name = "test", 27 | size = "small", 28 | srcs = ["test.go"], 29 | tags = ["manual"], 30 | ) 31 | -------------------------------------------------------------------------------- /tests/legacy/examples/vendor/github.com/user/vendored/vendored.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package vendored 17 | 18 | // Vendored returns a string. 19 | func Vendored() string { 20 | return "I was vendored" 21 | } 22 | -------------------------------------------------------------------------------- /tests/legacy/extldflags_rpath/README.md: -------------------------------------------------------------------------------- 1 | This test checks that flags passed to the external linker with -extldflags 2 | through gc_linkopts are correctly combined with other flags passed through 3 | -extldflags. 4 | 5 | `go tool link` only uses the last set of flags passed with -extldflags. If more 6 | than one set of flags is passed, the last set is passed to the external linker, 7 | and the rest are silently ignored. 8 | 9 | `go_binary` and `go_test` should look for -extldflags in gc_linkopts and 10 | combine the flags into a single list passed to `go tool link`. This includes 11 | flags generated by the rules themselves. 12 | 13 | This test checks this behavior by adding extra rpaths, which has an observable 14 | effect on a `go_binary` linked with the external linker. The shell script checks 15 | that these paths are present. 16 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/go_with_cgo_dep_caller.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "tests/core/c_linkmodes/go_with_cgo_dep.h" 16 | 17 | int main() { 18 | UnixHello(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/core/go_path/cmd/bin/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary") 2 | 3 | go_binary( 4 | name = "bin", 5 | srcs = ["bin.go"], 6 | data = ["bin.go"], # test duplicate 7 | importpath = "example.com/repo/cmd/bin", 8 | visibility = ["//visibility:public"], 9 | ) 10 | 11 | go_binary( 12 | name = "pie", 13 | srcs = ["bin.go"], 14 | importpath = "example.com/repo/cmd/bin", 15 | linkmode = "pie", 16 | visibility = ["//visibility:public"], 17 | deps = [ 18 | "//tests/core/go_path/pkg/lib:go_default_library", 19 | ], 20 | ) 21 | 22 | go_binary( 23 | name = "cross", 24 | srcs = ["bin.go"], 25 | goarch = "arm", 26 | goos = "plan9", 27 | importpath = "example.com/repo/cmd/bin", 28 | pure = "on", 29 | visibility = ["//visibility:public"], 30 | ) 31 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/cc_dependency/BUILD.bazel: -------------------------------------------------------------------------------- 1 | cc_library( 2 | name = "version", 3 | srcs = ["cxx_version.cc"], 4 | hdrs = ["version.h"], 5 | linkopts = ["-ldl"], 6 | visibility = ["//tests/legacy/examples/cgo:__pkg__"], 7 | # TODO(yugui) Support darwin too and remove this workaround. 8 | # See also comments in cxx_version.cc. 9 | deps = select({ 10 | "@platforms//os:macos": [], 11 | "//conditions:default": [":c_version_import"], 12 | }), 13 | ) 14 | 15 | cc_binary( 16 | name = "c_version_so", 17 | srcs = [ 18 | "c_version.c", 19 | "c_version.h", 20 | ], 21 | linkshared = True, 22 | ) 23 | 24 | cc_import( 25 | name = "c_version_import", 26 | hdrs = ["c_version.h"], 27 | shared_library = ":c_version_so", 28 | tags = ["manual"], 29 | ) 30 | -------------------------------------------------------------------------------- /tests/core/cgo/objc/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_test( 4 | name = "objc_test", 5 | srcs = ["objc_darwin_test.go"], 6 | embed = select({ 7 | "@io_bazel_rules_go//go/platform:darwin": [":objc_lib"], 8 | "//conditions:default": [], 9 | }), 10 | ) 11 | 12 | go_library( 13 | name = "objc_lib", 14 | srcs = [ 15 | "add_darwin.go", 16 | "add_darwin.h", 17 | "add_darwin.m", 18 | "sub_darwin.go", 19 | ], 20 | cdeps = [":sub"], 21 | cgo = True, 22 | copts = ["-fmodules"], 23 | importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/objc", 24 | tags = ["manual"], 25 | ) 26 | 27 | objc_library( 28 | name = "sub", 29 | srcs = ["sub.m"], 30 | enable_modules = True, 31 | tags = ["manual"], 32 | ) 33 | -------------------------------------------------------------------------------- /tests/core/output_groups/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "lib", 5 | srcs = ["lib.go"], 6 | importpath = "lib", 7 | ) 8 | 9 | go_test( 10 | name = "lib_test", 11 | srcs = ["lib_test.go"], 12 | embed = [":lib"], 13 | ) 14 | 15 | go_binary( 16 | name = "bin", 17 | srcs = ["bin.go"], 18 | ) 19 | 20 | filegroup( 21 | name = "compilation_outputs", 22 | testonly = True, 23 | srcs = [ 24 | ":bin", 25 | ":lib", 26 | ":lib_test", 27 | ], 28 | output_group = "compilation_outputs", 29 | ) 30 | 31 | go_test( 32 | name = "compilation_outputs_test", 33 | srcs = ["compilation_outputs_test.go"], 34 | data = [":compilation_outputs"], 35 | deps = ["//go/tools/bazel:go_default_library"], 36 | ) 37 | -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | go_test( 6 | name = "remote_test", 7 | srcs = ["@io_bazel_rules_go//tests/core/runfiles:runfiles_test.go"], 8 | deps = ["@io_bazel_rules_go//tests/core/runfiles:check_runfiles"], 9 | ) 10 | 11 | go_binary( 12 | name = "remote_cmd", 13 | srcs = ["@io_bazel_rules_go//tests/core/runfiles:runfiles_cmd.go"], 14 | deps = ["@io_bazel_rules_go//tests/core/runfiles:check_runfiles"], 15 | ) 16 | 17 | go_binary( 18 | name = "remote_bin", 19 | srcs = ["@io_bazel_rules_go//tests/core/runfiles:empty_bin.go"], 20 | ) 21 | 22 | filegroup( 23 | name = "remote_group", 24 | srcs = ["remote_group.txt"], 25 | ) 26 | 27 | exports_files(["remote_file.txt"]) 28 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_test.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "os/exec" 5 | "strings" 6 | "testing" 7 | 8 | "github.com/bazelbuild/rules_go/go/tools/bazel" 9 | ) 10 | 11 | func Test(t *testing.T) { 12 | for _, tc := range []struct { 13 | name, path, want string 14 | }{ 15 | { 16 | name: "tag_pure_bin", 17 | want: "pure", 18 | }, { 19 | name: "tag_cgo_bin", 20 | want: "cgo", 21 | }, 22 | } { 23 | t.Run(tc.name, func(t *testing.T) { 24 | path, ok := bazel.FindBinary("tests/core/cgo", tc.name) 25 | if !ok { 26 | t.Fatalf("could not find binary: %s", tc.name) 27 | } 28 | out, err := exec.Command(path).Output() 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | got := strings.TrimSpace(string(out)) 33 | if got != tc.want { 34 | t.Errorf("got %s; want %s", got, tc.want) 35 | } 36 | }) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/core/cross/main.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | 21 | "github.com/bazelbuild/rules_go/tests/core/cross/platform_lib" 22 | ) 23 | 24 | func main() { 25 | fmt.Println(platform_lib.Platform) 26 | } 27 | -------------------------------------------------------------------------------- /tests/core/go_plugin_with_proto_library/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test") 2 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 3 | 4 | test_suite(name = "go_plugin_with_proto_library") 5 | 6 | go_test( 7 | name = "go_default_test", 8 | srcs = ["all_test.go"], 9 | data = [":plugin"], 10 | deps = [":validate"], 11 | ) 12 | 13 | go_binary( 14 | name = "plugin", 15 | srcs = ["plugin.go"], 16 | out = "plugin.so", 17 | linkmode = "plugin", 18 | deps = [":validate"], 19 | ) 20 | 21 | proto_library( 22 | name = "validate_proto", 23 | srcs = ["validate.proto"], 24 | ) 25 | 26 | go_proto_library( 27 | name = "validate", 28 | gc_goopts = ["-trimpath=$(BINDIR)=>."], 29 | importpath = "go_plugin_with_proto_library/validate", 30 | proto = ":validate_proto", 31 | ) 32 | -------------------------------------------------------------------------------- /go/tools/bazel/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "bazel", 5 | srcs = [ 6 | "bazel.go", 7 | "runfiles.go", 8 | ], 9 | importpath = "github.com/bazelbuild/rules_go/go/tools/bazel", 10 | visibility = ["//visibility:public"], 11 | ) 12 | 13 | go_test( 14 | name = "bazel_test", 15 | size = "small", 16 | srcs = ["bazel_test.go"], 17 | data = ["empty.txt"], 18 | embed = [":bazel"], 19 | ) 20 | 21 | # Runfiles functionality in this package is tested by //tests/core/runfiles. 22 | 23 | filegroup( 24 | name = "all_files", 25 | testonly = True, 26 | srcs = glob(["**"]), 27 | visibility = ["//visibility:public"], 28 | ) 29 | 30 | alias( 31 | name = "go_default_library", 32 | actual = ":bazel", 33 | visibility = ["//visibility:public"], 34 | ) 35 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/gogo/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_test") 2 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 3 | load("@rules_proto//proto:defs.bzl", "proto_library") 4 | 5 | proto_library( 6 | name = "values_proto", 7 | srcs = ["values.proto"], 8 | deps = [ 9 | "@com_google_protobuf//:duration_proto", 10 | "@gogo_special_proto//github.com/gogo/protobuf/gogoproto", 11 | ], 12 | ) 13 | 14 | go_proto_library( 15 | name = "values_go_proto", 16 | compilers = [ 17 | "@io_bazel_rules_go//proto:gogofaster_proto", 18 | ], 19 | importpath = "github.com/bazelbuild/rules_go/examples/proto/gogo", 20 | proto = ":values_proto", 21 | ) 22 | 23 | go_test( 24 | name = "gogo_test", 25 | srcs = ["gogo_test.go"], 26 | deps = [ 27 | ":values_go_proto", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /go/tools/bazel_benchmark/WORKSPACE.in: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 2 | 3 | local_repository( 4 | name = "io_bazel_rules_go", 5 | path = "{{.RulesGoDir}}", 6 | ) 7 | 8 | http_archive( 9 | name = "bazel_gazelle", 10 | urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.13.0/bazel-gazelle-0.13.0.tar.gz"], 11 | sha256 = "bc653d3e058964a5a26dcad02b6c72d7d63e6bb88d94704990b908a1445b8758", 12 | ) 13 | 14 | load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies") 15 | 16 | go_rules_dependencies() 17 | 18 | go_register_toolchains(go_version = "host") 19 | 20 | load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") 21 | 22 | gazelle_dependencies() 23 | 24 | load("@io_bazel_rules_go//tests/integration/popular_repos:popular_repos.bzl", "popular_repos") 25 | 26 | popular_repos() 27 | -------------------------------------------------------------------------------- /tests/core/cgo/cgo_link_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cgo_link 16 | 17 | import "testing" 18 | 19 | func Test(t *testing.T) { 20 | want := 42 21 | if got := F(); got != want { 22 | t.Errorf("got %d; want %d", got, want) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /go/toolchain/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | load("@bazel_skylib//rules:common_settings.bzl", "string_flag") 3 | load( 4 | ":toolchains.bzl", 5 | "declare_constraints", 6 | ) 7 | 8 | package(default_visibility = ["//visibility:public"]) 9 | 10 | declare_constraints() 11 | 12 | string_flag( 13 | name = "sdk_version", 14 | build_setting_default = "", 15 | ) 16 | 17 | filegroup( 18 | name = "all_rules", 19 | srcs = glob(["*.bzl"]), 20 | visibility = ["//visibility:public"], 21 | ) 22 | 23 | filegroup( 24 | name = "all_files", 25 | testonly = True, 26 | srcs = glob(["**"]), 27 | visibility = ["//visibility:public"], 28 | ) 29 | 30 | bzl_library( 31 | name = "toolchains", 32 | srcs = ["toolchains.bzl"], 33 | deps = [ 34 | "//go/private:platforms", 35 | "//go/private:sdk", 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /tests/core/go_test/internal_test.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib 17 | 18 | import ( 19 | "testing" 20 | ) 21 | 22 | var Expect = "Expect" 23 | 24 | func TestInternal(t *testing.T) { 25 | if Got != Expect { 26 | t.Errorf("Got %q expected %q", Got, Expect) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/core/nogo/deps/README.rst: -------------------------------------------------------------------------------- 1 | nogo analyzers with dependencies 2 | ============================= 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _go_library: /docs/go/core/rules.md#_go_library 6 | 7 | Tests to ensure that custom `nogo`_ analyzers that depend on each other are 8 | run in the correct order. 9 | 10 | .. contents:: 11 | 12 | deps_test 13 | --------- 14 | Given the following dependency graph of analyzers: 15 | 16 | a ----+ 17 | | 18 | v 19 | b --> c --> d 20 | 21 | Where analyzers a, b, c are explicitly depended on by the `nogo`_ rule and d 22 | isn't, verifies that a `go_library`_ build causes both paths in the graph 23 | (a->c->d and b->c->d) to be executed, and that each analyzer runs exactly once. 24 | 25 | Also verify that the diagnostics reported by d are not printed to the build log 26 | since d was not explicitly depended on by the declared `nogo`_ rule. 27 | -------------------------------------------------------------------------------- /examples/basic-gazelle/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "github.com/bazelbuild/rules_go/examples/basic-gazelle/cmd" 19 | "k8s.io/klog/v2" 20 | ) 21 | 22 | func main() { 23 | klog.InitFlags(nil) 24 | cmd.Execute() 25 | } 26 | -------------------------------------------------------------------------------- /go/tools/bazel_testing/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | load("//go:def.bzl", "go_library") 3 | 4 | go_library( 5 | name = "bazel_testing", 6 | srcs = ["bazel_testing.go"], 7 | importpath = "github.com/bazelbuild/rules_go/go/tools/bazel_testing", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "//go/tools/bazel", 11 | "//go/tools/internal/txtar", 12 | ], 13 | ) 14 | 15 | filegroup( 16 | name = "all_files", 17 | testonly = True, 18 | srcs = glob(["**"]), 19 | visibility = ["//visibility:public"], 20 | ) 21 | 22 | alias( 23 | name = "go_default_library", 24 | actual = ":bazel_testing", 25 | visibility = ["//visibility:public"], 26 | ) 27 | 28 | bzl_library( 29 | name = "def", 30 | srcs = ["def.bzl"], 31 | visibility = ["//visibility:public"], 32 | deps = ["//go:def"], 33 | ) 34 | -------------------------------------------------------------------------------- /tests/extras/gomock/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test", "gomock") 2 | 3 | go_library( 4 | name = "client", 5 | srcs = [ 6 | "client.go", 7 | ], 8 | importpath = "github.com/bazelbuild/rules_go/gomock/client", 9 | visibility = ["//visibility:public"], 10 | deps = [ 11 | "@go_googleapis//google/bytestream:bytestream_go_proto", 12 | "@org_golang_google_grpc//:grpc", 13 | ], 14 | ) 15 | 16 | gomock( 17 | name = "mocks", 18 | out = "client_mock.go", 19 | library = ":client", 20 | package = "client", 21 | source = "client.go", 22 | visibility = ["//visibility:public"], 23 | ) 24 | 25 | go_test( 26 | name = "client_test", 27 | srcs = [ 28 | "client_mock.go", 29 | "client_test.go", 30 | ], 31 | embed = [":client"], 32 | deps = ["@com_github_golang_mock//gomock"], 33 | ) 34 | -------------------------------------------------------------------------------- /go/tools/builders/nogo_typeparams_go118.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2022 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:build go1.18 17 | // +build go1.18 18 | 19 | package main 20 | 21 | import ( 22 | "go/ast" 23 | "go/types" 24 | ) 25 | 26 | func initInstanceInfo(info *types.Info) { 27 | info.Instances = make(map[*ast.Ident]types.Instance) 28 | } 29 | -------------------------------------------------------------------------------- /tests/core/go_test/external_test.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib_test 17 | 18 | import ( 19 | "lib" 20 | "testing" 21 | ) 22 | 23 | var Expect = "Expect" 24 | 25 | func TestExternal(t *testing.T) { 26 | if lib.Got != Expect { 27 | t.Errorf("Got %q expected %q", lib.Got, Expect) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/core/nogo/coverage/README.rst: -------------------------------------------------------------------------------- 1 | nogo test with coverage 2 | ======================= 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _#1940: https://github.com/bazelbuild/rules_go/issues/1940 6 | .. _#2146: https://github.com/bazelbuild/rules_go/issues/2146 7 | 8 | Tests to ensure that `nogo`_ works with coverage. 9 | 10 | coverage_test 11 | ------------- 12 | Checks that `nogo`_ works when coverage is enabled. All covered libraries gain 13 | an implicit dependencies on ``//go/tools/coverdata``, which is a 14 | `go_tool_library`_, which isn't built with `nogo`_. We should be able to 15 | handle libraries like this that do not have serialized facts. Verifies `#1940`_. 16 | 17 | Also checks that `nogo`_ itself can be built with coverage enabled. 18 | Verifies `#2146`_. 19 | 20 | gen_code_test 21 | ------------- 22 | Checks how `nogo`_ should not run on source code that was generated as part of 23 | rules_go's coverage implementation. 24 | -------------------------------------------------------------------------------- /examples/basic-gazelle/pkg/roll/roll_dice_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package roll 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestGenerateNumber(t *testing.T) { 22 | result := generateNumber() 23 | 24 | if result == "" { 25 | t.Error("got an empty string") 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/core/cgo/cc_libs_common.go: -------------------------------------------------------------------------------- 1 | package cc_libs_test 2 | 3 | import ( 4 | "bytes" 5 | "github.com/bazelbuild/rules_go/go/tools/bazel" 6 | "io/ioutil" 7 | "testing" 8 | ) 9 | 10 | // A distinctive substring contained in every absolute path pointing into the 11 | // Bazel cache. 12 | const execPathIndicator = "/execroot/io_bazel_rules_go" 13 | 14 | func verifyNoCachePaths(t *testing.T, shortPath string) { 15 | binPath, err := bazel.Runfile(shortPath) 16 | if err != nil { 17 | t.Error(err) 18 | } 19 | binBytes, err := ioutil.ReadFile(binPath) 20 | if err != nil { 21 | t.Error(err) 22 | } 23 | if pos := bytes.Index(binBytes, []byte(execPathIndicator)); pos != -1 { 24 | begin := pos - 150 25 | if begin < 0 { 26 | begin = 0 27 | } 28 | end := pos + 150 29 | if end > len(binBytes) { 30 | end = len(binBytes) 31 | } 32 | t.Errorf("%s leaks an absolute path:\n%q", shortPath, binBytes[begin:end]) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/core/coverage/README.rst: -------------------------------------------------------------------------------- 1 | .. _#2127: https://github.com/bazelbuild/rules_go/issues/2127 2 | 3 | coverage functionality 4 | ====================== 5 | 6 | coverage_test 7 | ------------- 8 | 9 | Checks that ``bazel coverage`` on a ``go_test`` produces reasonable output. 10 | Libraries referenced by the test that pass ``--instrumentation_filter`` should 11 | have coverage data. Library excluded with ``--instrumentatiuon_filter`` should 12 | not have coverage data. 13 | 14 | binary_coverage_test 15 | -------------------- 16 | 17 | Checks that ``bazel build --collect_code_coverage`` can instrument a 18 | ``go_binary``. ``bazel coverage`` should also work, though it should fail 19 | with status 4 since the binary is not a test. 20 | 21 | This functionality isn't really complete. The generate test main package 22 | gathers and writes coverage data, and that's not present. This is just 23 | a regression test for a link error (`#2127`_). 24 | -------------------------------------------------------------------------------- /tests/legacy/examples/monobuild/cmd/mycmd.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | 21 | "full/import/path/to/lib1" 22 | "totally/different/import/for/lib2" 23 | ) 24 | 25 | func main() { 26 | fmt.Println("lib1: ", lib1.Name()) 27 | fmt.Println("lib2: ", lib2.Description()) 28 | } 29 | -------------------------------------------------------------------------------- /tests/core/c_linkmodes/go_with_cgo_dep.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "C" 18 | import ( 19 | "fmt" 20 | 21 | "golang.org/x/sys/unix" 22 | ) 23 | 24 | //export UnixHello 25 | func UnixHello() { 26 | fmt.Printf("Hello, %d\n", unix.Getuid()) 27 | } 28 | 29 | func main() {} 30 | -------------------------------------------------------------------------------- /tests/legacy/examples/lib/lib_test.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The Bazel Authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package lib 17 | 18 | import ( 19 | "testing" 20 | ) 21 | 22 | func TestMeaning(t *testing.T) { 23 | if m := Meaning(); m != 42 { 24 | t.Errorf("got %d, want 42", m) 25 | } 26 | } 27 | 28 | func TestAddTwoNumbers(t *testing.T) { 29 | AddTwoNumbers() 30 | } 31 | --------------------------------------------------------------------------------