Skip to content

Commit 6b43230

Browse files
committed
test case with shared library libs
1 parent 3bc8130 commit 6b43230

File tree

11 files changed

+187
-9
lines changed

11 files changed

+187
-9
lines changed

docs/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ dependencies = [
1313
"absl-py",
1414
"typing-extensions",
1515
"sphinx-reredirects",
16-
"pefile"
16+
"pefile",
17+
"pyelftools",
1718
]

docs/requirements.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ colorama==0.4.6 ; sys_platform == 'win32' \
111111
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
112112
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
113113
# via sphinx
114-
docutils==0.22.2 \
115-
--hash=sha256:9fdb771707c8784c8f2728b67cb2c691305933d68137ef95a75db5f4dfbc213d \
116-
--hash=sha256:b0e98d679283fc3bb0ead8a5da7f501baa632654e7056e9c5846842213d674d8
114+
docutils==0.21.2 \
115+
--hash=sha256:3a6b18732edf182daa3cd12775bbb338cf5691468f91eeeb109deff6ebfa986f \
116+
--hash=sha256:dafca5b9e384f0e419294eb4d2ff9fa826435bf15f15b7bd45723e8ad76811b2
117117
# via
118118
# myst-parser
119119
# sphinx
@@ -137,9 +137,9 @@ jinja2==3.1.6 \
137137
# myst-parser
138138
# readthedocs-sphinx-ext
139139
# sphinx
140-
markdown-it-py==4.0.0 \
141-
--hash=sha256:87327c59b172c5011896038353a81343b6754500a08cd7a4973bb48c6d578147 \
142-
--hash=sha256:cb0a2b4aa34f932c007117b194e945bd74e0ec24133ceb5bac59009cda1cb9f3
140+
markdown-it-py==3.0.0 \
141+
--hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \
142+
--hash=sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb
143143
# via
144144
# mdit-py-plugins
145145
# myst-parser
@@ -264,6 +264,10 @@ pefile==2024.8.26 \
264264
--hash=sha256:3ff6c5d8b43e8c37bb6e6dd5085658d658a7a0bdcd20b6a07b1fcfc1c4e9d632 \
265265
--hash=sha256:76f8b485dcd3b1bb8166f1128d395fa3d87af26360c2358fb75b80019b957c6f
266266
# via rules-python-docs (docs/pyproject.toml)
267+
pyelftools==0.32 \
268+
--hash=sha256:013df952a006db5e138b1edf6d8a68ecc50630adbd0d83a2d41e7f846163d738 \
269+
--hash=sha256:6de90ee7b8263e740c8715a925382d4099b354f29ac48ea40d840cf7aa14ace5
270+
# via rules-python-docs (docs/pyproject.toml)
267271
pygments==2.19.2 \
268272
--hash=sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887 \
269273
--hash=sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b

python/private/venv_runfiles.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def _merge_venv_path_group(ctx, group, keep_map):
174174
# flattening the files depset, but can lower the number of materialized
175175
# files significantly. Usually overlaps are limited to a small number
176176
# of directories. Note that, when doing so, shared libraries need to
177-
# be symlinked directory, not the directory containing them, due to
178-
# symlink resolution semantics on Linux.
177+
# be symlinked directly, not the directory containing them, due to
178+
# dynamic linker symlink resolution semantics on Linux.
179179
for entry in group:
180180
prefix = entry.venv_path
181181
for file in entry.files.to_list():

