Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/upload_buck2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
cd examples/with_prelude
# TODO: rust examples don't work on windows + arm64
if [[ "${{ matrix.target.triple }}" == "aarch64-pc-windows-msvc" ]]; then
TARGETS="cpp/... python/..."
TARGETS="cpp/... python/hello_world/..."
else
TARGETS="rust/... cpp/... python/..."
fi
Expand Down
27 changes: 0 additions & 27 deletions examples/with_prelude/cpp/python_cextension/BUCK

This file was deleted.

19 changes: 13 additions & 6 deletions examples/with_prelude/python/use_cextension/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
# WILL BE DELETED. UNLESS THERE IS AN ONCALL ADDED THIS FILE WILL BE

# DELETED WITHOUT NOTICE - DO NOT DEPEND ON IT.
# FIXME(marwhal): Get python_cextension example working again
# python_binary(
# name = "cext",
# deps = ["//cpp/python_cextension:cpprint"],
# main = "cext/cext.py"
# )

cxx_python_extension(
name = "cpprint",
srcs = ["print.cpp"],
base_module = "",
visibility = ["PUBLIC"],
)

python_binary(
name = "cext",
deps = [":cpprint"],
main = "cext.py"
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,3 @@ static struct PyModuleDef extension = {
PyMODINIT_FUNC PyInit_cpprint(void) {
return PyModule_Create(&extension);
}

int main(int argc, char* argv[]) {
wchar_t* program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}

/* Add a built-in module, before Py_Initialize */
if (PyImport_AppendInittab("cppring", PyInit_cpprint) == -1) {
fprintf(stderr, "Error: could not extend in-built modules table\n");
exit(1);
}

/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(program);

/* Initialize the Python interpreter. Required.
If this step fails, it will be a fatal error. */
Py_Initialize();

return 0;
}
2 changes: 1 addition & 1 deletion prelude/python/cxx_python_extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def cxx_python_extension_impl(ctx: AnalysisContext) -> list[Provider]:
platform_compiler_flags = ctx.attrs.platform_compiler_flags,
extra_link_flags = python_toolchain.extension_linker_flags,
lang_platform_compiler_flags = ctx.attrs.lang_platform_compiler_flags,
preprocessor_flags = ctx.attrs.preprocessor_flags,
preprocessor_flags = python_toolchain.extension_preprocessor_flags + ctx.attrs.preprocessor_flags,
lang_preprocessor_flags = ctx.attrs.lang_preprocessor_flags,
platform_preprocessor_flags = ctx.attrs.platform_preprocessor_flags,
lang_platform_preprocessor_flags = ctx.attrs.lang_platform_preprocessor_flags,
Expand Down
1 change: 1 addition & 0 deletions prelude/python/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PythonToolchainInfo = provider(
"binary_linker_flags": provider_field(ArgLike, default = []),
"extension_linker_flags": provider_field(ArgLike, default = []),
"wheel_linker_flags": provider_field(ArgLike, default = []),
"extension_preprocessor_flags": provider_field(list[ArgLike], default = []),
# site-packages-relative rpaths to emebed into libs/bins in the wheel
"wheel_rpaths": provider_field(ArgLike, default = []),
"gen_lpar_bootstrap": provider_field(Dependency | None, default = None),
Expand Down
6 changes: 6 additions & 0 deletions prelude/toolchains/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def python_toolchain_impl(ctx) -> list[Provider]:
linker_flags = [],
binary_linker_flags = [],
extension_linker_flags = ctx.attrs.extension_linker_flags,
extension_preprocessor_flags = ctx.attrs.extension_preprocessor_flags,
),
PythonPlatformInfo(name = "x86_64"),
]
Expand All @@ -113,6 +114,7 @@ python_toolchain = rule(
attrs = {
"compile": attrs.default_only(attrs.dep(default = "prelude//python/tools:compile.py")),
"extension_linker_flags": attrs.list(attrs.arg()),
"extension_preprocessor_flags": attrs.list(attrs.arg()),
"interpreter": attrs.dep(providers = [RunInfo]),
},
is_toolchain_rule = True,
Expand Down Expand Up @@ -204,5 +206,9 @@ def remote_python_toolchain(
"DEFAULT": ["-L$(location :cpython_archive[lib])", "@$(location :libpython_symbols)"],
"prelude//os:windows": ["/LIBPATH:$(location :cpython_archive[lib])"],
}),
extension_preprocessor_flags = select({
"DEFAULT": ["-I$(location :cpython_archive[include])"],
"prelude//os:windows": ["/I$(location :cpython_archive[include])"],
}),
**kwargs
)
Loading