├── .bazelci └── presubmit.yml ├── .bazelignore ├── .bazelrc ├── .bazelversion ├── .bcr ├── config.yml ├── metadata.template.json ├── presubmit.yml └── source.template.json ├── .github ├── ISSUE_TEMPLATE │ └── config.yaml └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .vscode ├── extensions.json └── settings.json ├── AUTHORS ├── BUILD.bazel ├── CODEOWNERS ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE.txt ├── MODULE.bazel ├── README.rst ├── WORKSPACE ├── docs ├── BUILD.bazel ├── doc_helpers.bzl ├── go │ ├── core │ │ ├── BUILD.bazel │ │ ├── buildgraph.excalidraw │ │ ├── buildgraph.svg │ │ ├── bzlmod.md │ │ ├── cross_compilation.md │ │ ├── defines_and_stamping.md │ │ ├── embedding.md │ │ ├── examples.md │ │ ├── platform-specific_dependencies.md │ │ ├── rules.bzl │ │ ├── rules.md │ │ └── workspace.md │ ├── editors │ │ └── vim.md │ └── extras │ │ ├── BUILD.bazel │ │ ├── extras.bzl │ │ └── extras.md └── rule_body.vm ├── examples ├── .bazelrc ├── basic_gazelle │ ├── .bazelrc │ ├── BUILD.bazel │ ├── MODULE.bazel │ ├── README.md │ ├── go.mod │ ├── go.sum │ ├── printlinks.go │ └── printlinks_test.go └── hello │ ├── .bazelrc │ ├── BUILD.bazel │ ├── MODULE.bazel │ ├── README.md │ ├── hello.go │ └── hello_test.go ├── extras ├── BUILD.bazel ├── gomock.bzl └── gomock │ └── BUILD.bazel ├── go.mod ├── go.sum ├── go ├── BUILD.bazel ├── config │ └── BUILD.bazel ├── constraints │ ├── amd64 │ │ └── BUILD.bazel │ └── arm │ │ └── BUILD.bazel ├── core.rst ├── def.bzl ├── dependencies.rst ├── deps.bzl ├── extensions.bzl ├── extras.rst ├── modes.rst ├── nogo.rst ├── nogo_logo.png ├── platform │ ├── BUILD.bazel │ ├── apple.bzl │ └── list.bzl ├── private │ ├── BUILD.bazel │ ├── BUILD.nogo.bazel │ ├── BUILD.sdk.bazel │ ├── actions │ │ ├── BUILD.bazel │ │ ├── archive.bzl │ │ ├── binary.bzl │ │ ├── compilepkg.bzl │ │ ├── link.bzl │ │ ├── stdlib.bzl │ │ └── utils.bzl │ ├── common.bzl │ ├── context.bzl │ ├── extensions.bzl │ ├── go_mod.bzl │ ├── go_toolchain.bzl │ ├── mode.bzl │ ├── nogo.bzl │ ├── platforms.bzl │ ├── polyfill_bazel_features.bzl │ ├── providers.bzl │ ├── repositories.bzl │ ├── rpath.bzl │ ├── rules │ │ ├── BUILD.bazel │ │ ├── binary.bzl │ │ ├── cgo.bzl │ │ ├── cross.bzl │ │ ├── go_bin_for_host.bzl │ │ ├── info.bzl │ │ ├── library.bzl │ │ ├── nogo.bzl │ │ ├── sdk.bzl │ │ ├── source.bzl │ │ ├── stdlib.bzl │ │ ├── test.bzl │ │ ├── transition.bzl │ │ └── wrappers.bzl │ ├── sdk.bzl │ ├── skylib │ │ ├── README.rst │ │ └── lib │ │ │ ├── BUILD.bazel │ │ │ └── versions.bzl │ └── tools │ │ ├── BUILD.bazel │ │ ├── files_equal_test.bzl │ │ ├── lines_sorted_test.bzl │ │ ├── path.bzl │ │ └── single_output_test.bzl ├── providers.rst ├── runfiles │ ├── BUILD.bazel │ ├── caller_repository_example_test.go │ ├── directory.go │ ├── example_test.go │ ├── fs.go │ ├── global.go │ ├── manifest.go │ ├── rlocationpath_xdefs_example_test.go │ └── runfiles.go ├── toolchain │ ├── BUILD.bazel │ └── toolchains.bzl ├── toolchains.rst └── tools │ ├── BUILD.bazel │ ├── bazel │ ├── BUILD.bazel │ ├── bazel.go │ ├── bazel_test.go │ ├── empty.txt │ └── runfiles.go │ ├── bazel_benchmark │ ├── BUILD.bazel │ ├── BUILD.bazel.in │ ├── WORKSPACE.in │ ├── bazel_benchmark.go │ ├── bazel_benchmark.sh │ └── hello.go.in │ ├── bazel_testing │ ├── BUILD.bazel │ ├── bazel_testing.go │ └── def.bzl │ ├── builders │ ├── BUILD.bazel │ ├── ar.go │ ├── asm.go │ ├── builder.go │ ├── cc.go │ ├── cgo2.go │ ├── compilepkg.go │ ├── constants.go │ ├── cover.go │ ├── cover_test.go │ ├── edit.go │ ├── embedcfg.go │ ├── env.go │ ├── env_test.go │ ├── filter.go │ ├── filter_buildid.go │ ├── filter_test.go │ ├── flags.go │ ├── generate_nogo_main.go │ ├── generate_test_main.go │ ├── go_path.go │ ├── importcfg.go │ ├── info.go │ ├── link.go │ ├── md5sum.go │ ├── nogo.go │ ├── nogo_fix.go │ ├── nogo_fix_test.go │ ├── nogo_main.go │ ├── nogo_typeparams_go117.go │ ├── nogo_typeparams_go118.go │ ├── nogo_validation.go │ ├── nolint.go │ ├── nolint_test.go │ ├── path.go │ ├── path_windows.go │ ├── protoc.go │ ├── read.go │ ├── read_test.go │ ├── read_test_fixture.go │ ├── replicate.go │ ├── stdlib.go │ ├── stdliblist.go │ └── stdliblist_test.go │ ├── bzltestutil │ ├── BUILD.bazel │ ├── chdir │ │ ├── BUILD.bazel │ │ └── init.go │ ├── lcov.go │ ├── lcov_test.go │ ├── test2json.go │ ├── testdata │ │ ├── empty.json │ │ ├── empty.xml │ │ ├── report.json │ │ ├── report.xml │ │ ├── timeout.json │ │ └── timeout.xml │ ├── timeout.go │ ├── wrap.go │ ├── wrap_test.go │ ├── xml.go │ └── xml_test.go │ ├── coverdata │ ├── BUILD.bazel │ └── coverdata.go │ ├── fetch_repo │ ├── BUILD.bazel │ ├── fetch_repo_test.go │ ├── go.mod │ └── main.go │ ├── gazelle │ └── README.rst │ ├── go_bin_runner │ ├── BUILD.bazel │ └── main.go │ ├── gopackagesdriver │ ├── BUILD.bazel │ ├── aspect.bzl │ ├── bazel.go │ ├── bazel_json_builder.go │ ├── build_context.go │ ├── driver_request.go │ ├── flatpackage.go │ ├── gopackagesdriver_test.go │ ├── json_packages_driver.go │ ├── main.go │ ├── packageregistry.go │ ├── pkgjson │ │ ├── BUILD.bazel │ │ ├── main.go │ │ └── pkg_json.bzl │ └── utils.go │ ├── internal │ ├── stdlib_tags │ │ ├── BUILD.bazel │ │ └── stdlib_tags.go │ └── txtar │ │ ├── BUILD.bazel │ │ ├── archive.go │ │ └── archive_test.go │ ├── releaser │ ├── BUILD.bazel │ ├── boilerplate.go │ ├── file.go │ ├── git.go │ ├── github.go │ ├── go.mod │ ├── prepare.go │ ├── releaser.go │ ├── run.go │ ├── upgradedep.go │ └── upgradedep_test.go │ └── windows-testrunner │ ├── go.mod │ └── windows-testrunner.go ├── internal └── BUILD.bazel ├── proto ├── BUILD.bazel ├── compiler.bzl ├── core.rst ├── def.bzl ├── gogo.bzl ├── private │ ├── BUILD.bazel │ └── toolchain.bzl └── wkt │ ├── BUILD.bazel │ └── well_known_types.bzl ├── tests ├── BUILD.bazel ├── README.rst ├── bcr │ ├── .bazelrc │ ├── .bazelversion │ ├── BUILD.bazel │ ├── MODULE.bazel │ ├── WORKSPACE │ ├── go_tool_test.sh │ ├── lib.go │ ├── main.go │ ├── mockable.go │ ├── mockable_test.go │ ├── other_module │ │ ├── BUILD.bazel │ │ ├── MODULE.bazel │ │ ├── WORKSPACE │ │ └── bar.txt │ ├── proto │ │ ├── BUILD.bazel │ │ ├── foo.proto │ │ ├── foo_grpc_test.go │ │ └── foo_proto_test.go │ ├── runfiles │ │ ├── BUILD.bazel │ │ └── runfiles_test.go │ ├── sdk_patch_test.go │ ├── test.go │ ├── test_go_sdk.patch │ ├── third_party │ │ ├── BUILD.bazel │ │ └── lib.go │ ├── transition.bzl │ └── wrap_test.go ├── buildifier_test.bzl ├── core │ ├── README.rst │ ├── boringcrypto │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── boringcrypto_test.go │ ├── build_stdlib │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── build_stdlib_test.go │ ├── c_linkmodes │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── add.go │ │ ├── add_sandwich.c │ │ ├── add_sandwich.go │ │ ├── add_sandwich.h │ │ ├── add_test_archive.c │ │ ├── add_test_sandwich.c │ │ ├── add_test_shared.c │ │ ├── c-archive_empty_hdr_test.c │ │ ├── crypto.go │ │ ├── crypto_test_dl.c │ │ ├── empty.go │ │ ├── go_with_cgo_dep.go │ │ ├── go_with_cgo_dep_caller.cc │ │ └── skip.c │ ├── cgo │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── add.c │ │ ├── add.cpp │ │ ├── add.h │ │ ├── add.m │ │ ├── add.mm │ │ ├── adder.go │ │ ├── adder_test.go │ │ ├── asm │ │ │ ├── BUILD.bazel │ │ │ ├── asm_amd64.S │ │ │ ├── asm_arm64.S │ │ │ ├── cgoasm.go │ │ │ └── cgoasm_test.go │ │ ├── asm_conditional_cgo │ │ │ ├── BUILD.bazel │ │ │ ├── asm_amd64.S │ │ │ ├── asm_arm64.S │ │ │ ├── asm_cgo.go │ │ │ ├── asm_conditional_cgo_test.go │ │ │ └── asm_nocgo.go │ │ ├── asm_dep_conditional_cgo │ │ │ ├── BUILD.bazel │ │ │ ├── asm_dep_cgo.go │ │ │ ├── asm_dep_conditional_cgo_test.go │ │ │ └── asm_dep_nocgo.go │ │ ├── bar.cc │ │ ├── bar.go │ │ ├── cc_libs_common.go │ │ ├── cc_libs_darwin_test.go │ │ ├── cc_libs_linux_test.go │ │ ├── cgo_abs_paths_test.go │ │ ├── cgo_link_dep.c │ │ ├── cgo_link_test.go │ │ ├── cgo_ref.go │ │ ├── cgo_required_test.go │ │ ├── direct_dep.go │ │ ├── dylib_client.go │ │ ├── dylib_test.go │ │ ├── external_includes_test.go │ │ ├── foo.c │ │ ├── foo.go │ │ ├── generate_imported_dylib.sh │ │ ├── imported.c │ │ ├── native_dep.c │ │ ├── native_dep.h │ │ ├── objc │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ ├── add_darwin.go │ │ │ ├── add_darwin.h │ │ │ ├── add_darwin.m │ │ │ ├── objc_darwin_test.go │ │ │ ├── sub.m │ │ │ └── sub_darwin.go │ │ ├── provide_external_symbol.go │ │ ├── pure.go │ │ ├── race_off.c │ │ ├── race_off.go │ │ ├── race_on.c │ │ ├── race_on.go │ │ ├── race_test.go │ │ ├── split_import_a.go │ │ ├── split_import_b.go │ │ ├── split_import_c.c │ │ ├── split_import_c.h │ │ ├── split_import_cgo.go │ │ ├── split_import_i_test.go │ │ ├── split_import_x_test.go │ │ ├── tag_cgo.go │ │ ├── tag_cgo_err.go │ │ ├── tag_pure.go │ │ ├── tag_pure_err.c │ │ ├── tag_pure_err.go │ │ ├── tag_test.go │ │ ├── transitive_dep.go │ │ ├── use_c_symbol_through_go.c │ │ ├── use_external_symbol.go │ │ └── use_transitive_symbol.go │ ├── compatibility │ │ ├── BUILD.bazel │ │ ├── README.md │ │ └── hello.go │ ├── coverage │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── binary_coverage_test.go │ │ ├── coverage_test.go │ │ ├── issue3017_test.go │ │ ├── lcov_coverage_test.go │ │ └── lcov_test_main_coverage_test.go │ ├── cross │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── asm.s │ │ ├── cross_test.go │ │ ├── def.bzl │ │ ├── ios_select_test.go │ │ ├── lib_darwin.go │ │ ├── lib_linux.go │ │ ├── lib_windows.go │ │ ├── main.go │ │ ├── non_executable_test.go │ │ ├── proto_test.go │ │ └── sdk_version_test.go │ ├── from_go_mod_file │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── from_go_mod_file_test.go │ ├── go_bazel_test │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── dataargtest_test.go │ ├── go_binary │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── broken_cgo.go │ │ ├── configurable_attribute_bad_test.go │ │ ├── configurable_attribute_good_test.go │ │ ├── custom_bin.go │ │ ├── hello.go │ │ ├── linkmode.bzl │ │ ├── many_deps.bzl │ │ ├── meaning.go │ │ ├── meaning2.go │ │ ├── non_executable_test.go │ │ ├── out_test.go │ │ ├── package_conflict_test.go │ │ ├── pgo.go │ │ ├── pgo.pprof │ │ ├── pgo_test.go │ │ ├── pie_darwin_amd64_test.go │ │ ├── pie_darwin_test.go │ │ ├── pie_linux_test.go │ │ ├── prefix │ │ │ ├── BUILD.bazel │ │ │ └── prefix.go │ │ ├── stamp_bin.go │ │ ├── stamp_dep.go │ │ ├── stamp_embed.go │ │ ├── stamp_test.go │ │ ├── static_bin.go │ │ ├── static_cgo_bin.go │ │ ├── static_pure_bin.go │ │ ├── static_test.go │ │ ├── tags_lib_bad.go │ │ ├── tags_lib_good.go │ │ ├── tags_main_bad.go │ │ ├── tags_main_good.go │ │ └── testing_testing.go │ ├── go_download_sdk │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── go_download_sdk_test.go │ ├── go_library │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── def.bzl │ │ ├── embedsrcs_error_test.go │ │ ├── embedsrcs_gen_test.go.in │ │ ├── embedsrcs_simple_test.go │ │ ├── embedsrcs_static │ │ │ ├── contains_hidden │ │ │ │ ├── .hidden │ │ │ │ ├── .hidden_dir │ │ │ │ │ ├── .env │ │ │ │ │ └── visible_file │ │ │ │ ├── _hidden_dir │ │ │ │ │ ├── .bashrc │ │ │ │ │ ├── _hidden_file │ │ │ │ │ └── visible_file │ │ │ │ └── visible │ │ │ │ │ ├── .bzr │ │ │ │ │ └── file-under-version-control │ │ │ │ │ └── visible_file │ │ │ ├── dir │ │ │ │ ├── _no │ │ │ │ └── f │ │ │ ├── file │ │ │ ├── glob │ │ │ │ ├── _hidden │ │ │ │ └── f │ │ │ └── no │ │ ├── embedsrcs_test.go │ │ ├── empty_bar.go │ │ ├── empty_baz.s │ │ ├── empty_foo.go │ │ ├── empty_main.go │ │ ├── gen_embedsrcs_files.go │ │ ├── import_alias_a_v2.go │ │ ├── import_alias_b.go │ │ ├── import_alias_test.go │ │ ├── imported.c │ │ ├── inc.go │ │ ├── inc_asmhdr.s │ │ ├── inc_bar.s │ │ ├── inc_foo.s │ │ ├── no_srcs_test.go │ │ ├── package_height.go │ │ ├── package_height_dep_deep.go │ │ ├── package_height_dep_shallow.go │ │ ├── package_height_embeddee.go │ │ ├── package_height_embedder.go │ │ ├── use_syso.go │ │ ├── wrap_imported_amd64.s │ │ └── wrap_imported_arm64.s │ ├── go_path │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── cmd │ │ │ └── bin │ │ │ │ ├── BUILD.bazel │ │ │ │ └── bin.go │ │ ├── extra.txt │ │ ├── go_path_test.go │ │ └── pkg │ │ │ └── lib │ │ │ ├── BUILD.bazel │ │ │ ├── data.txt │ │ │ ├── embed_test.go │ │ │ ├── embedded_src.txt │ │ │ ├── external_test.go │ │ │ ├── generated_embeded.bzl │ │ │ ├── internal_test.go │ │ │ ├── lib.go │ │ │ ├── template │ │ │ └── index.html.tmpl │ │ │ ├── testdata │ │ │ └── testdata.txt │ │ │ ├── transitive.go │ │ │ └── vendored.go │ ├── go_plugin │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── all_test.go │ │ └── plugin.go │ ├── go_plugin_with_proto_library │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── all_test.go │ │ ├── plugin.go │ │ └── validate.proto │ ├── go_proto_aspect │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── codegen.bzl │ │ └── foo.proto │ ├── go_proto_library │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── adjusted_a.proto │ │ ├── adjusted_b.proto │ │ ├── adjusted_c.proto │ │ ├── adjusted_import_test.go │ │ ├── bar.proto │ │ ├── compiler_multi_suffix_test.go │ │ ├── compilers │ │ │ ├── BUILD.bazel │ │ │ ├── dbenums.go │ │ │ └── main.go │ │ ├── embed_test.go │ │ ├── enum.proto │ │ ├── extra.go │ │ ├── foo.proto │ │ ├── gofast_grpc_test.go │ │ ├── gofast_test.go │ │ ├── gogofast_grpc_test.go │ │ ├── gogofast_test.go │ │ ├── grpc.proto │ │ ├── no_go_package.proto │ │ ├── proto_package_test.go │ │ ├── protos_a.proto │ │ ├── protos_alias_test.go │ │ ├── protos_b.proto │ │ ├── protos_test.go │ │ ├── proxy_a.proto │ │ ├── proxy_b.proto │ │ ├── proxy_test.go │ │ ├── transitive_test.go │ │ └── wkt_wrapper_test.go │ ├── go_proto_library_importmap │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── foo.proto │ │ └── importmap_test.go │ ├── go_proto_library_importpath │ │ ├── BUILD.bazel │ │ ├── bar.proto │ │ ├── foo.proto │ │ └── importpath_test.go │ ├── go_test │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── binary_env_test.go │ │ ├── data_test.go │ │ ├── data_test_dep.go │ │ ├── data_test_embed.go │ │ ├── env_inherit_test.go │ │ ├── env_test.go │ │ ├── example_test.go │ │ ├── external_importmap_dep.go │ │ ├── external_importmap_lib.go │ │ ├── external_importmap_test.go │ │ ├── external_test.go │ │ ├── filter_test_cases_test.go │ │ ├── flag_test.go │ │ ├── fuzz_test.go │ │ ├── indirect_import_dep.go │ │ ├── indirect_import_i_test.go │ │ ├── indirect_import_lib.go │ │ ├── indirect_import_x_test.go │ │ ├── internal_test.go │ │ ├── lib.go │ │ ├── only_testmain_test.go │ │ ├── pwd_test.go │ │ ├── same_package_test.go │ │ ├── sharding_test.go │ │ ├── sigterm_handler_test.go │ │ ├── syso_direct_test.go │ │ ├── syso_transitive_test.go │ │ ├── tags_bad_test.go │ │ ├── tags_good_test.go │ │ ├── test_fail_fast_test.go │ │ ├── test_filter_test.go │ │ ├── testing_testing_test.go │ │ ├── testmain_import_indirect_test.go │ │ ├── testmain_import_main_test.go │ │ ├── testmain_pwd_test.go │ │ ├── testmain_without_exit_test.go │ │ ├── timeout_test.go │ │ ├── wrapped_test.go │ │ ├── wrapper_test.go │ │ ├── x │ │ ├── x_defs │ │ │ ├── BUILD.bazel │ │ │ ├── bar.go │ │ │ ├── baz.go │ │ │ ├── foo.go │ │ │ ├── foo_test.go │ │ │ ├── qux.go │ │ │ ├── x_defs_lib.go │ │ │ └── x_defs_test.go │ │ ├── xml_panic_test.go │ │ ├── xmlreport_test.go │ │ ├── y │ │ └── z │ ├── importmap │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── import.go │ │ ├── importmap_test.go │ │ └── lib.go │ ├── nogo │ │ ├── README.rst │ │ ├── bzlmod │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── includes_excludes_test.go │ │ ├── config │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── config_test.go │ │ ├── coverage │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ ├── coverage_cgo_test.go │ │ │ ├── coverage_test.go │ │ │ └── gen_code_test.go │ │ ├── custom │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ ├── custom_test.go │ │ │ └── flags │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── README.rst │ │ │ │ └── flags_test.go │ │ ├── deps │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── deps_test.go │ │ ├── generate │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── empty_test.go │ │ ├── generics │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── generics_test.go │ │ ├── includes_excludes │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── includes_excludes_test.go │ │ ├── nolint │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── nolint_test.go │ │ ├── tests │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── tests_test.go │ │ └── vet │ │ │ ├── BUILD.bazel │ │ │ ├── README.rst │ │ │ └── vet_test.go │ ├── output_groups │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── bin.go │ │ ├── compilation_outputs_test.go │ │ ├── lib.go │ │ └── lib_test.go │ ├── race │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── race_test.go │ ├── runfiles │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── bin.go │ │ ├── check_runfiles.go │ │ ├── empty_bin.go │ │ ├── local_file.txt │ │ ├── local_group.txt │ │ ├── runfiles_cmd.go │ │ ├── runfiles_remote_test │ │ │ ├── WORKSPACE │ │ │ └── remote_pkg │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── remote_file.txt │ │ │ │ └── remote_group.txt │ │ └── runfiles_test.go │ ├── starlark │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── cgo │ │ │ ├── BUILD.bazel │ │ │ └── cgo_test.bzl │ │ ├── common_tests.bzl │ │ ├── context_tests.bzl │ │ ├── packagedriver │ │ │ ├── BUILD.bazel │ │ │ ├── fixtures │ │ │ │ ├── a │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ └── a.go │ │ │ │ ├── b │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ └── b.go │ │ │ │ └── c │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── c.go │ │ │ │ │ └── c_test.go │ │ │ └── go_pkg_info_aspect_test.bzl │ │ ├── provider_tests.bzl │ │ └── sdk_tests.bzl │ ├── stdlib │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── buildid_test.go │ │ ├── reproduce_test.sh │ │ └── stdlib_files.bzl │ ├── strip │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── strip_test.go │ ├── transition │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── cmdline_test.go │ │ └── hermeticity_test.go │ └── transitive_headers │ │ ├── a │ │ ├── BUILD.bazel │ │ ├── a.go │ │ └── a.s │ │ ├── b │ │ ├── BUILD.bazel │ │ ├── b.go │ │ └── b.h │ │ └── c │ │ ├── BUILD.bazel │ │ ├── c.go │ │ └── c.h ├── examples │ ├── README.rst │ └── executable_name │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── main.go │ │ └── name_test.sh ├── extras │ └── gomock │ │ ├── README.rst │ │ ├── reflective │ │ ├── BUILD.bazel │ │ ├── client.go │ │ └── client_test.go │ │ ├── source │ │ ├── BUILD.bazel │ │ ├── client.go │ │ ├── client_test.go │ │ └── client_wrapper.go │ │ └── source_with_importpath │ │ ├── BUILD.bazel │ │ ├── client.go │ │ └── client_test.go ├── go.mod ├── grpc_repos.bzl ├── integration │ ├── README.rst │ ├── gazelle │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── gazelle_test.go │ ├── go_bin_runner │ │ ├── BUILD.bazel │ │ └── go_bin_runner_test.go │ ├── googleapis │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── color_service.go │ │ ├── color_service.proto │ │ └── color_service_test.go │ ├── grpc_plugin │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── hello.go │ │ ├── hello.proto │ │ └── hello_test.go │ ├── popular_repos │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ ├── popular_repos.bzl │ │ └── popular_repos.py │ └── reproducibility │ │ ├── BUILD.bazel │ │ ├── README.rst │ │ └── reproducibility_test.go ├── legacy │ ├── README.rst │ ├── asm_include │ │ ├── BUILD.bazel │ │ ├── foo_amd64.go │ │ ├── foo_amd64.h │ │ ├── foo_amd64.s │ │ ├── foo_other.go │ │ └── foo_test.go │ ├── binary_test_outputs │ │ ├── BUILD.bazel │ │ ├── bin.go │ │ └── test.go │ ├── build_constraints │ │ ├── BUILD.bazel │ │ ├── build_constraints_test.go │ │ ├── cgo_group_linux.c │ │ ├── cgo_group_unknown.c │ │ ├── cgo_linux.c │ │ ├── cgo_linux.go │ │ ├── cgo_unknown.c │ │ ├── cgo_unknown.go │ │ ├── suffix_linux.go │ │ ├── suffix_unknown.go │ │ ├── tag_l.go │ │ └── tag_unknown.go │ ├── build_constraints_go_asm │ │ ├── BUILD.bazel │ │ ├── asm_arm64.s │ │ ├── asm_linux_amd64.s │ │ ├── asm_unknown.s │ │ └── build_constraints_go_asm_test.go │ ├── cgo_filtered │ │ ├── BUILD.bazel │ │ ├── pure.go │ │ └── pure_test.go │ ├── cgo_multi_dir │ │ ├── BUILD.bazel │ │ ├── bar │ │ │ └── bar.go │ │ ├── cgo_multi_dir_test.go │ │ └── foo │ │ │ └── foo.go │ ├── cgo_opts │ │ ├── BUILD.bazel │ │ ├── cgo_opts.go │ │ └── cgo_opts_test.go │ ├── cgo_pthread_flag │ │ ├── BUILD.bazel │ │ ├── cgo_pthread_flag.go │ │ └── cgo_pthread_flag_test.go │ ├── cgo_pure │ │ ├── BUILD.bazel │ │ ├── cgo.c │ │ ├── cgo.go │ │ ├── cgo_no_tag.go │ │ ├── cgo_pure_test.go │ │ └── pure.go │ ├── cgo_select │ │ ├── BUILD.bazel │ │ ├── cgo_darwin.go │ │ ├── cgo_linux.go │ │ ├── cgo_select_test.go │ │ ├── cgo_windows.go │ │ ├── darwin.c │ │ ├── linux.c │ │ └── windows.c │ ├── cgo_sys_hdr │ │ ├── BUILD.bazel │ │ ├── foo.go │ │ ├── foo_test.go │ │ └── sub │ │ │ └── foo.h │ ├── cgo_trans_deps │ │ ├── BUILD.bazel │ │ ├── cgo_lib.go │ │ ├── cgo_test.go │ │ └── dep │ │ │ ├── BUILD.bazel │ │ │ └── dep.go │ ├── empty_package │ │ ├── BUILD.bazel │ │ ├── cgo.c │ │ ├── cgo.go │ │ ├── empty_package_test.go │ │ ├── mixed_cgo.go │ │ └── mixed_pure.go │ ├── examples │ │ ├── bin │ │ │ ├── BUILD.bazel │ │ │ └── bin.go │ │ ├── cgo │ │ │ ├── BUILD.bazel │ │ │ ├── cc_dependency │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── c_version.c │ │ │ │ ├── c_version.h │ │ │ │ ├── cxx_version.cc │ │ │ │ └── version.h │ │ │ ├── cgo_lib_test.go │ │ │ ├── example_command │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── generate_test.bzl │ │ │ │ └── main.go │ │ │ ├── export_example.go │ │ │ ├── generated.go.tpl │ │ │ ├── import_example.go │ │ │ ├── pure_go.go │ │ │ ├── skip_go_library │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── cgo_foo.go │ │ │ │ └── types.go │ │ │ ├── sub │ │ │ │ └── floor.go │ │ │ ├── use_exported.c │ │ │ └── use_exported.h │ │ ├── external │ │ │ ├── BUILD.bazel │ │ │ └── main.go │ │ ├── lib │ │ │ ├── BUILD.bazel │ │ │ ├── add_amd64.s │ │ │ ├── add_arm64.s │ │ │ ├── asm.go │ │ │ ├── deep │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── doc.go │ │ │ │ └── thought.go │ │ │ ├── lib.go │ │ │ ├── lib_test.go │ │ │ ├── lib_x_test.go │ │ │ ├── sub_amd64.s │ │ │ └── sub_arm64.s │ │ ├── monobuild │ │ │ ├── cmd │ │ │ │ ├── BUILD.bazel │ │ │ │ └── mycmd.go │ │ │ ├── lib1 │ │ │ │ ├── BUILD.bazel │ │ │ │ └── lib1.go │ │ │ └── lib2 │ │ │ │ ├── BUILD.bazel │ │ │ │ └── lib2.go │ │ ├── proto │ │ │ ├── BUILD.bazel │ │ │ ├── dep │ │ │ │ ├── BUILD.bazel │ │ │ │ └── useful.proto │ │ │ ├── embed │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── embed.go │ │ │ │ └── embed.proto │ │ │ ├── gogo │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── gogo_test.go │ │ │ │ └── values.proto │ │ │ ├── gostyle │ │ │ │ ├── BUILD.bazel │ │ │ │ └── gostyle.proto │ │ │ ├── grpc │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── main.go │ │ │ │ └── my_svc.proto │ │ │ ├── gs.go │ │ │ ├── lib │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── lib.proto │ │ │ │ └── lib2.proto │ │ │ └── proto_test.go │ │ ├── stamped_bin │ │ │ ├── BUILD.bazel │ │ │ └── stamped_test.go │ │ └── vendor │ │ │ └── github.com │ │ │ └── user │ │ │ └── vendored │ │ │ ├── BUILD.bazel │ │ │ └── vendored.go │ ├── extldflags_rpath │ │ ├── BUILD.bazel │ │ ├── README.md │ │ ├── extldflags_rpath_test.sh │ │ └── main.go │ ├── info │ │ ├── BUILD.bazel │ │ └── info_test.sh │ ├── no_prefix │ │ ├── BUILD.bazel │ │ └── no_prefix_test.go │ ├── package_named_build │ │ └── build │ │ │ ├── BUILD.bazel │ │ │ ├── build.go │ │ │ └── build_test.go │ ├── proto_ignore_go_package_option │ │ ├── BUILD.bazel │ │ ├── a.proto │ │ └── b.proto │ ├── providers │ │ ├── BUILD.bazel │ │ ├── test.bzl │ │ ├── test.go │ │ └── test.sh │ ├── slash_names │ │ ├── BUILD.bazel │ │ ├── a │ │ │ └── pkg │ │ │ │ └── pkg.go │ │ ├── b │ │ │ └── pkg │ │ │ │ └── pkg.go │ │ └── slash_test.go │ ├── test_build_constraints │ │ ├── BUILD.bazel │ │ ├── bar_l_test.go │ │ ├── bar_unknown_test.go │ │ ├── baz_linux_test.go │ │ ├── baz_unknown_test.go │ │ ├── foo_linux_test.go │ │ └── foo_unknown_test.go │ ├── test_chdir │ │ ├── BUILD.bazel │ │ ├── data.txt │ │ ├── data_test.go │ │ └── remote.bzl │ ├── test_rundir │ │ ├── BUILD.bazel │ │ └── rundir_test.go │ ├── transitive_data │ │ ├── BUILD.bazel │ │ ├── c_data.txt │ │ ├── cgo_data.txt │ │ ├── empty.go │ │ ├── empty_cgo.go │ │ ├── go_data.txt │ │ └── transitive_data_test.go │ └── visibility │ │ ├── BUILD.bazel │ │ └── foo.go ├── runfiles │ ├── BUILD.bazel │ ├── defs.bzl │ ├── fs_test.go │ ├── runfiles_bazel_test.go │ ├── runfiles_test.go │ ├── test.txt │ ├── test_dir │ │ ├── file.txt │ │ └── subdir │ │ │ └── other_file.txt │ ├── testfs │ │ ├── BUILD.bazel │ │ └── testfs.go │ └── testprog │ │ ├── BUILD.bazel │ │ └── main.go └── update.py ├── third_party ├── BUILD.bazel ├── README.txt ├── com_github_gogo_protobuf-gazelle.patch ├── com_github_golang_mock-gazelle.patch ├── com_github_golang_protobuf-gazelle.patch ├── com_github_pmezard_go_difflib-gazelle.patch ├── org_golang_google_genproto-gazelle.patch ├── org_golang_google_grpc_cmd_protoc_gen_go_grpc.patch ├── org_golang_google_protobuf-gazelle.patch ├── org_golang_x_sys-gazelle.patch ├── org_golang_x_tools-deletegopls.patch ├── org_golang_x_tools-gazelle.patch ├── org_golang_x_tools_go_vcs-gazelle.patch ├── org_golang_x_xerrors-gazelle.patch └── sanitize_patch_dates.go ├── tools.go ├── tools └── gopackagesdriver.sh └── windows.rst /.bazelignore: -------------------------------------------------------------------------------- 1 | tests/bcr 2 | examples 3 | -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /.bcr/config.yml: -------------------------------------------------------------------------------- 1 | fixedReleaser: 2 | login: fmeum 3 | email: fabian@meumertzhe.im 4 | -------------------------------------------------------------------------------- /.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 | "email": "zplin@uber.com", 11 | "github": "linzhp", 12 | "name": "Zhongpeng Lin" 13 | }, 14 | { 15 | "email": "tfrench@uber.com", 16 | "github": "tyler-french", 17 | "name": "Tyler French" 18 | } 19 | ], 20 | "repository": [ 21 | "github:bazel-contrib/rules_go" 22 | ], 23 | "versions": [], 24 | "yanked_versions": {} 25 | } 26 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | 9 | MODULE.bazel.lock 10 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @go-maintainers 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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:gomock", 14 | ], 15 | ) 16 | -------------------------------------------------------------------------------- /examples/.bazelrc: -------------------------------------------------------------------------------- 1 | # This helps configure rules_go CI to test the examples. 2 | # It's not part of the examples themselves. 3 | # 4 | # This file is separate from the main .bazelrc because bzlmod is disabled 5 | # there, but it is required to build the examples. 6 | 7 | common:ci --enable_bzlmod 8 | common:ci --color=no 9 | common:ci --verbose_failures 10 | common:ci --sandbox_debug 11 | common:ci --spawn_strategy=standalone 12 | common:ci --genrule_strategy=standalone 13 | common:ci --test_strategy=standalone 14 | -------------------------------------------------------------------------------- /examples/basic_gazelle/.bazelrc: -------------------------------------------------------------------------------- 1 | # This helps with rules_go's testing. It's not part of the example. 2 | import %workspace%/../.bazelrc 3 | -------------------------------------------------------------------------------- /examples/hello/.bazelrc: -------------------------------------------------------------------------------- 1 | # This helps with rules_go's testing. It's not part of the example. 2 | import %workspace%/../.bazelrc 3 | -------------------------------------------------------------------------------- /examples/hello/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # This file lists targets that can be built with Bazel. 2 | # 3 | # Each target is declared with a rule (like go_library) and is described 4 | # by a set of attributes like srcs and importpath. 5 | load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test") 6 | 7 | go_library( 8 | name = "hello_lib", 9 | srcs = ["hello.go"], 10 | importpath = "github.com/bazel-contrib/rules_go/examples/hello", 11 | visibility = ["//visibility:private"], 12 | ) 13 | 14 | go_binary( 15 | name = "hello", 16 | embed = [":hello_lib"], 17 | visibility = ["//visibility:public"], 18 | ) 19 | 20 | go_test( 21 | name = "hello_test", 22 | srcs = ["hello_test.go"], 23 | embed = [":hello_lib"], 24 | ) 25 | -------------------------------------------------------------------------------- /examples/hello/README.md: -------------------------------------------------------------------------------- 1 | # rules_go "Hello World" example 2 | 3 | This directory contains a minimal, standalone example using Bazel and rules_go. It shows how to use the [`go_binary`](../../go/core/rules.md#go_binary), [`go_library`](../../go/core/rules.md#go_library), and [`go_test`](../../go/core/rules.md#go_test) rules without requiring any other dependencies. 4 | 5 | To run the binary: 6 | 7 | ```bash 8 | bazel run //:hello 9 | ``` 10 | 11 | To test the library: 12 | 13 | ```bash 14 | bazel test //:hello_test 15 | ``` 16 | 17 | For an explanation and an introduction to Bazel, see [Bazel Tutorial: Build a Go Project](https://bazel.build/start/go). 18 | -------------------------------------------------------------------------------- /examples/hello/hello.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | sayHello(os.Stdout) 11 | } 12 | 13 | func sayHello(w io.Writer) { 14 | fmt.Fprintf(w, "Hello Bazel! 💚\n") 15 | } 16 | -------------------------------------------------------------------------------- /examples/hello/hello_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | func TestHello(t *testing.T) { 10 | out := bytes.NewBuffer(nil) 11 | sayHello(out) 12 | got := out.String() 13 | if !strings.Contains(got, "Hello") { 14 | t.Errorf("did not print Hello") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /extras/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | filegroup( 4 | name = "all_rules", 5 | srcs = glob(["*.bzl"]) + ["//go/private:all_rules"], 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 = "gomock", 18 | srcs = ["gomock.bzl"], 19 | visibility = ["//visibility:public"], 20 | deps = [ 21 | "//go/private:context", 22 | "//go/private:go_toolchain", 23 | "//go/private:providers", 24 | "//go/private/rules:wrappers", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /go/extensions.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | load("//go/private:extensions.bzl", _go_sdk = "go_sdk") 16 | 17 | go_sdk = _go_sdk 18 | -------------------------------------------------------------------------------- /go/extras.rst: -------------------------------------------------------------------------------- 1 | .. _extras.md: /docs/go/extras/extras.md 2 | 3 | This file has moved, please find it at extras.md_. 4 | -------------------------------------------------------------------------------- /go/nogo_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/go/nogo_logo.png -------------------------------------------------------------------------------- /go/private/BUILD.nogo.bazel: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | alias( 4 | name = "nogo", 5 | actual = "{{nogo}}", 6 | ) 7 | 8 | exports_files(["scope.bzl"]) 9 | -------------------------------------------------------------------------------- /go/private/actions/utils.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "@bazel_skylib//lib:shell.bzl", 3 | "shell", 4 | ) 5 | 6 | def quote_opts(opts): 7 | return " ".join([shell.quote(opt) if " " in opt else opt for opt in opts]) 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /go/runfiles/rlocationpath_xdefs_example_test.go: -------------------------------------------------------------------------------- 1 | package runfiles_test 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/bazelbuild/rules_go/go/runfiles" 7 | ) 8 | 9 | // Injected by Bazel by adding the following attribute on the target 10 | // (supported by go_binary, go_test, and go_library): 11 | // 12 | // x_defs = { 13 | // "example.com/pkg.fileTxtRlocationpath": "$(rlocationpath file.txt)", 14 | // }, 15 | var fileTxtRlocationpath string 16 | 17 | // Read a runfile at a path injected by Bazel at build time. 18 | func ExampleRlocation_injectedPath() { 19 | p, err := runfiles.Rlocation(fileTxtRlocationpath) 20 | if err != nil { 21 | panic(err) 22 | } 23 | content, _ := os.ReadFile(p) 24 | println(string(content)) 25 | } 26 | -------------------------------------------------------------------------------- /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 | "//go/tools/gopackagesdriver:all_files", 12 | ], 13 | visibility = ["//visibility:public"], 14 | ) 15 | -------------------------------------------------------------------------------- /go/tools/bazel/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/go/tools/bazel/empty.txt -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /go/tools/builders/env_test.go: -------------------------------------------------------------------------------- 1 | //go:build !windows 2 | 3 | package main 4 | 5 | import "testing" 6 | 7 | func TestVerbFromName(t *testing.T) { 8 | testCases := []struct { 9 | name string 10 | verb string 11 | }{ 12 | {"/a/b/c/d/builder", ""}, 13 | {"builder", ""}, 14 | {"/a/b/c/d/builder-cc", "cc"}, 15 | {"builder-ld", "ld"}, 16 | {"c:\\builder\\builder.exe", ""}, 17 | {"c:\\builder with spaces\\builder-cc.exe", "cc"}, 18 | } 19 | 20 | for _, tc := range testCases { 21 | result := verbFromName(tc.name) 22 | if result != tc.verb { 23 | t.Fatalf("retrieved invalid verb %q from name %q", result, tc.name) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /go/tools/builders/read_test_fixture.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | ) 6 | 7 | //go:embed before.sql 8 | var beforeDoubleQuoteRune string 9 | 10 | func doubleQuoteRune() { 11 | rune := '"' 12 | } 13 | 14 | //go:embed after.sql 15 | var afterDoubleQuoteRune string 16 | -------------------------------------------------------------------------------- /go/tools/bzltestutil/chdir/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_tool_library") 2 | 3 | go_tool_library( 4 | name = "chdir", 5 | srcs = ["init.go"], 6 | # We add "+initfirst/" to the package path so this package is initialized 7 | # before user code. See comment above the init function in init.go. 8 | importmap = "+initfirst/github.com/bazelbuild/rules_go/go/tools/bzltestutil/chdir", 9 | importpath = "github.com/bazelbuild/rules_go/go/tools/bzltestutil/chdir", 10 | visibility = ["//go/tools/bzltestutil:__pkg__"], 11 | ) 12 | 13 | filegroup( 14 | name = "all_files", 15 | testonly = True, 16 | srcs = glob( 17 | ["**"], 18 | exclude = ["testdata/*"], 19 | ), 20 | visibility = ["//visibility:public"], 21 | ) 22 | -------------------------------------------------------------------------------- /go/tools/bzltestutil/testdata/empty.json: -------------------------------------------------------------------------------- 1 | {"Action":"fail"} -------------------------------------------------------------------------------- /go/tools/bzltestutil/testdata/empty.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /go/tools/fetch_repo/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_go/go/tools/fetch_repo 2 | 3 | go 1.21.0 4 | -------------------------------------------------------------------------------- /go/tools/gazelle/README.rst: -------------------------------------------------------------------------------- 1 | Gazelle has moved to a new repository: 2 | `github.com/bazelbuild/bazel-gazelle `_ 3 | -------------------------------------------------------------------------------- /go/tools/internal/stdlib_tags/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 2 | 3 | go_library( 4 | name = "stdlib_tags_lib", 5 | srcs = ["stdlib_tags.go"], 6 | importpath = "github.com/bazelbuild/rules_go/go/tools/internal/stdlib_tags", 7 | visibility = ["//visibility:private"], 8 | ) 9 | 10 | go_binary( 11 | name = "stdlib_tags", 12 | embed = [":stdlib_tags_lib"], 13 | visibility = ["//go/tools:__subpackages__"], 14 | ) 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /go/tools/releaser/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_go/go/tools/releaser 2 | 3 | go 1.21.0 4 | -------------------------------------------------------------------------------- /go/tools/windows-testrunner/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_go/go/tools/windows-testrunner 2 | 3 | go 1.21.0 4 | -------------------------------------------------------------------------------- /internal/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "TOOLS_NOGO", "nogo") 2 | 3 | nogo( 4 | name = "nogo", 5 | visibility = ["//visibility:public"], 6 | deps = [ 7 | a 8 | for a in TOOLS_NOGO 9 | # Filter out shadow as it triggers on err and is very noisy. 10 | if a != "@org_golang_x_tools//go/analysis/passes/shadow:go_default_library" 11 | ], 12 | ) 13 | -------------------------------------------------------------------------------- /proto/private/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":toolchain.bzl", "legacy_proto_toolchain") 2 | 3 | legacy_proto_toolchain( 4 | name = "legacy_proto_toolchain", 5 | visibility = ["//visibility:public"], 6 | ) 7 | 8 | filegroup( 9 | name = "all_rules", 10 | testonly = True, 11 | srcs = glob(["*.bzl"]), 12 | visibility = ["//:__subpackages__"], 13 | ) 14 | 15 | filegroup( 16 | name = "all_files", 17 | testonly = True, 18 | srcs = glob(["**"]), 19 | visibility = ["//:__subpackages__"], 20 | ) 21 | -------------------------------------------------------------------------------- /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/bcr/.bazelrc: -------------------------------------------------------------------------------- 1 | common --enable_bzlmod 2 | build --@my_rules_go//go/toolchain:sdk_version=1.23.1 3 | -------------------------------------------------------------------------------- /tests/bcr/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /tests/bcr/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/bcr/WORKSPACE -------------------------------------------------------------------------------- /tests/bcr/lib.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | func Name() string { 4 | return "bzlmod" 5 | } 6 | -------------------------------------------------------------------------------- /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/mockable.go: -------------------------------------------------------------------------------- 1 | package mockable 2 | 3 | import "net/url" 4 | 5 | type Client interface { 6 | Connect(addr string) url.URL 7 | } 8 | -------------------------------------------------------------------------------- /tests/bcr/mockable_test.go: -------------------------------------------------------------------------------- 1 | package mockable 2 | 3 | var _ Client = (*MockClient)(nil) 4 | -------------------------------------------------------------------------------- /tests/bcr/other_module/BUILD.bazel: -------------------------------------------------------------------------------- 1 | exports_files(["bar.txt"]) 2 | -------------------------------------------------------------------------------- /tests/bcr/other_module/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module(name = "other_module") 2 | 3 | bazel_dep(name = "rules_go", version = "") 4 | 5 | go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") 6 | 7 | # Request an invalid SDK to verify that it isn't fetched since the test module registers a toolchain 8 | # that takes precedence. 9 | go_sdk.download(version = "3.0.0") 10 | -------------------------------------------------------------------------------- /tests/bcr/other_module/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/bcr/other_module/WORKSPACE -------------------------------------------------------------------------------- /tests/bcr/other_module/bar.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /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/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/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/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/bcr/test_go_sdk.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/os/dir.go b/src/os/dir.go 2 | index 5306bcb..d110a19 100644 3 | --- a/src/os/dir.go 4 | +++ b/src/os/dir.go 5 | @@ -17,6 +17,8 @@ const ( 6 | readdirFileInfo 7 | ) 8 | 9 | +const SayHello = "Hello" 10 | + 11 | // Readdir reads the contents of the directory associated with file and 12 | // returns a slice of up to n [FileInfo] values, as would be returned 13 | // by [Lstat], in directory order. Subsequent calls on the same file will yield 14 | -------------------------------------------------------------------------------- /tests/bcr/third_party/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@my_rules_go//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "third_party", 5 | srcs = ["lib.go"], 6 | importpath = "example.com/third_party", 7 | visibility = ["//visibility:public"], 8 | ) 9 | -------------------------------------------------------------------------------- /tests/bcr/third_party/lib.go: -------------------------------------------------------------------------------- 1 | package third_party 2 | 3 | func shadow() int { 4 | foo := 5 5 | if foo > 0 { 6 | // Trigger the "shadow" nogo error. 7 | foo := 6 8 | return foo 9 | } 10 | return foo 11 | } -------------------------------------------------------------------------------- /tests/bcr/wrap_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "runtime" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | func TestSdkVersion(t *testing.T) { 10 | if !strings.Contains(runtime.Version(), "1.23.6") { 11 | t.Fatal("Incorrect toolchain version", runtime.Version()) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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/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/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/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. -------------------------------------------------------------------------------- /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/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/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/c_linkmodes/add_sandwich.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | -------------------------------------------------------------------------------- /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_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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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.Int31n(100) 11 | b := rand.Int31n(100) 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/core/cgo/asm/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 2 | 3 | go_library( 4 | name = "asm", 5 | srcs = [ 6 | "asm_amd64.S", 7 | "asm_arm64.S", 8 | "cgoasm.go", 9 | ], 10 | cgo = True, 11 | importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/asm", 12 | visibility = ["//tests/core/cgo:__subpackages__"], 13 | ) 14 | 15 | go_test( 16 | name = "asm_test", 17 | srcs = [ 18 | "cgoasm_test.go", 19 | ], 20 | embed = [":asm"], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/core/cgo/asm/asm_amd64.S: -------------------------------------------------------------------------------- 1 | /* 2 | https://stackoverflow.com/questions/73435637/how-can-i-fix-usr-bin-ld-warning-trap-o-missing-note-gnu-stack-section-imp 3 | */ 4 | #if defined(__ELF__) && defined(__GNUC__) 5 | .section .note.GNU-stack,"",@progbits 6 | #endif 7 | 8 | /* 9 | define this symbol both with and without underscore. 10 | It seems like Mac OS X wants the underscore, but Linux does not. 11 | */ 12 | .global example_asm_func 13 | .global _example_asm_func 14 | .text 15 | example_asm_func: 16 | _example_asm_func: 17 | mov $42, %rax 18 | ret 19 | 20 | #if NOT_DEFINED 21 | #error "should not fail" 22 | #endif 23 | -------------------------------------------------------------------------------- /tests/core/cgo/asm/asm_arm64.S: -------------------------------------------------------------------------------- 1 | /* 2 | define this symbol both with and without underscore. 3 | It seems like Mac OS X wants the underscore, but Linux does not. 4 | */ 5 | .global example_asm_func 6 | .global _example_asm_func 7 | .p2align 2 /* ld: warning: arm64 function not 4-byte aligned */ 8 | example_asm_func: 9 | _example_asm_func: 10 | mov x0, #44 11 | ret 12 | 13 | #if NOT_DEFINED 14 | #error "should not fail" 15 | #endif 16 | -------------------------------------------------------------------------------- /tests/core/cgo/asm/cgoasm.go: -------------------------------------------------------------------------------- 1 | //go:build amd64 || arm64 2 | 3 | package asm 4 | 5 | /* 6 | extern int example_asm_func(); 7 | */ 8 | import "C" 9 | 10 | func CallAssembly() int { 11 | return int(C.example_asm_func()) 12 | } 13 | -------------------------------------------------------------------------------- /tests/core/cgo/asm/cgoasm_test.go: -------------------------------------------------------------------------------- 1 | //go:build amd64 || arm64 2 | 3 | package asm 4 | 5 | import ( 6 | "runtime" 7 | "testing" 8 | ) 9 | 10 | func TestNativeAssembly(t *testing.T) { 11 | expectedGOARCH := map[string]int{ 12 | "amd64": 42, 13 | "arm64": 44, 14 | } 15 | expected := expectedGOARCH[runtime.GOARCH] 16 | if expected == 0 { 17 | t.Fatalf("expected=0 for GOARCH=%s; missing value?", runtime.GOARCH) 18 | } 19 | actual := CallAssembly() 20 | if actual != expected { 21 | t.Errorf("callAssembly()=%d; expected=%d", actual, expected) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/core/cgo/asm_conditional_cgo/asm_amd64.S: -------------------------------------------------------------------------------- 1 | /* 2 | https://stackoverflow.com/questions/73435637/how-can-i-fix-usr-bin-ld-warning-trap-o-missing-note-gnu-stack-section-imp 3 | */ 4 | #if defined(__ELF__) && defined(__GNUC__) 5 | .section .note.GNU-stack,"",@progbits 6 | #endif 7 | 8 | /* 9 | define this symbol both with and without underscore. 10 | It seems like Mac OS X wants the underscore, but Linux does not. 11 | */ 12 | .global example_asm_func 13 | .global _example_asm_func 14 | .text 15 | example_asm_func: 16 | _example_asm_func: 17 | mov $42, %rax 18 | ret 19 | 20 | #if NOT_DEFINED 21 | #error "should not fail" 22 | #endif 23 | -------------------------------------------------------------------------------- /tests/core/cgo/asm_conditional_cgo/asm_arm64.S: -------------------------------------------------------------------------------- 1 | /* 2 | define this symbol both with and without underscore. 3 | It seems like Mac OS X wants the underscore, but Linux does not. 4 | */ 5 | .global example_asm_func 6 | .global _example_asm_func 7 | .p2align 2 /* ld: warning: arm64 function not 4-byte aligned */ 8 | example_asm_func: 9 | _example_asm_func: 10 | mov x0, #44 11 | ret 12 | 13 | #if NOT_DEFINED 14 | #error "should not fail" 15 | #endif 16 | -------------------------------------------------------------------------------- /tests/core/cgo/asm_conditional_cgo/asm_cgo.go: -------------------------------------------------------------------------------- 1 | //go:build amd64 || arm64 2 | 3 | // build constraints must match the constraints in the tests/core/cgo/asm package 4 | 5 | package main 6 | 7 | /* 8 | extern int example_asm_func(); 9 | */ 10 | import "C" 11 | 12 | func callASM() (int, error) { 13 | return int(C.example_asm_func()), nil 14 | } 15 | 16 | const builtWithCgo = true 17 | -------------------------------------------------------------------------------- /tests/core/cgo/asm_conditional_cgo/asm_nocgo.go: -------------------------------------------------------------------------------- 1 | //go:build !(cgo && (amd64 || arm64)) 2 | 3 | package main 4 | 5 | import "errors" 6 | 7 | func callASM() (int, error) { 8 | return 0, errors.New("cgo disabled and/or unsupported platform") 9 | } 10 | 11 | const builtWithCgo = false 12 | -------------------------------------------------------------------------------- /tests/core/cgo/asm_dep_conditional_cgo/asm_dep_cgo.go: -------------------------------------------------------------------------------- 1 | //go:build cgo && (amd64 || arm64) 2 | 3 | // build constraints must match the constraints in the tests/core/cgo/asm package 4 | 5 | package main 6 | 7 | import ( 8 | "github.com/bazelbuild/rules_go/tests/core/cgo/asm" 9 | ) 10 | 11 | func callASMPackage() (int, error) { 12 | return asm.CallAssembly(), nil 13 | } 14 | 15 | const builtWithCgo = true 16 | -------------------------------------------------------------------------------- /tests/core/cgo/asm_dep_conditional_cgo/asm_dep_nocgo.go: -------------------------------------------------------------------------------- 1 | //go:build !(cgo && (amd64 || arm64)) 2 | 3 | // build constraints must match the constraints in the tests/core/cgo/asm package 4 | 5 | package main 6 | 7 | import "errors" 8 | 9 | func callASMPackage() (int, error) { 10 | return 0, errors.New("cgo disabled and/or unsupported platform") 11 | } 12 | 13 | const builtWithCgo = false 14 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /tests/core/cgo/cgo_required_test.go: -------------------------------------------------------------------------------- 1 | //go:build cgo 2 | // +build cgo 3 | 4 | package cgo_required 5 | 6 | import "testing" 7 | 8 | // Without correct filtering, gentestmain will try to link against this test 9 | // that does not exist with pure = True 10 | func TestHelloWorld(t *testing.T) {} 11 | -------------------------------------------------------------------------------- /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/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/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/cgo/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo() { 4 | printf("foo\n"); 5 | } 6 | 7 | 8 | -------------------------------------------------------------------------------- /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/imported.c: -------------------------------------------------------------------------------- 1 | int foo() { return 42; } 2 | -------------------------------------------------------------------------------- /tests/core/cgo/native_dep.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void native_greeting(void) { 4 | printf("Hello, world!\n"); 5 | } 6 | -------------------------------------------------------------------------------- /tests/core/cgo/native_dep.h: -------------------------------------------------------------------------------- 1 | extern void native_greeting(void); 2 | -------------------------------------------------------------------------------- /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/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/add_darwin.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/cgo/pure.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/cgo/race_off.c: -------------------------------------------------------------------------------- 1 | // +build !race 2 | 3 | int race_enabled = 0; 4 | -------------------------------------------------------------------------------- /tests/core/cgo/race_off.go: -------------------------------------------------------------------------------- 1 | // +build !race 2 | 3 | package race 4 | 5 | const goRaceEnabled = false 6 | -------------------------------------------------------------------------------- /tests/core/cgo/race_on.c: -------------------------------------------------------------------------------- 1 | // +build race 2 | 3 | int race_enabled = 1; 4 | -------------------------------------------------------------------------------- /tests/core/cgo/race_on.go: -------------------------------------------------------------------------------- 1 | // +build race 2 | 3 | package race 4 | 5 | const goRaceEnabled = true 6 | -------------------------------------------------------------------------------- /tests/core/cgo/split_import_a.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | func Answer() int { return 42 } 4 | -------------------------------------------------------------------------------- /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/cgo/split_import_c.c: -------------------------------------------------------------------------------- 1 | int half(int x) { return x/2; } 2 | 3 | -------------------------------------------------------------------------------- /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/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/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/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/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/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.go: -------------------------------------------------------------------------------- 1 | // +build !cgo 2 | 3 | package main 4 | 5 | import "fmt" 6 | 7 | func main() { 8 | fmt.Println("pure") 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/cgo/tag_pure_err.c: -------------------------------------------------------------------------------- 1 | #error should not be compiled 2 | -------------------------------------------------------------------------------- /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/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_c_symbol_through_go.c: -------------------------------------------------------------------------------- 1 | #include "tests/core/cgo/use_transitive_symbol.h" 2 | 3 | int main() { 4 | PrintGreeting(); 5 | } 6 | -------------------------------------------------------------------------------- /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/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/compatibility/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_binary", "go_cross_binary") 2 | 3 | go_binary( 4 | name = "hello", 5 | srcs = ["hello.go"], 6 | ) 7 | 8 | go_cross_binary( 9 | name = "hello_old", 10 | sdk_version = "1.22", 11 | target = ":hello", 12 | ) 13 | -------------------------------------------------------------------------------- /tests/core/compatibility/README.md: -------------------------------------------------------------------------------- 1 | # Compatibility 2 | 3 | ## compatibility_test 4 | 5 | Verifies that a simple Go project builds with an older version of Go. 6 | -------------------------------------------------------------------------------- /tests/core/compatibility/hello.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("hello") 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/cross/asm.s: -------------------------------------------------------------------------------- 1 | // Example assembly copied from https://github.com/rpccloud/goid 2 | 3 | #include "go_asm.h" 4 | #include "textflag.h" 5 | 6 | #ifdef GOARCH_386 7 | #define get_tls(r) MOVL TLS, r 8 | #define g(r) 0(r)(TLS*1) 9 | #endif 10 | 11 | TEXT ·getg(SB), NOSPLIT, $0-4 12 | get_tls(CX) 13 | MOVL g(CX), AX 14 | MOVL AX, ret+0(FP) 15 | RET 16 | -------------------------------------------------------------------------------- /tests/core/cross/lib_darwin.go: -------------------------------------------------------------------------------- 1 | package platform_lib 2 | 3 | const Platform = "darwin" 4 | -------------------------------------------------------------------------------- /tests/core/cross/lib_linux.go: -------------------------------------------------------------------------------- 1 | package platform_lib 2 | 3 | const Platform = "linux" 4 | -------------------------------------------------------------------------------- /tests/core/cross/lib_windows.go: -------------------------------------------------------------------------------- 1 | package platform_lib 2 | 3 | const Platform = "windows" 4 | -------------------------------------------------------------------------------- /tests/core/from_go_mod_file/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "from_go_mod_file_test", 5 | srcs = ["from_go_mod_file_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/from_go_mod_file/README.rst: -------------------------------------------------------------------------------- 1 | from_go_mod_file 2 | ================ 3 | 4 | from_go_mod_file_test 5 | --------------------- 6 | Verifies that ``go_sdk.from_file`` can be used to fetch the Go SDK version 7 | that is described by the toolchain in ``go.mod``. 8 | -------------------------------------------------------------------------------- /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_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/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/core/go_binary/custom_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /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/meaning.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "fmt" 5 | "github.com/bazelbuild/rules_go/tests/core/usesyso" 6 | ) 7 | 8 | func main() { 9 | fmt.Println("The meaning of life is:", usesyso.Foo()) 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/go_binary/meaning2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "fmt" 5 | ) 6 | 7 | func foo() int 8 | 9 | func main() { 10 | fmt.Println("The meaning of life is:", foo()) 11 | } 12 | -------------------------------------------------------------------------------- /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_binary/pgo.pprof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_binary/pgo.pprof -------------------------------------------------------------------------------- /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_binary/prefix/prefix.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /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/go_binary/stamp_dep.go: -------------------------------------------------------------------------------- 1 | package stamp_dep 2 | 3 | var ( 4 | DepSelf = "redacted" 5 | DepBin = "redacted" 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/go_binary/stamp_embed.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var Embed = "redacted" 4 | -------------------------------------------------------------------------------- /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/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_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_binary/static_pure_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "net" 5 | _ "os" 6 | ) 7 | 8 | func main() {} 9 | -------------------------------------------------------------------------------- /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_lib_good.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/go_binary/tags_main_bad.go: -------------------------------------------------------------------------------- 1 | // +build !good 2 | 3 | package main 4 | 5 | var Does Not = Compile 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/core/go_binary/testing_testing.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | if testing.Testing() { 11 | panic("testing.Testing() returned 'true' in a binary") 12 | } 13 | 14 | file, err := os.Create(os.Args[1]) 15 | if err != nil { 16 | panic(fmt.Sprintf("Failed to open output file %s", err)) 17 | } 18 | file.Close() 19 | } 20 | -------------------------------------------------------------------------------- /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_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/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/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/embedsrcs_static/contains_hidden/.hidden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/dir/_no: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/dir/_no -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/dir/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/dir/f -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/file -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/glob/_hidden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/glob/_hidden -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/glob/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/glob/f -------------------------------------------------------------------------------- /tests/core/go_library/embedsrcs_static/no: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/embedsrcs_static/no -------------------------------------------------------------------------------- /tests/core/go_library/empty_bar.go: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | 3 | package bar 4 | -------------------------------------------------------------------------------- /tests/core/go_library/empty_baz.s: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | -------------------------------------------------------------------------------- /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/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/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/go_library/imported.c: -------------------------------------------------------------------------------- 1 | int foo() { return 42; } 2 | -------------------------------------------------------------------------------- /tests/core/go_library/inc.go: -------------------------------------------------------------------------------- 1 | package inc 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_library/inc_foo.s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_library/inc_foo.s -------------------------------------------------------------------------------- /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/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/core/go_library/package_height_dep_shallow.go: -------------------------------------------------------------------------------- 1 | package dep 2 | 3 | type T struct{} 4 | -------------------------------------------------------------------------------- /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_library/package_height_embedder.go: -------------------------------------------------------------------------------- 1 | package embed 2 | 3 | var X = T{} 4 | -------------------------------------------------------------------------------- /tests/core/go_library/use_syso.go: -------------------------------------------------------------------------------- 1 | package usesyso 2 | 3 | func foo() int32 4 | 5 | func Foo() int32 { 6 | return foo() 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_library/wrap_imported_amd64.s: -------------------------------------------------------------------------------- 1 | // +build amd64 2 | 3 | #include "textflag.h" 4 | 5 | TEXT ·foo(SB), NOSPLIT, $0-4 6 | CALL foo(SB) 7 | MOVL AX, ret+0(FP) 8 | RET 9 | -------------------------------------------------------------------------------- /tests/core/go_library/wrap_imported_arm64.s: -------------------------------------------------------------------------------- 1 | // +build arm64 2 | 3 | #include "textflag.h" 4 | 5 | TEXT ·foo(SB), NOSPLIT, $0-4 6 | BL foo(SB) 7 | MOVW R0, ret+0(FP) 8 | RET 9 | -------------------------------------------------------------------------------- /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/core/go_path/cmd/bin/bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /tests/core/go_path/extra.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_path/extra.txt -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/data.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_path/pkg/lib/data.txt -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/embed_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/embedded_src.txt: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/external_test.go: -------------------------------------------------------------------------------- 1 | package lib_test 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/internal_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /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/core/go_path/pkg/lib/template/index.html.tmpl: -------------------------------------------------------------------------------- 1 | {{ .Content }} 2 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/testdata/testdata.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_path/pkg/lib/testdata/testdata.txt -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/transitive.go: -------------------------------------------------------------------------------- 1 | package transitive 2 | 3 | var ( 4 | _ = "" 5 | ) 6 | -------------------------------------------------------------------------------- /tests/core/go_path/pkg/lib/vendored.go: -------------------------------------------------------------------------------- 1 | package vendored 2 | -------------------------------------------------------------------------------- /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/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/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_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/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/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/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_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_proto_aspect/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 2 | load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") 3 | load(":codegen.bzl", "go_generated_library") 4 | 5 | go_generated_library( 6 | name = "go_generated", 7 | importpath = "github.com/bazelbuild/rules_go/tests/core/go_proto_aspect", 8 | visibility = ["//visibility:public"], 9 | ) 10 | 11 | proto_library( 12 | name = "foo_proto", 13 | srcs = ["foo.proto"], 14 | ) 15 | 16 | go_proto_library( 17 | name = "foo_go_proto", 18 | importpath = "github.com/bazelbuild/rules_go/tests/core/go_proto_aspectpb", 19 | proto = ":foo_proto", 20 | deps = [":go_generated"], 21 | ) 22 | -------------------------------------------------------------------------------- /tests/core/go_proto_aspect/README.rst: -------------------------------------------------------------------------------- 1 | go_proto_library _go_proto_aspect 2 | ========================== 3 | 4 | _go_proto_aspect test 5 | -------------- 6 | 7 | Checks that the ``_go_proto_aspect`` used by ``go_proto_library`` works without assuming the ``deps`` are either ``go_library`` 8 | or ``go_proto_library`` targets. The test uses a custom code generator rule that provides ``GoInfo``, which is the only requirement 9 | of ``go_proto_library``'s ``deps``, but it doesn't have all the attributes of ``go_library`` or ``go_proto_library``. 10 | -------------------------------------------------------------------------------- /tests/core/go_proto_aspect/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.core.go_proto_aspect.foo; 4 | option go_package = "go_proto_aspectpb"; 5 | 6 | message Foo { 7 | int64 value = 1; 8 | } 9 | -------------------------------------------------------------------------------- /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/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/adjusted_c.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package adjusted.c; 4 | 5 | message C { 6 | int64 c = 1; 7 | } 8 | -------------------------------------------------------------------------------- /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/core/go_proto_library/enum.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tests.core.go_proto_library.enum; 3 | option go_package = "github.com/bazelbuild/rules_go/tests/core/go_proto_library/enum"; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | extend google.protobuf.EnumValueOptions { 8 | optional string db_enum = 5002; 9 | } 10 | 11 | 12 | enum Enum { 13 | INVALID = 0; 14 | BYTES = 1 [(tests.core.go_proto_library.enum.db_enum) = "bytes_type"]; 15 | INT32 = 2; 16 | } 17 | -------------------------------------------------------------------------------- /tests/core/go_proto_library/extra.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | func Extra() int { 4 | return 42 5 | } 6 | -------------------------------------------------------------------------------- /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/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/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_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/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/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("@com_google_protobuf//bazel:proto_library.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/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/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/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/core/go_proto_library_importpath/bar.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.core.go_proto_library_importpath.bar; 4 | 5 | import "tests/core/go_proto_library_importpath/foo.proto"; 6 | 7 | message Bar { 8 | foo.Foo value = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/core/go_proto_library_importpath/foo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tests.core.go_proto_library_importpath.foo; 4 | 5 | message Foo { 6 | int64 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/core/go_proto_library_importpath/importpath_test.go: -------------------------------------------------------------------------------- 1 | package importpath_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | bar_proto "tests/core/go_proto_library_importpath/bar_go_proto" 8 | foo_proto "path/to/foo_go" 9 | ) 10 | 11 | func Test(t *testing.T) { 12 | bar := &bar_proto.Bar{} 13 | bar.Value = &foo_proto.Foo{} 14 | bar.Value.Value = 5 15 | 16 | var expected int64 = 5 17 | if bar.Value.Value != expected { 18 | t.Errorf(fmt.Sprintf("Not equal: \n"+ 19 | "expected: %d\n"+ 20 | "actual : %d", expected, bar.Value.Value)) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/indirect_import_lib.go: -------------------------------------------------------------------------------- 1 | package indirect_import 2 | 3 | var X string = "not set" 4 | -------------------------------------------------------------------------------- /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/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/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/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/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/core/go_test/sharding_test.go: -------------------------------------------------------------------------------- 1 | package sharding_test 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "testing" 7 | ) 8 | 9 | func TestShardStatusFile(t *testing.T) { 10 | if _, err := os.Stat(os.Getenv("TEST_SHARD_STATUS_FILE")); err != nil { 11 | log.Fatalf("Expected Go test runner to create TEST_SHARD_STATUS_FILE: %v", err) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/core/go_test/syso_direct_test.go: -------------------------------------------------------------------------------- 1 | package sysod 2 | 3 | import( 4 | "testing" 5 | ) 6 | 7 | func foo() int32 8 | 9 | func TestSysoDirect(t *testing.T) { 10 | want := int32(42) 11 | got := foo() 12 | if want != got { 13 | t.Errorf("want: %d, got %d", want, got) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/core/go_test/syso_transitive_test.go: -------------------------------------------------------------------------------- 1 | package syso 2 | 3 | import( 4 | "testing" 5 | "github.com/bazelbuild/rules_go/tests/core/usesyso" 6 | ) 7 | 8 | func TestSysoTransitive(t *testing.T) { 9 | want := int32(42) 10 | got := usesyso.Foo() 11 | if want != got { 12 | t.Errorf("want: %d, got %d", want, got) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /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/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/core/go_test/testing_testing_test.go: -------------------------------------------------------------------------------- 1 | package testing_testing 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMain(m *testing.M) { 8 | if ! testing.Testing() { 9 | panic("testing.Testing() returned 'false' in a test") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /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/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/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/core/go_test/x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_test/x -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/foo.go: -------------------------------------------------------------------------------- 1 | package foo 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/qux.go: -------------------------------------------------------------------------------- 1 | package qux 2 | 3 | var Qux string 4 | -------------------------------------------------------------------------------- /tests/core/go_test/x_defs/x_defs_lib.go: -------------------------------------------------------------------------------- 1 | package x_defs_lib 2 | 3 | var LibGo = "not set" 4 | 5 | var DataDep = "not set" 6 | -------------------------------------------------------------------------------- /tests/core/go_test/y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_test/y -------------------------------------------------------------------------------- /tests/core/go_test/z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/go_test/z -------------------------------------------------------------------------------- /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/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/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/core/nogo/bzlmod/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "includes_exclude_test", 5 | srcs = ["includes_excludes_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/bzlmod/README.rst: -------------------------------------------------------------------------------- 1 | Nogo Bzlmod configuration 2 | ================== 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _Bzlmod: /docs/go/core/bzlmod.md 6 | 7 | Tests that verify nogo_ works when configured from ``MODULE.bazel``. 8 | 9 | .. contents:: 10 | 11 | includes_excludes_test 12 | ----------- 13 | 14 | Verifies that `go_library`_ targets can be built in default configurations with 15 | nogo with includes and excludes being honored. 16 | -------------------------------------------------------------------------------- /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/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/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_cgo_test", 5 | srcs = ["coverage_cgo_test.go"], 6 | ) 7 | 8 | go_bazel_test( 9 | name = "coverage_test", 10 | srcs = ["coverage_test.go"], 11 | ) 12 | 13 | go_bazel_test( 14 | name = "gen_code_test", 15 | srcs = ["gen_code_test.go"], 16 | ) 17 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/core/nogo/includes_excludes/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "includes_exclude_test", 5 | srcs = ["includes_excludes_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/includes_excludes/README.rst: -------------------------------------------------------------------------------- 1 | Nogo excludes-includes configuration 2 | ================== 3 | 4 | .. _nogo: /go/nogo.rst 5 | 6 | Tests that verify nogo_ `includes` and `excludes` works when configured from ``WORKSPACE.bazel``. 7 | 8 | .. contents:: 9 | 10 | includes_excludes_test 11 | ----------- 12 | 13 | Verifies that `go_library`_ targets can be built in default configurations with 14 | nogo with includes and excludes being honored. 15 | -------------------------------------------------------------------------------- /tests/core/nogo/nolint/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "nolint_test", 5 | srcs = ["nolint_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/nolint/README.rst: -------------------------------------------------------------------------------- 1 | Nolint check 2 | ========= 3 | 4 | .. _go_library: /docs/go/core/rules.md#_go_library 5 | 6 | Tests to ensure that errors found by nogo and annotated with //nolint are 7 | ignored. 8 | 9 | .. contents:: 10 | 11 | nolint_test 12 | -------- 13 | Verified that errors emitted by ``nogo`` are ignored when `//nolint` appears as 14 | a comment. 15 | -------------------------------------------------------------------------------- /tests/core/nogo/tests/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "tests_test", 5 | srcs = ["tests_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/nogo/tests/README.rst: -------------------------------------------------------------------------------- 1 | nogo for go_test 2 | ============================= 3 | 4 | .. _nogo: /go/nogo.rst 5 | .. _go_test: /docs/go/core/rules.md#_go_test 6 | 7 | Verifies interactions between `nogo`_ and `go_test`_. 8 | 9 | 10 | tests_test 11 | ============================= 12 | 13 | Tests that `nogo`_ can handle various edge cases of external tests. 14 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/core/output_groups/bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/output_groups/lib.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /tests/core/output_groups/lib_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | -------------------------------------------------------------------------------- /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/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/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/runfiles/empty_bin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /tests/core/runfiles/local_file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/runfiles/local_file.txt -------------------------------------------------------------------------------- /tests/core/runfiles/local_group.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/runfiles/local_group.txt -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "runfiles_remote_test") 2 | -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/remote_pkg/remote_file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/runfiles/runfiles_remote_test/remote_pkg/remote_file.txt -------------------------------------------------------------------------------- /tests/core/runfiles/runfiles_remote_test/remote_pkg/remote_group.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/runfiles/runfiles_remote_test/remote_pkg/remote_group.txt -------------------------------------------------------------------------------- /tests/core/starlark/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":common_tests.bzl", "common_test_suite") 2 | load(":context_tests.bzl", "context_test_suite") 3 | load(":provider_tests.bzl", "provider_test_suite") 4 | load(":sdk_tests.bzl", "sdk_test_suite") 5 | 6 | common_test_suite() 7 | 8 | context_test_suite() 9 | 10 | provider_test_suite() 11 | 12 | sdk_test_suite() 13 | -------------------------------------------------------------------------------- /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/core/starlark/cgo/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/private:common.bzl", "GO_TOOLCHAIN") 2 | load(":cgo_test.bzl", "cgo_test_suite") 3 | 4 | constraint_value( 5 | name = "os_does_not_exist", 6 | constraint_setting = "@platforms//os:os", 7 | ) 8 | 9 | # Make a platform we know won't have a C++ toolchain registered for it. 10 | platform( 11 | name = "platform_has_no_cc_toolchain", 12 | constraint_values = [":os_does_not_exist"], 13 | ) 14 | 15 | # Make a fake Go toolchain for this platform 16 | toolchain( 17 | name = "fake_go_toolchain", 18 | target_compatible_with = [ 19 | ":os_does_not_exist", 20 | ], 21 | toolchain = "@go_sdk//:go_linux_amd64-impl", 22 | toolchain_type = GO_TOOLCHAIN, 23 | ) 24 | 25 | cgo_test_suite() 26 | -------------------------------------------------------------------------------- /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/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/a/a.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | func A() { 4 | return 5 | } 6 | -------------------------------------------------------------------------------- /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/core/starlark/packagedriver/fixtures/b/b.go: -------------------------------------------------------------------------------- 1 | package b 2 | 3 | func B() { 4 | return 5 | } 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | deps = ["//go/runfiles"], 9 | ) 10 | 11 | stdlib_files(name = "stdlib_files") 12 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/core/strip/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") 2 | 3 | go_bazel_test( 4 | name = "strip_test", 5 | srcs = ["strip_test.go"], 6 | ) 7 | -------------------------------------------------------------------------------- /tests/core/strip/README.rst: -------------------------------------------------------------------------------- 1 | symbol stripping 2 | ==================== 3 | 4 | strip_test 5 | --------- 6 | 7 | Tests that the global Bazel configuration for stripping are applied to go_binary 8 | targets. 9 | In particular, it tests that stripping is performed iff the bazel flag ``--strip`` 10 | is set to ``always`` or ``--strip`` is set to ``sometimes`` and ``--compilation_mode`` 11 | is ``fastbuild``. 12 | Additionally, it tests that stack traces still contain the same information when stripping 13 | is enabled. 14 | -------------------------------------------------------------------------------- /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/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/core/transitive_headers/a/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "a", 5 | srcs = [ 6 | "a.go", 7 | "a.s", 8 | ], 9 | deps = ["//tests/core/transitive_headers/b"], 10 | importpath = "github.com/bazelbuild/rules_go/tests/core/transitive_headers/a", 11 | ) 12 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/a/a.go: -------------------------------------------------------------------------------- 1 | package a 2 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/a/a.s: -------------------------------------------------------------------------------- 1 | #include "../b/b.h" 2 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/b/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "b", 5 | srcs = [ 6 | "b.go", 7 | "b.h", 8 | ], 9 | deps = ["//tests/core/transitive_headers/c"], 10 | importpath = "github.com/bazelbuild/rules_go/tests/core/transitive_headers/b", 11 | visibility = ["//visibility:public"], 12 | ) 13 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/b/b.go: -------------------------------------------------------------------------------- 1 | package b 2 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/b/b.h: -------------------------------------------------------------------------------- 1 | #include "../c/c.h" 2 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/c/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "c", 5 | srcs = [ 6 | "c.go", 7 | "c.h", 8 | ], 9 | importpath = "github.com/bazelbuild/rules_go/tests/core/transitive_headers/c", 10 | visibility = ["//visibility:public"], 11 | ) 12 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/c/c.go: -------------------------------------------------------------------------------- 1 | package c 2 | -------------------------------------------------------------------------------- /tests/core/transitive_headers/c/c.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/core/transitive_headers/c/c.h -------------------------------------------------------------------------------- /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/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/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/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/extras/gomock/README.rst: -------------------------------------------------------------------------------- 1 | 2 | ===================== 3 | 4 | Tests that ensure the gomock rules can be called correctly under different input permutations. 5 | 6 | reflective 7 | ------------------------ 8 | Checks that gomock can be run in "reflective" mode when passed a `GoInfo` and `interfaces`. 9 | 10 | source 11 | ------------------------ 12 | Checks that gomock can be run in "source" mode when passed a `GoInfo` and `source`. 13 | 14 | source_with_importpath 15 | ------------------------ 16 | Checks that gomock can be run in "source" mode when passed an `importpath` and `source`. 17 | This test case also demonstrates the circumstance in which `importpath` is necessary to prevent a circular dependency. 18 | -------------------------------------------------------------------------------- /tests/extras/gomock/reflective/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/extras/gomock/reflective/client_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | var _ Client = (*MockClient)(nil) 4 | -------------------------------------------------------------------------------- /tests/extras/gomock/source/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/extras/gomock/source/client_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | var _ Client = (*MockClient)(nil) 4 | -------------------------------------------------------------------------------- /tests/extras/gomock/source/client_wrapper.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | type ClientWrapper interface { 4 | Client 5 | Close() error 6 | } 7 | -------------------------------------------------------------------------------- /tests/extras/gomock/source_with_importpath/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/extras/gomock/source_with_importpath/client_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | var _ Client = (*MockClient)(nil) 4 | -------------------------------------------------------------------------------- /tests/go.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/go.mod -------------------------------------------------------------------------------- /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/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 | ) 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/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/integration/googleapis/README.rst: -------------------------------------------------------------------------------- 1 | Functionality related to Google APIs 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 Google APIs. 9 | -------------------------------------------------------------------------------- /tests/integration/grpc_plugin/README.rst: -------------------------------------------------------------------------------- 1 | Testing that the protoc-gen-go-grpc plugin works 2 | ======================================= 3 | 4 | hello_test 5 | ------------------ 6 | 7 | Verifies that the generated code for a simple gRPC service: 8 | - exposes a `pb.UnimplementedGreetServer` style struct 9 | - exposes a `pb.RegisterGreetServer` method that accepts a `grpc.ServiceRegistrar` instead of a raw `*grpc.Server` 10 | -------------------------------------------------------------------------------- /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/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/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/asm_include/foo_amd64.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | func foo() int32 4 | -------------------------------------------------------------------------------- /tests/legacy/asm_include/foo_amd64.h: -------------------------------------------------------------------------------- 1 | #define FOOVAL 42 2 | -------------------------------------------------------------------------------- /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/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/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/binary_test_outputs/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/build_constraints/build_constraints_test.go: -------------------------------------------------------------------------------- 1 | package build_constraints 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | ) 7 | 8 | func check(value string, t *testing.T) { 9 | var want string 10 | if runtime.GOOS == "linux" { 11 | want = "linux" 12 | } else { 13 | want = "unknown" 14 | } 15 | if value != want { 16 | t.Errorf("got %s; want %s", value, want) 17 | } 18 | } 19 | 20 | func TestSuffix(t *testing.T) { 21 | check(suffix, t) 22 | } 23 | 24 | func TestTag(t *testing.T) { 25 | check(tag, t) 26 | } 27 | 28 | func TestCgoGo(t *testing.T) { 29 | check(cgoGo, t) 30 | } 31 | 32 | func TestCgoC(t *testing.T) { 33 | check(cgoC, t) 34 | } 35 | 36 | func TestCgoCGroup(t *testing.T) { 37 | check(cgoCGroup, t) 38 | } 39 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_group_linux.c: -------------------------------------------------------------------------------- 1 | const char* cgoCGroup = "linux"; 2 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_group_unknown.c: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | const char* cgoCGroup = "unknown"; 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/cgo_linux.c: -------------------------------------------------------------------------------- 1 | const char* cgoC = "linux"; 2 | -------------------------------------------------------------------------------- /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/legacy/build_constraints/cgo_unknown.c: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | const char* cgoC = "unknown"; 4 | -------------------------------------------------------------------------------- /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/build_constraints/suffix_linux.go: -------------------------------------------------------------------------------- 1 | package build_constraints 2 | 3 | var suffix = "linux" 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/suffix_unknown.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package build_constraints 4 | 5 | var suffix = "unknown" 6 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/tag_l.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package build_constraints 4 | 5 | var tag = "linux" 6 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints/tag_unknown.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package build_constraints 4 | 5 | var tag = "unknown" 6 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints_go_asm/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 = ["build_constraints_go_asm_test.go"], 7 | embed = [":go_default_library"], 8 | ) 9 | 10 | go_library( 11 | name = "go_default_library", 12 | srcs = [ 13 | # Check that constraints apply to assembly files. 14 | "asm_arm64.s", 15 | "asm_linux_amd64.s", 16 | "asm_unknown.s", 17 | ], 18 | cgo = False, 19 | importpath = "github.com/bazelbuild/rules_go/tests/build_constraints_go_asm", 20 | ) 21 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints_go_asm/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/legacy/build_constraints_go_asm/asm_linux_amd64.s: -------------------------------------------------------------------------------- 1 | TEXT ·asm(SB),$0-0 2 | MOVQ $12,RET(FP) 3 | RET 4 | -------------------------------------------------------------------------------- /tests/legacy/build_constraints_go_asm/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_go_asm/build_constraints_go_asm_test.go: -------------------------------------------------------------------------------- 1 | package build_constraints_go_asm 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | ) 7 | 8 | func asm() int 9 | 10 | func TestAsm(t *testing.T) { 11 | got := asm() 12 | var want int 13 | if runtime.GOOS == "linux" { 14 | want = 12 15 | } else if runtime.GOARCH == "arm64" { 16 | want = 75 17 | } else { 18 | want = 34 19 | } 20 | if got != want { 21 | t.Errorf("got %d; want %d", got, want) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /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/cgo_filtered/pure.go: -------------------------------------------------------------------------------- 1 | package cgo_filtered 2 | 3 | var Value = 42 4 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/cgo_pure/cgo.c: -------------------------------------------------------------------------------- 1 | const int value = 2; 2 | -------------------------------------------------------------------------------- /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/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_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 | -------------------------------------------------------------------------------- /tests/legacy/cgo_pure/pure.go: -------------------------------------------------------------------------------- 1 | //+build !cgo 2 | 3 | package cgo_pure 4 | 5 | var Value = 1 6 | -------------------------------------------------------------------------------- /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_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/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_select/darwin.c: -------------------------------------------------------------------------------- 1 | const char* goos = "darwin"; 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/linux.c: -------------------------------------------------------------------------------- 1 | const char* goos = "linux"; 2 | -------------------------------------------------------------------------------- /tests/legacy/cgo_select/windows.c: -------------------------------------------------------------------------------- 1 | const char* goos = "windows"; 2 | -------------------------------------------------------------------------------- /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/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/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/cgo_sys_hdr/sub/foo.h: -------------------------------------------------------------------------------- 1 | int x = 42; 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/legacy/cgo_trans_deps/dep/dep.go: -------------------------------------------------------------------------------- 1 | package dep 2 | 3 | var X = 42 4 | -------------------------------------------------------------------------------- /tests/legacy/empty_package/cgo.c: -------------------------------------------------------------------------------- 1 | const int value = 2; 2 | -------------------------------------------------------------------------------- /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/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/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/legacy/empty_package/mixed_pure.go: -------------------------------------------------------------------------------- 1 | //+build !cgo 2 | 3 | package mixed 4 | 5 | var Value = 1 6 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/legacy/examples/cgo/pure_go.go: -------------------------------------------------------------------------------- 1 | package cgo 2 | 3 | func PrintCXXVersion() { 4 | printCXXVersion() 5 | } 6 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /tests/legacy/examples/cgo/skip_go_library/types.go: -------------------------------------------------------------------------------- 1 | package skip_go_library 2 | 3 | type Type struct{} 4 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/legacy/examples/proto/dep/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 2 | load("@com_google_protobuf//bazel:proto_library.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/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/legacy/examples/proto/embed/embed.go: -------------------------------------------------------------------------------- 1 | package embed 2 | 3 | func OtherThing() *EmbedExample { 4 | return &EmbedExample{ 5 | A: 42, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /tests/legacy/examples/proto/lib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") 2 | load("@com_google_protobuf//bazel:proto_library.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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/legacy/extldflags_rpath/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() {} 4 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/legacy/package_named_build/build/build.go: -------------------------------------------------------------------------------- 1 | package build 2 | 3 | const Foo = 42 4 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/legacy/providers/test.bzl: -------------------------------------------------------------------------------- 1 | load("//go:def.bzl", "GoInfo") 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 = [GoInfo], 12 | ), 13 | }, 14 | ) 15 | -------------------------------------------------------------------------------- /tests/legacy/providers/test.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/legacy/providers/test.go -------------------------------------------------------------------------------- /tests/legacy/providers/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exit 0 -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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_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/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_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/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/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/test_chdir/data.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/legacy/test_chdir/data.txt -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/c_data.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/legacy/transitive_data/c_data.txt -------------------------------------------------------------------------------- /tests/legacy/transitive_data/cgo_data.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/legacy/transitive_data/cgo_data.txt -------------------------------------------------------------------------------- /tests/legacy/transitive_data/empty.go: -------------------------------------------------------------------------------- 1 | package go_lib 2 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/empty_cgo.go: -------------------------------------------------------------------------------- 1 | package go_lib 2 | 3 | import "C" 4 | -------------------------------------------------------------------------------- /tests/legacy/transitive_data/go_data.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_go/8e7d9cdba62a6c56267d12bba6599a6c31eaf704/tests/legacy/transitive_data/go_data.txt -------------------------------------------------------------------------------- /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/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/legacy/visibility/foo.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | const Foo = 1 4 | -------------------------------------------------------------------------------- /tests/runfiles/defs.bzl: -------------------------------------------------------------------------------- 1 | def _root_symlinks_impl(ctx): 2 | return [ 3 | DefaultInfo( 4 | runfiles = ctx.runfiles( 5 | root_symlinks = { 6 | "link_" + f.basename: f 7 | for f in ctx.files.data 8 | }, 9 | ), 10 | ), 11 | ] 12 | 13 | root_symlinks = rule( 14 | implementation = _root_symlinks_impl, 15 | attrs = { 16 | "data": attr.label_list(allow_files = True), 17 | }, 18 | ) 19 | -------------------------------------------------------------------------------- /tests/runfiles/test.txt: -------------------------------------------------------------------------------- 1 | hi! 2 | -------------------------------------------------------------------------------- /tests/runfiles/test_dir/file.txt: -------------------------------------------------------------------------------- 1 | file 2 | -------------------------------------------------------------------------------- /tests/runfiles/test_dir/subdir/other_file.txt: -------------------------------------------------------------------------------- 1 | other_file 2 | -------------------------------------------------------------------------------- /tests/runfiles/testfs/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | go_library( 4 | name = "testfs", 5 | srcs = ["testfs.go"], 6 | importpath = "github.com/bazelbuild/rules_go/go/tests/runfiles/testfs", 7 | visibility = ["//visibility:public"], 8 | ) 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tools.go: -------------------------------------------------------------------------------- 1 | //go:build tools 2 | 3 | package rules_go 4 | 5 | // These imports only exist to keep go.mod entries for packages that are referenced in BUILD files, 6 | // but not in Go code. 7 | 8 | import ( 9 | _ "github.com/gogo/protobuf/proto" 10 | _ "github.com/golang/mock/mockgen" 11 | _ "github.com/golang/protobuf/protoc-gen-go" 12 | _ "golang.org/x/net/context" 13 | _ "google.golang.org/genproto/protobuf/api" 14 | _ "google.golang.org/grpc" 15 | _ "google.golang.org/protobuf/cmd/protoc-gen-go" 16 | _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" 17 | ) 18 | -------------------------------------------------------------------------------- /tools/gopackagesdriver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | exec bazel run --tool_tag=gopackagesdriver -- //go/tools/gopackagesdriver "${@}" 3 | --------------------------------------------------------------------------------