diff --git a/tests/cc/current_py_cc_libs/BUILD.bazel b/tests/cc/current_py_cc_libs/BUILD.bazel index 1e108c3132..fb61435d37 100644 --- a/tests/cc/current_py_cc_libs/BUILD.bazel +++ b/tests/cc/current_py_cc_libs/BUILD.bazel @@ -15,3 +15,19 @@ load(":current_py_cc_libs_tests.bzl", "current_py_cc_libs_test_suite") current_py_cc_libs_test_suite(name = "current_py_cc_libs_tests") + +# buildifier: disable=native-cc +cc_test( + name = "python_libs_linking_test", + srcs = ["python_libs_linking_test.cc"], + # Mac and Windows fail with linking errors, but its not clear why; someone + # with more C + Mac/Windows experience will have to figure it out. + # - rickeylev@ + target_compatible_with = [ + "@platforms//os:linux", + ], + deps = [ + "@rules_python//python/cc:current_py_cc_headers", + "@rules_python//python/cc:current_py_cc_libs", + ], +) diff --git a/tests/cc/current_py_cc_libs/python_libs_linking_test.cc b/tests/cc/current_py_cc_libs/python_libs_linking_test.cc new file mode 100644 index 0000000000..1ecce088b6 --- /dev/null +++ b/tests/cc/current_py_cc_libs/python_libs_linking_test.cc @@ -0,0 +1,18 @@ +#include + +int main(int argc, char** argv) { + // Early return to prevent the broken code below from running. + if (argc >= 1) { + return 0; + } + + // The below code won't actually run. We just reference some Python + // symbols so the compiler and linker do some work to verify they are + // able to resolve the symbols. + // To make it actually run, more custom initialization is necessary. + // See https://docs.python.org/3/c-api/intro.html#embedding-python + Py_Initialize(); + PyRun_SimpleString("print('Hello, world')\n"); + Py_Finalize(); + return 0; +}