Skip to content
Merged
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
16 changes: 7 additions & 9 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,30 @@ bazel_dep(name = "zlib", version = "1.3.1.bcr.8")

# OR-Tools wrappers dependencies
bazel_dep(name = "gazelle", version = "0.43.0")
bazel_dep(name = "pybind11_abseil", version = "202402.0")
bazel_dep(name = "pybind11_bazel", version = "2.13.6")
bazel_dep(name = "pybind11_protobuf", version = "0.0.0-20240524-1d7a729")
bazel_dep(name = "swig", version = "4.3.0")

git_override(
module_name = "pybind11_bazel",
commit = "2b6082a4d9d163a52299718113fa41e4b7978db5",
patch_strip = 1,
patches = ["//:patches/pybind11_bazel.patch"],
commit = "d5f6a112138c672daec4ca279f33baae95ca10ec", # Incomming 3.0.1 2026/03
#commit = "2b6082a4d9d163a52299718113fa41e4b7978db5", # 2024/09
#patch_strip = 1,
#patches = ["//:patches/pybind11_bazel.patch"], # patch for 2024/09
remote = "https://github.com/pybind/pybind11_bazel.git",
)

bazel_dep(name = "pybind11_abseil", version = "202402.0")
git_override(
module_name = "pybind11_abseil",
commit = "70f8b693b3b70573ca785ef62d9f48054f45d786",
patch_strip = 1,
patches = ["//:patches/pybind11_abseil.patch"],
remote = "https://github.com/pybind/pybind11_abseil.git",
)

bazel_dep(name = "pybind11_protobuf", version = "0.0.0-20240524-1d7a729")
git_override(
module_name = "pybind11_protobuf",
commit = "f02a2b7653bc50eb5119d125842a3870db95d251",
remote = "https://github.com/pybind/pybind11_protobuf.git",
)
bazel_dep(name = "swig", version = "4.3.0")

