diff --git a/.gitignore b/.gitignore index fdebdf0ccc5..cb96e754433 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,6 @@ CMakeFiles DartConfiguration.tcl *build*/* build/ + +# Ignore Bzlmod lock file until it is more stable +MODULE.bazel.lock diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000000..b60d97d50c3 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,120 @@ +module( + name = "com_google_ortools", +) + +bazel_dep(name = "abseil-cpp", version = "20240722.0", repo_name = "com_google_absl") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "contrib_rules_jvm", version = "0.27.0") +bazel_dep(name = "eigen", version = "3.4.0.bcr.1") +bazel_dep(name = "gazelle", version = "0.39.1", repo_name = "bazel_gazelle") +bazel_dep(name = "glpk", version = "5.0.bcr.1") +bazel_dep(name = "google_benchmark", version = "1.8.5", repo_name = "com_google_benchmark") +bazel_dep(name = "googletest", version = "1.15.2", repo_name = "com_google_googletest") +bazel_dep(name = "highs", version = "1.8.0") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "protobuf", version = "27.1.bcr.1", repo_name = "com_google_protobuf") +bazel_dep(name = "pybind11_abseil", version = "202402.0", repo_name = "org_pybind11_abseil") +bazel_dep(name = "pybind11_bazel", version = "2.13.6") +bazel_dep(name = "pybind11_protobuf", version = "0.0.0-20240524-1d7a729") +bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_google_re2") +bazel_dep(name = "rules_cc", version = "0.0.10") +bazel_dep(name = "rules_go", version = "0.50.1", repo_name = "io_bazel_rules_go") +bazel_dep(name = "rules_java", version = "7.12.2") +bazel_dep(name = "rules_jvm_external", version = "6.4") +bazel_dep(name = "rules_license", version = "1.0.0") +bazel_dep(name = "rules_proto", version = "6.0.2") +bazel_dep(name = "rules_python", version = "0.37.2") +bazel_dep(name = "scip", version = "8.1.0") +bazel_dep(name = "swig", version = "4.2.0") +bazel_dep(name = "zlib", version = "1.3.1.bcr.3") + +PYTHON_VERSIONS = [ + "3.8", + "3.9", + "3.10", + "3.11", + "3.12", +] +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +[ + python.toolchain( + is_default = python_version == PYTHON_VERSIONS[-1], + python_version = python_version, + ) + for python_version in PYTHON_VERSIONS +] +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +[ + pip.parse( + hub_name = "ortools_pip_deps", + python_version = python_version, + requirements_lock = "//bazel:ortools_requirements.txt", + ) + for python_version in PYTHON_VERSIONS +] +[ + pip.parse( + hub_name = "ortools_notebook_deps", + python_version = python_version, + requirements_lock = "//bazel:notebook_requirements.txt", + ) + for python_version in PYTHON_VERSIONS +] +use_repo(pip, pip_deps = "ortools_pip_deps") +use_repo(pip, "ortools_notebook_deps") + +JUNIT_PLATFORM_VERSION = "1.9.2" +JUNIT_JUPITER_VERSION = "5.9.2" +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") +maven.install( + artifacts = [ + "net.java.dev.jna:jna:5.14.0", + "com.google.truth:truth:0.32", + "org.junit.platform:junit-platform-launcher:%s" % JUNIT_PLATFORM_VERSION, + "org.junit.platform:junit-platform-reporting:%s" % JUNIT_PLATFORM_VERSION, + "org.junit.jupiter:junit-jupiter-api:%s" % JUNIT_JUPITER_VERSION, + "org.junit.jupiter:junit-jupiter-params:%s" % JUNIT_JUPITER_VERSION, + "org.junit.jupiter:junit-jupiter-engine:%s" % JUNIT_JUPITER_VERSION, + ], + repositories = [ + "https://repo1.maven.org/maven2", + ], +) +use_repo(maven, "maven") + +go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") +go_sdk.download(version = "1.22.4") +go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") +go_deps.module( + path = "github.com/golang/glog", + sum = "h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=", + version = "v1.2.2", +) +go_deps.module( + path = "github.com/golang/protobuf", + sum = "h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=", + version = "v1.5.0", +) +go_deps.module( + path = "github.com/google/go-cmp", + sum = "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=", + version = "v0.6.0", +) +go_deps.module( + path = "google.golang.org/protobuf", + sum = "h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=", + version = "v1.34.2", +) +go_deps.module( + path = "golang.org/x/xerrors", + sum = "h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=", + version = "v0.0.0-20191204190536-9bdfabe68543", +) +use_repo( + go_deps, + "com_github_golang_glog", + "com_github_golang_protobuf", + "com_github_google_go_cmp", + "org_golang_google_protobuf", + "org_golang_x_xerrors", +) diff --git a/WORKSPACE b/WORKSPACE index 63dd2e28ce2..74d0a081d1c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -169,6 +169,7 @@ http_archive( build_file = "//bazel:glpk.BUILD.bazel", sha256 = "4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15", url = "http://ftp.gnu.org/gnu/glpk/glpk-5.0.tar.gz", + strip_prefix = "glpk-5.0", ) http_archive( @@ -197,7 +198,7 @@ new_git_repository( build_file_content = """ cc_library( - name = 'eigen3', + name = 'eigen', srcs = [], includes = ['.'], hdrs = glob(['Eigen/**', 'unsupported/**']), diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 00000000000..e69de29bb2d diff --git a/bazel/glpk.BUILD.bazel b/bazel/glpk.BUILD.bazel index 094a7b521d2..7f6d476898e 100644 --- a/bazel/glpk.BUILD.bazel +++ b/bazel/glpk.BUILD.bazel @@ -15,37 +15,37 @@ cc_library( name = "glpk", srcs = glob( [ - "glpk-5.0/src/*.c", - "glpk-5.0/src/*/*.c", - "glpk-5.0/src/*.h", - "glpk-5.0/src/*/*.h", + "src/*.c", + "src/*/*.c", + "src/*.h", + "src/*/*.h", ], exclude = [ - "glpk-5.0/src/proxy/main.c", - "glpk-5.0/src/zlib/*", + "src/proxy/main.c", + "src/zlib/*", ], ), hdrs = [ - "glpk-5.0/src/glpk.h", + "src/glpk.h", ], copts = [ "-w", - "-Iexternal/glpk/glpk-5.0/src", - "-Iexternal/glpk/glpk-5.0/src/amd", - "-Iexternal/glpk/glpk-5.0/src/api", - "-Iexternal/glpk/glpk-5.0/src/bflib", - "-Iexternal/glpk/glpk-5.0/src/colamd", - "-Iexternal/glpk/glpk-5.0/src/draft", - "-Iexternal/glpk/glpk-5.0/src/env", - "-Iexternal/glpk/glpk-5.0/src/intopt", - "-Iexternal/glpk/glpk-5.0/src/minisat", - "-Iexternal/glpk/glpk-5.0/src/misc", - "-Iexternal/glpk/glpk-5.0/src/mpl", - "-Iexternal/glpk/glpk-5.0/src/npp", - "-Iexternal/glpk/glpk-5.0/src/proxy", - "-Iexternal/glpk/glpk-5.0/src/simplex", + "-Iexternal/glpk/src", + "-Iexternal/glpk/src/amd", + "-Iexternal/glpk/src/api", + "-Iexternal/glpk/src/bflib", + "-Iexternal/glpk/src/colamd", + "-Iexternal/glpk/src/draft", + "-Iexternal/glpk/src/env", + "-Iexternal/glpk/src/intopt", + "-Iexternal/glpk/src/minisat", + "-Iexternal/glpk/src/misc", + "-Iexternal/glpk/src/mpl", + "-Iexternal/glpk/src/npp", + "-Iexternal/glpk/src/proxy", + "-Iexternal/glpk/src/simplex", ], deps = ["@zlib"], - includes = ["glpk-5.0/src"], + includes = ["src"], visibility = ["//visibility:public"], ) diff --git a/bazel/scip.BUILD.bazel b/bazel/scip.BUILD.bazel index 8271c09fb9e..6c7a68b1116 100644 --- a/bazel/scip.BUILD.bazel +++ b/bazel/scip.BUILD.bazel @@ -68,7 +68,7 @@ BLISS_FILE = select({ }) cc_library( - name = "libscip", + name = "scip", srcs = glob( [ "src/*/*.c", diff --git a/bazel/swig_java.bzl b/bazel/swig_java.bzl index ec26d1f0f91..ebe334707c5 100644 --- a/bazel/swig_java.bzl +++ b/bazel/swig_java.bzl @@ -13,6 +13,7 @@ """Build definitions for SWIG Java.""" +load("@bazel_skylib//lib:paths.bzl", "paths") load("@rules_java//java:java_library.bzl", "java_library") load("@rules_java//java/common:java_common.bzl", "java_common") @@ -69,10 +70,10 @@ def _java_wrap_cc_impl(ctx): generated_c_files.append(outhdr) # Add swig LIB files. - swig_lib = {"SWIG_LIB": "external/swig/Lib"} + swig_lib = {"SWIG_LIB": paths.dirname(ctx.files._swig_lib[0].path)} ctx.actions.run( outputs = generated_c_files + [java_files_dir], - inputs = depset([src] + ctx.files.swig_includes, transitive = header_sets), + inputs = depset([src] + ctx.files.swig_includes + ctx.files._swig_lib, transitive = header_sets), env = swig_lib, executable = ctx.executable._swig, arguments = [swig_args], @@ -127,6 +128,9 @@ It's expected that the `swig` binary exists in the host's path. executable = True, cfg = "exec", ), + "_swig_lib": attr.label( + default = Label("@swig//:lib_java"), + ), "swig_includes": attr.label_list( doc = "SWIG includes.", allow_files = True, @@ -186,7 +190,7 @@ def ortools_java_wrap_cc( deps = deps, swig_opt = swig_opt, module = module, - swig_includes = swig_includes + ["@swig//:lib_java"], + swig_includes = swig_includes, use_directors = use_directors, visibility = ["//visibility:private"], **kwargs @@ -196,7 +200,7 @@ def ortools_java_wrap_cc( name = cc_name, srcs = [outfile], hdrs = [outhdr] if use_directors else [], - deps = deps + ["@bazel_tools//tools/jdk:jni"], + deps = deps + [Label("@bazel_tools//tools/jdk:jni")], alwayslink = True, visibility = visibility, **kwargs diff --git a/ortools/gscip/BUILD.bazel b/ortools/gscip/BUILD.bazel index d9494838b3e..6a65fca6278 100644 --- a/ortools/gscip/BUILD.bazel +++ b/ortools/gscip/BUILD.bazel @@ -131,7 +131,7 @@ cc_library( name = "gscip_callback_result", srcs = ["gscip_callback_result.cc"], hdrs = ["gscip_callback_result.h"], - deps = ["@scip//:libscip"], + deps = ["@scip"], ) cc_library( @@ -147,6 +147,6 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/types:span", - "@scip//:libscip", + "@scip", ], ) diff --git a/ortools/linear_solver/BUILD.bazel b/ortools/linear_solver/BUILD.bazel index 618e1921a6c..2e13e952b6e 100644 --- a/ortools/linear_solver/BUILD.bazel +++ b/ortools/linear_solver/BUILD.bazel @@ -354,7 +354,7 @@ cc_library( srcs = ["lpi_glop.cpp"], deps = [ "//ortools/glop:lp_solver", - "@scip//:libscip", + "@scip", ], ) diff --git a/ortools/linear_solver/proto_solver/BUILD.bazel b/ortools/linear_solver/proto_solver/BUILD.bazel index 57a1d822278..10f42707cc0 100644 --- a/ortools/linear_solver/proto_solver/BUILD.bazel +++ b/ortools/linear_solver/proto_solver/BUILD.bazel @@ -135,7 +135,7 @@ cc_library( "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/time", ] + select({ - "//ortools/linear_solver:use_scip": ["@scip//:libscip"], + "//ortools/linear_solver:use_scip": ["@scip"], "//conditions:default": [], }), ) diff --git a/ortools/linear_solver/python/BUILD.bazel b/ortools/linear_solver/python/BUILD.bazel index 4cac58db4fe..da1eec9228c 100644 --- a/ortools/linear_solver/python/BUILD.bazel +++ b/ortools/linear_solver/python/BUILD.bazel @@ -25,7 +25,7 @@ pybind_extension( "//ortools/linear_solver:model_exporter", "//ortools/linear_solver/wrappers:model_builder_helper", "@com_google_absl//absl/strings", - "@eigen//:eigen3", + "@eigen", "@pybind11_protobuf//pybind11_protobuf:native_proto_caster", ], ) diff --git a/ortools/math_opt/io/BUILD.bazel b/ortools/math_opt/io/BUILD.bazel index 428beafedd0..b0d2c42e337 100644 --- a/ortools/math_opt/io/BUILD.bazel +++ b/ortools/math_opt/io/BUILD.bazel @@ -96,6 +96,6 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", - "@scip//:libscip", + "@scip", ], ) diff --git a/ortools/math_opt/solvers/BUILD.bazel b/ortools/math_opt/solvers/BUILD.bazel index 023e966a490..44a6c3c0980 100644 --- a/ortools/math_opt/solvers/BUILD.bazel +++ b/ortools/math_opt/solvers/BUILD.bazel @@ -64,7 +64,7 @@ cc_library( "@com_google_absl//absl/time", "@com_google_absl//absl/types:span", "@com_google_protobuf//:protobuf", - "@scip//:libscip", + "@scip", ], alwayslink = 1, ) @@ -381,7 +381,7 @@ cc_library( "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", - "@eigen//:eigen3", + "@eigen", ], ) diff --git a/ortools/math_opt/solvers/gscip/BUILD.bazel b/ortools/math_opt/solvers/gscip/BUILD.bazel index fd91d856745..d13385cae35 100644 --- a/ortools/math_opt/solvers/gscip/BUILD.bazel +++ b/ortools/math_opt/solvers/gscip/BUILD.bazel @@ -32,6 +32,6 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/time", - "@scip//:libscip", + "@scip", ], ) diff --git a/ortools/pdlp/BUILD.bazel b/ortools/pdlp/BUILD.bazel index d1e2b010988..09a91129428 100644 --- a/ortools/pdlp/BUILD.bazel +++ b/ortools/pdlp/BUILD.bazel @@ -25,7 +25,7 @@ cc_library( ":solvers_cc_proto", "//ortools/base:threadpool", "@com_google_absl//absl/functional:any_invocable", - "@eigen//:eigen3", + "@eigen//:eigen", ], ) @@ -96,7 +96,7 @@ cc_library( "//ortools/base", "//ortools/base:mathutil", "@com_google_absl//absl/random:distributions", - "@eigen//:eigen3", + "@eigen", ], ) @@ -112,7 +112,7 @@ cc_test( ":solvers_cc_proto", ":test_util", "//ortools/base:protobuf_util", - "@eigen//:eigen3", + "@eigen", ], ) @@ -148,7 +148,7 @@ cc_library( "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/time", "@com_google_protobuf//:protobuf", - "@eigen//:eigen3", + "@eigen", ], ) @@ -176,7 +176,7 @@ cc_test( "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", - "@eigen//:eigen3", + "@eigen", ], ) @@ -191,7 +191,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", - "@eigen//:eigen3", + "@eigen", ], ) @@ -208,7 +208,7 @@ cc_test( "//ortools/linear_solver:linear_solver_cc_proto", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", - "@eigen//:eigen3", + "@eigen", ], ) @@ -231,7 +231,7 @@ cc_library( "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", - "@eigen//:eigen3", + "@eigen", ], ) @@ -247,7 +247,7 @@ cc_library( "//ortools/base", "//ortools/base:mathutil", "@com_google_absl//absl/random:distributions", - "@eigen//:eigen3", + "@eigen", ], ) @@ -263,7 +263,7 @@ cc_test( ":sharder", ":solve_log_cc_proto", ":test_util", - "@eigen//:eigen3", + "@eigen", ], ) @@ -280,7 +280,7 @@ cc_library( "//ortools/util:logging", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", - "@eigen//:eigen3", + "@eigen", ], ) @@ -293,7 +293,7 @@ cc_test( ":sharded_quadratic_program", ":sharder", ":test_util", - "@eigen//:eigen3", + "@eigen", ], ) @@ -308,7 +308,7 @@ cc_library( "//ortools/base:timer", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", - "@eigen//:eigen3", + "@eigen", ], ) @@ -323,7 +323,7 @@ cc_test( "//ortools/base", "//ortools/base:mathutil", "@com_google_absl//absl/random:distributions", - "@eigen//:eigen3", + "@eigen", ], ) @@ -386,7 +386,7 @@ cc_library( "//ortools/base", "//ortools/base:gmock", "@com_google_absl//absl/types:span", - "@eigen//:eigen3", + "@eigen", ], ) @@ -398,7 +398,7 @@ cc_test( ":test_util", "//ortools/base", "@com_google_absl//absl/types:span", - "@eigen//:eigen3", + "@eigen", ], ) @@ -414,7 +414,7 @@ cc_library( "//ortools/base", "//ortools/base:mathutil", "@com_google_absl//absl/algorithm:container", - "@eigen//:eigen3", + "@eigen", ], ) @@ -430,6 +430,6 @@ cc_test( ":test_util", ":trust_region", "@com_google_absl//absl/strings", - "@eigen//:eigen3", + "@eigen", ], ) diff --git a/ortools/pdlp/python/BUILD.bazel b/ortools/pdlp/python/BUILD.bazel index 270920aa980..50029c3c559 100644 --- a/ortools/pdlp/python/BUILD.bazel +++ b/ortools/pdlp/python/BUILD.bazel @@ -30,7 +30,7 @@ pybind_extension( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", - "@eigen//:eigen3", + "@eigen", "@pybind11_protobuf//pybind11_protobuf:native_proto_caster", ], ) diff --git a/ortools/pdlp/samples/code_samples.bzl b/ortools/pdlp/samples/code_samples.bzl index 9dc8cab8e82..baee0229171 100644 --- a/ortools/pdlp/samples/code_samples.bzl +++ b/ortools/pdlp/samples/code_samples.bzl @@ -26,7 +26,7 @@ def code_sample_cc(name): "//ortools/pdlp:quadratic_program", "//ortools/pdlp:solve_log_cc_proto", "//ortools/pdlp:solvers_cc_proto", - "@eigen//:eigen3", + "@eigen", ], ) @@ -42,6 +42,6 @@ def code_sample_cc(name): "//ortools/pdlp:quadratic_program", "//ortools/pdlp:solve_log_cc_proto", "//ortools/pdlp:solvers_cc_proto", - "@eigen//:eigen3", + "@eigen", ], )