Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Bzlmod #4428

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ CMakeFiles
DartConfiguration.tcl
*build*/*
build/

# Ignore Bzlmod lock file until it is more stable
MODULE.bazel.lock
120 changes: 120 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
3 changes: 2 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -197,7 +198,7 @@ new_git_repository(
build_file_content =
"""
cc_library(
name = 'eigen3',
name = 'eigen',
srcs = [],
includes = ['.'],
hdrs = glob(['Eigen/**', 'unsupported/**']),
Expand Down
Empty file added WORKSPACE.bzlmod
Empty file.
44 changes: 22 additions & 22 deletions bazel/glpk.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
2 changes: 1 addition & 1 deletion bazel/scip.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ BLISS_FILE = select({
})

cc_library(
name = "libscip",
name = "scip",
srcs = glob(
[
"src/*/*.c",
Expand Down
12 changes: 8 additions & 4 deletions bazel/swig_java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ortools/gscip/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
],
)
2 changes: 1 addition & 1 deletion ortools/linear_solver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ cc_library(
srcs = ["lpi_glop.cpp"],
deps = [
"//ortools/glop:lp_solver",
"@scip//:libscip",
"@scip",
],
)

Expand Down
2 changes: 1 addition & 1 deletion ortools/linear_solver/proto_solver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
}),
)
Expand Down
2 changes: 1 addition & 1 deletion ortools/linear_solver/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
2 changes: 1 addition & 1 deletion ortools/math_opt/io/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
4 changes: 2 additions & 2 deletions ortools/math_opt/solvers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
],
)

Expand Down
2 changes: 1 addition & 1 deletion ortools/math_opt/solvers/gscip/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Loading
Loading