# Python
# https://rules-python.readthedocs.io/en/latest/toolchains.html#library-modules-with-dev-only-python-usage
Expand Down
13 changes: 3 additions & 10 deletions cmake/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,10 @@ if(BUILD_PYTHON)
FetchContent_Declare(
pybind11
GIT_REPOSITORY "https://github.com/pybind/pybind11.git"
#GIT_TAG "master" # COMPILE FAIL
#GIT_TAG "f365314" # 2025/03/24 COMPILE FAIL
#GIT_TAG "48eb5ad" # 2025/03/23 TEST PASS
# ...
#GIT_TAG "a1d00916" # 2024/08/15 TEST PASS
#GIT_TAG "bd5951b6" # 2024/08/14 TEST FAIL
GIT_TAG "v2.13.6" # TEST PASS with a1d00916 patch apply
#GIT_SHALLOW TRUE
#GIT_TAG "v3.0.2" # 2026/02/17
GIT_TAG "v3.0.1" # 2025/08/22
GIT_SHALLOW TRUE
UPDATE_COMMAND git reset --hard
PATCH_COMMAND git apply --ignore-whitespace
"${CMAKE_CURRENT_LIST_DIR}/../../patches/pybind11-v2.13.6.patch"
SYSTEM
)
set(PYBIND11_FINDPYTHON ON)
Expand Down
2 changes: 1 addition & 1 deletion cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ add_custom_command(
COMMAND ${stubgen_EXECUTABLE} -p ortools.math_opt.core.python.solver --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.pdlp.python.pdlp --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.routing.pywraprouting --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.routing.python.model --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.routing.python.routing --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.sat.python.cp_model_helper --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.scheduling.python.rcpsp --output .
COMMAND ${stubgen_EXECUTABLE} -p ortools.set_cover.python.set_cover --output .
Expand Down
25 changes: 12 additions & 13 deletions ortools/math_opt/elemental/python/elemental.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,9 @@ bool PyToCppEnum(PyObject* const py_enum, EnumT& cpp_enum,
// the latter).
template <const absl::string_view& name>
struct AsArray {
constexpr AsArray() {
#if __cplusplus >= 202002L
std::copy(name.begin(), name.end(), array);
#else
// `std::copy` is not constexpr before C++20.
char* p = array;
for (const char c : name) {
*p++ = c;
}
*p = '\0';
#endif
}
char array[name.size() + 1];

char array[name.size() + 1] = {};
constexpr AsArray() { std::copy(name.begin(), name.end(), array); }
};

// An RAII object that allows creating a UTF8 string from a numpy unicode
Expand Down Expand Up @@ -300,6 +289,16 @@ struct type_caster<ElementId<element_type>> {
}
};

#if defined(PYBIND11_HAS_NATIVE_ENUM)
// We must first disable the default pybind11 handler for enums to make our
// specialization non-ambiguous:
// https://pybind11.readthedocs.io/en/stable/classes.html#enumerations-and-internal-types
template <typename AttrType>
struct type_caster_enum_type_enabled<
AttrType, enable_if_t<(GetIndexIfAttr<AttrType>() >= 0)>>
: std::false_type {};
#endif

// Type caster for casting enum values from python enums to C++ `Elemental`
// enums.
template <typename AttrType>
Expand Down
12 changes: 5 additions & 7 deletions ortools/sat/python/cp_model_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,7 @@ PYBIND11_MODULE(cp_model_helper, m) {
.def(py::init<std::shared_ptr<CpModelProto>, int>())
.def(py::init<std::shared_ptr<CpModelProto>>()) // new variable.
.def_property_readonly(
"proto", &IntVar::proto, py::return_value_policy::reference,
py::keep_alive<1, 0>(),
"proto", &IntVar::proto, py::return_value_policy::reference_internal,
"Returns the IntegerVariableProto of this variable.")
.def_property_readonly("model_proto", &IntVar::model_proto,
"Returns the CP model protobuf")
Expand Down Expand Up @@ -2120,8 +2119,7 @@ PYBIND11_MODULE(cp_model_helper, m) {
.def_property_readonly("model_proto", &Constraint::model_proto,
"Returns the model protobuf.")
.def_property_readonly("proto", &Constraint::proto,
py::return_value_policy::reference,
py::keep_alive<1, 0>(),
py::return_value_policy::reference_internal,
"Returns the ConstraintProto of this constraint.")
.def_property("name", &Constraint::name, &Constraint::SetName,
"The name of the constraint.")
Expand Down Expand Up @@ -2236,9 +2234,9 @@ intervals into the schedule.
"Returns the index of the interval variable.")
.def_property_readonly("model_proto", &IntervalVar::model_proto,
"Returns the model protobuf.")
.def_property_readonly(
"proto", &IntervalVar::proto, py::return_value_policy::reference,
py::keep_alive<1, 0>(), "Returns the interval constraint protobuf.")
.def_property_readonly("proto", &IntervalVar::proto,
py::return_value_policy::reference_internal,
"Returns the interval constraint protobuf.")
.def_property("name", &IntervalVar::name, &IntervalVar::SetName,
"The name of the interval variable.")
.def(
Expand Down
4 changes: 2 additions & 2 deletions ortools/util/python/wrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class Generator {
.def_property_readonly(
"$0",
[]($1 self) { return self->mutable_$2(); },
py::return_value_policy::reference, py::keep_alive<0, 1>()))",
py::return_value_policy::reference_internal))",
field.name(), current_context_.self_mutable_name, field.name());
// We'll need to generate the wrapping for
// `google::protobuf::RepeatedPtrField<$3>`.
Expand All @@ -383,7 +383,7 @@ class Generator {
.def_property_readonly(
"$0",
[]($1 self) { return self->mutable_$0(); },
py::return_value_policy::reference, py::keep_alive<0, 1>()))",
py::return_value_policy::reference_internal))",
field.name(),
current_context_.self_mutable_name);
// We'll need to generate the wrapping for
Expand Down
Loading
Loading