tests/support/copy_file.bzl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Copies a file to a directory."""
2+
3+
def _copy_file_to_dir_impl(ctx):
4+
out_file = ctx.actions.declare_file(
5+
"{}/{}".format(ctx.attr.out_dir, ctx.file.src.basename),
6+
)
7+
ctx.actions.run_shell(
8+
inputs = [ctx.file.src],
9+
outputs = [out_file],
10+
arguments = [ctx.file.src.path, out_file.path],
11+
command = 'cp -f "$1" "$2"',
12+
progress_message = "Copying %{input} to %{output}",
13+
)
14+
return [DefaultInfo(files = depset([out_file]))]
15+
16+
copy_file_to_dir = rule(
17+
implementation = _copy_file_to_dir_impl,
18+
attrs = {
19+
"src": attr.label(
20+
allow_single_file = True,
21+
mandatory = True,
22+
),
23+
"out_dir": attr.string(mandatory = True),
24+
},
25+
)

tests/venv_site_packages_libs/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,16 @@ py_reconfig_test(
3434
"@other//with_external_data",
3535
],
3636
)
37+
38+
py_reconfig_test(
39+
name = "shared_lib_loading_test",
40+
srcs = ["shared_lib_loading_test.py"],
41+
bootstrap_impl = "script",
42+
main = "shared_lib_loading_test.py",
43+
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT,
44+
venvs_site_packages = "yes",
45+
deps = [
46+
"//tests/venv_site_packages_libs/ext_with_libs",
47+
"@dev_pip//pyelftools",
48+
],
49+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
2+
load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library")
3+
load("//python:py_library.bzl", "py_library")
4+
load("//tests/support:copy_file.bzl", "copy_file_to_dir")
5+
6+
package(
7+
default_visibility = ["//visibility:public"],
8+
licenses = ["notice"],
9+
)
10+
11+
cc_library(
12+
name = "increment_impl",
13+
srcs = ["increment.c"],
14+
deps = [":increment_headers"],
15+
)
16+
17+
cc_library(
18+
name = "increment_headers",
19+
hdrs = ["increment.h"],
20+
)
21+
22+
cc_shared_library(
23+
name = "increment",
24+
deps = [":increment_impl"],
25+
)
26+
27+
cc_library(
28+
name = "adder_impl",
29+
srcs = ["adder.c"],
30+
deps = [
31+
":increment_headers",
32+
"@rules_python//python/cc:current_py_cc_headers",
33+
],
34+
)
35+
36+
# todo: copy more from py_extension in local_toolchains
37+
cc_shared_library(
38+
name = "adder",
39+
dynamic_deps = [":increment"],
40+
shared_lib_name = select({
41+
"//conditions:default": "adder.so",
42+
}),
43+
user_link_flags = [
44+
# NOTE: cc_shared_library adds Bazelized rpath entries, too.
45+
"-Wl,-rpath,$ORIGIN/libs",
46+
],
47+
deps = [":adder_impl"],
48+
)
49+
50+
copy_file_to_dir(
51+
name = "relocate_adder",
52+
src = ":adder",
53+
out_dir = "site-packages/ext_with_libs",
54+
)
55+
56+
copy_file_to_dir(
57+
name = "relocate_increment",
58+
src = ":increment",
59+
out_dir = "site-packages/ext_with_libs/libs",
60+
)
61+
62+
py_library(
63+
name = "ext_with_libs",
64+
srcs = glob(["site-packages/**/*.py"]),
65+
data = [
66+
":relocate_adder",
67+
":relocate_increment",
68+
],
69+
experimental_venvs_site_packages = "//python/config_settings:venvs_site_packages",
70+
imports = [package_name() + "/site-packages"],
71+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <Python.h>
2+
3+
#include "increment.h"
4+
5+
static PyObject *do_add(PyObject *self, PyObject *Py_UNUSED(args)) {
6+
return PyLong_FromLong(increment(1));
7+
}
8+
9+
static PyMethodDef AdderMethods[] = {
10+
{"do_add", do_add, METH_NOARGS, "Add one"}, {NULL, NULL, 0, NULL}};
11+
12+
static struct PyModuleDef addermodule = {PyModuleDef_HEAD_INIT, "adder", NULL,
13+
-1, AdderMethods};
14+
15+
PyMODINIT_FUNC PyInit_adder(void) { return PyModule_Create(&addermodule); }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "increment.h"
2+
3+
int increment(int val) { return val + 1; }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef TESTS_VENV_SITE_PACKAGES_LIBS_EXT_WITH_LIBS_INCREMENT_H_
2+
#define TESTS_VENV_SITE_PACKAGES_LIBS_EXT_WITH_LIBS_INCREMENT_H_
3+
4+
int increment(int);
5+
6+
#endif // TESTS_VVENV_SITE_PACKAGES_LIBS_EXT_WITH_LIBS_INCREMENT_H_

tests/venv_site_packages_libs/ext_with_libs/site-packages/ext_with_libs/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)