Skip to content

Commit aa8b96f

Browse files
committed
try basic test to check linkage
1 parent 54a616d commit aa8b96f

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tests/cc/current_py_cc_headers/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
16+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
1517
load(":current_py_cc_headers_tests.bzl", "current_py_cc_headers_test_suite")
1618

1719
current_py_cc_headers_test_suite(name = "current_py_cc_headers_tests")
20+
21+
cc_binary(
22+
name = "bin_abi3",
23+
srcs = ["bin_abi3.cc"],
24+
linkshared = True,
25+
deps = [
26+
"//python/cc:current_py_cc_headers_abi3",
27+
],
28+
)
29+
30+
sh_test(
31+
name = "abi3_headers_linkage_test",
32+
srcs = ["abi3_headers_linkage_test.sh"],
33+
data = [":bin_abi3"],
34+
deps = ["@bazel_tools//tools/bash/runfiles"],
35+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
echo "hi =========="
3+
echo "hi =========="
4+
5+
# --- begin runfiles.bash initialization v3 ---
6+
# Copy-pasted from the Bazel Bash runfiles library v3.
7+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
8+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
9+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
10+
source "$0.runfiles/$f" 2>/dev/null || \
11+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
12+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
13+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
14+
# --- end runfiles.bash initialization v3 ---
15+
set +e
16+
17+
echo $RUNFILES_DIR
18+
lib=$(rlocation _main/tests/cc/current_py_cc_headers/libbin_abi3.so)
19+
20+
dumpbin /nologo /DEPENDENTS "$lib"
21+
22+
exit 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <Python.h>
2+
3+
int SomeFunction() {
4+
// Early return to prevent the broken code below from running.
5+
if (true) {
6+
return 0;
7+
}
8+
9+
// The below code won't actually run. We just reference some Python
10+
// symbols so the compiler and linker do some work to verify they are
11+
// able to resolve the symbols.
12+
// To make it actually run, more custom initialization is necessary.
13+
// See https://docs.python.org/3/c-api/intro.html#embedding-python
14+
Py_Initialize();
15+
Py_Finalize();
16+
return 0;
17+
}

0 commit comments

Comments
 (0)