diff --git a/.bazelrc b/.bazelrc index 31ed2a18..a9ba220c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,9 @@ +common --enable_platform_specific_config + build --incompatible_strict_action_env +build:linux --cxxopt=-std=c++20 +build:macos --cxxopt=-std=c++20 +build:windows --cxxopt=-std:c++20 + run --incompatible_strict_action_env test --incompatible_strict_action_env diff --git a/WORKSPACE b/WORKSPACE index f9ea5642..fda8bef6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -52,10 +52,10 @@ google_or_tools_mac() google_or_tools_linux() google_or_tools_windows() -load("//library/ortools/cc:deps.bzl", "google_or_tools_mac", "google_or_tools_linux", "google_or_tools_windows") -google_or_tools_mac() -google_or_tools_linux() -google_or_tools_windows() +load("//library/ortools/cc:deps.bzl", "google_or_tools") +google_or_tools() +load("@com_google_protobuf//:protobuf_deps.bzl", google_or_tools_protobuf_deps = "protobuf_deps") +google_or_tools_protobuf_deps() # Load //tool/common load("//tool/common:deps.bzl", "vaticle_dependencies_ci_pip", vaticle_dependencies_tool_maven_artifacts = "maven_artifacts") diff --git a/library/ortools/cc/deps.bzl b/library/ortools/cc/deps.bzl index 7c61672e..af891aad 100644 --- a/library/ortools/cc/deps.bzl +++ b/library/ortools/cc/deps.bzl @@ -16,51 +16,87 @@ # load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") -def build_file_content(lib): - return """ -cc_import( - name = "lib", - shared_library = "lib/{0}", - visibility = ["//visibility:public"] -) -cc_library( - name = "incl", - hdrs = glob([ - "include/ortools/**/*.h", - "include/absl/**/*.h", - "include/absl/**/*.inc", - "include/google/protobuf/**/*.inc", - "include/google/protobuf/**/*.h", - ]), - strip_include_prefix = "include/", - visibility = ["//visibility:public"] -) -""".format(lib) +def google_or_tools(): + # Abseil-cpp + git_repository( + name = "com_google_absl", + tag = "20211102.0", + remote = "https://github.com/abseil/abseil-cpp.git", + ) -def google_or_tools_linux(): - http_archive( - name = "or_tools_linux", - urls = ["https://github.com/google/or-tools/releases/download/v9.0/or-tools_debian-10_v9.0.9048.tar.gz"], - strip_prefix = "or-tools_Debian-10-64bit_v9.0.9048/", - sha256 = "063fb1d8765ae23b0bb25b9c561e904532713416fe0458f7db45a0f72190eb50", - build_file_content = build_file_content("libortools.so") + # Protobuf + git_repository( + name = "com_google_protobuf", + tag = "v3.19.4", + remote = "https://github.com/protocolbuffers/protobuf.git", + ) + + # ZLIB + new_git_repository( + name = "zlib", + build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + tag = "v1.2.11", + remote = "https://github.com/madler/zlib.git", + ) + + git_repository( + name = "com_google_re2", + patches = ["@com_google_ortools//bazel:re2.patch"], + tag = "2022-02-01", + remote = "https://github.com/google/re2.git", + ) + + git_repository( + name = "com_google_googletest", + tag = "release-1.11.0", + remote = "https://github.com/google/googletest.git", ) -def google_or_tools_mac(): http_archive( - name = "or_tools_mac", - urls = ["https://github.com/google/or-tools/releases/download/v9.0/or-tools_MacOsX-11.2.3_v9.0.9048.tar.gz"], - strip_prefix = "or-tools_MacOsX-11.2.3_v9.0.9048/", - sha256 = "adf73a00d4ec49558b67be5ce3cfc8f30268da2253b35feb11d0d40700550bf6", - build_file_content = build_file_content("libortools.dylib") + name = "glpk", + build_file = "//bazel:glpk.BUILD", + sha256 = "4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15", + url = "http://ftp.gnu.org/gnu/glpk/glpk-5.0.tar.gz", ) -def google_or_tools_windows(): http_archive( - name = "or_tools_windows", - urls = ["https://github.com/google/or-tools/releases/download/v9.0/or-tools_VisualStudio2019-64bit_v9.0.9048.zip"], - strip_prefix = "or-tools_VisualStudio2019-64bit_v9.0.9048/", - sha256 = "1be7286e082ba346f8729a873c5fd85418ac2dc95b847d9baa5381c5ac5f5fd9", - build_file_content = build_file_content("ortools.lib") + name = "bliss", + build_file = "@com_google_ortools//bazel:bliss.BUILD", + patches = ["@com_google_ortools//bazel:bliss-0.73.patch"], + sha256 = "f57bf32804140cad58b1240b804e0dbd68f7e6bf67eba8e0c0fa3a62fd7f0f84", + url = "http://www.tcs.hut.fi/Software/bliss/bliss-0.73.zip", + ) + + new_git_repository( + name = "scip", + build_file = "@com_google_ortools//bazel:scip.BUILD", + patches = ["@com_google_ortools//bazel:scip.patch"], + patch_args = ["-p1"], + tag = "v800", + remote = "https://github.com/scipopt/scip.git", + ) + + # Eigen has no Bazel build. + new_git_repository( + name = "eigen", + tag = "3.4.0", + remote = "https://gitlab.com/libeigen/eigen.git", + build_file_content = +""" +cc_library( +name = 'eigen3', +srcs = [], +includes = ['.'], +hdrs = glob(['Eigen/**']), +visibility = ['//visibility:public'], +) +""" + ) + + git_repository( + name = "com_google_ortools", + remote = "https://github.com/google/or-tools.git", + tag = "v9.3", ) diff --git a/library/ortools/rust/BUILD b/library/ortools/rust/BUILD index ec0433e7..af50ee87 100644 --- a/library/ortools/rust/BUILD +++ b/library/ortools/rust/BUILD @@ -33,37 +33,21 @@ rust_library( rust_cxx_bridge( name = "ortools_bridge", src = "ortools.rs", - deps = select({ - "@vaticle_dependencies//util/platform:is_mac": [ - "@or_tools_mac//:lib", - "@or_tools_mac//:incl", - ], - "@vaticle_dependencies//util/platform:is_linux": [ - "@or_tools_linux//:lib", - "@or_tools_linux//:incl", - ], - "@vaticle_dependencies//util/platform:is_windows": [ - "@or_tools_windows//:lib", - "@or_tools_windows//:incl", - ], - }) + [":ortools_bridge_wrapper"], + deps = [ + ":ortools-wrapper", + "@com_google_ortools//ortools/base", + "@com_google_ortools//ortools/linear_solver", + "@com_google_ortools//ortools/linear_solver:linear_solver_cc_proto", + ] ) cc_library( - name = "ortools_bridge_wrapper", - hdrs = ["OrToolsWrapper.h"], - deps = select({ - "@vaticle_dependencies//util/platform:is_mac": [ - "@or_tools_mac//:lib", - "@or_tools_mac//:incl", - ], - "@vaticle_dependencies//util/platform:is_linux": [ - "@or_tools_linux//:lib", - "@or_tools_linux//:incl", - ], - "@vaticle_dependencies//util/platform:is_windows": [ - "@or_tools_windows//:lib", - "@or_tools_windows//:incl", - ], - }) + name = "ortools-wrapper", + srcs = [":OrToolsWrapper.h"], + deps = [ + "@com_google_ortools//ortools/base", + "@com_google_ortools//ortools/linear_solver", + "@com_google_ortools//ortools/linear_solver:linear_solver_cc_proto", + ], ) + diff --git a/library/ortools/rust/OrToolsWrapper.h b/library/ortools/rust/OrToolsWrapper.h index 6c873b63..e1f0b737 100644 --- a/library/ortools/rust/OrToolsWrapper.h +++ b/library/ortools/rust/OrToolsWrapper.h @@ -20,7 +20,11 @@ using namespace std; namespace operations_research { using MPSolverResultStatus = MPSolver::ResultStatus; - std::unique_ptr new_mpsolver() { + std::unique_ptr new_mpsolver_sat() { + return std::unique_ptr(MPSolver::CreateSolver("SAT")); + } + + std::unique_ptr new_mpsolver_scip() { return std::unique_ptr(MPSolver::CreateSolver("SCIP")); } } diff --git a/library/ortools/rust/ortools.rs b/library/ortools/rust/ortools.rs index 606bf6e5..82b52fb5 100644 --- a/library/ortools/rust/ortools.rs +++ b/library/ortools/rust/ortools.rs @@ -49,7 +49,9 @@ pub mod ffi { type MPConstraint; type MPObjective; - fn new_mpsolver() -> UniquePtr; + fn new_mpsolver_sat() -> UniquePtr; + fn new_mpsolver_scip() -> UniquePtr; + fn MakeIntVar(self: Pin<&mut MPSolver>, lb: f64, ub: f64, name: &CxxString) -> *mut MPVariable; fn solution_value(self: &MPVariable) -> f64;