Skip to content

Commit

Permalink
Merge branch 'main' of github.com:google/or-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Sep 13, 2023
2 parents 7d0d173 + 2e64e4e commit 4049eab
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 167 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/amd64_web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ref: https://github.com/docker-library/official-images
name: amd64 Web

on: [push, pull_request, workflow_dispatch]

jobs:
Distros:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check docker
run: |
docker info
docker buildx ls
- name: Build env image
run: make --directory=cmake web_env
- name: Build devel project
run: make --directory=cmake web_devel
- name: Build project
run: make --directory=cmake web_build
- name: Test project
run: make --directory=cmake web_test
42 changes: 41 additions & 1 deletion cmake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,46 @@ $(foreach stage,$(TOOLCHAIN_STAGES),$(eval $(call toolchain-stage-target,$(stage
clean_toolchains: $(addprefix clean_toolchain_, $(TOOLCHAIN_STAGES))
-rmdir $(addprefix cache/, $(TOOLCHAIN_TARGETS))

#########
## WEB ##
#########
WEB_STAGES := env devel build test

define make-web-stage-target =
#$$(info STAGE: $1)
#$$(info Create target: web_$1.)
.PHONY: web_$1
web_$1: docker/web/Dockerfile
#@docker image rm -f ${IMAGE}:web_$1 2>/dev/null
${DOCKER_BUILD_CMD} --target=$1 --tag ${IMAGE}:web_$1 -f $$< ..

#$$(info Create target: save_web_$1 (debug).)
.PHONY: save_web_$1
save_web_$1: cache/web/docker_$1.tar
cache/web/docker_$1.tar: web_$1
@rm -f $$@
mkdir -p cache/web
docker save ${IMAGE}:web_$1 -o $$@

#$$(info Create target: sh_web_$1 (debug).)
.PHONY: sh_web_$1
sh_web_$1: web_$1
${DOCKER_RUN_CMD} -it --name ${IMAGE}_web_$1 ${IMAGE}:web_$1

#$$(info Create target: clean_web_$1.)
.PHONY: clean_web_$1
clean_web_$1:
docker image rm -f ${IMAGE}:web_$1 2>/dev/null
rm -f cache/web/docker_$1.tar
endef

$(foreach stage,$(WEB_STAGES),$(eval $(call make-web-stage-target,$(stage))))

## MERGE ##
.PHONY: clean_web
clean_web: $(addprefix clean_web_, $(WEB_STAGES))
rm -f cache/web

#############
## VAGRANT ##
#############
Expand Down Expand Up @@ -451,7 +491,7 @@ $(clean_glop_targets): clean_glop_%
###########
## CLEAN ##
###########
targets = $(addprefix clean_, $(DISTROS))
targets = $(addprefix clean_, $(DISTROS)) clean_web
vms = $(addprefix clean_, $(VMS))
glops = $(addprefix clean_glop_, $(STAGES))
.PHONY: clean $(targets)
Expand Down
2 changes: 1 addition & 1 deletion cmake/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ if(BUILD_MATH_OPT)
)
list(APPEND proto_files ${math_opt_proto_files})
endif()
if(USE_PDLP)
if(USE_PDLP OR BUILD_MATH_OPT)
file(GLOB_RECURSE pdlp_proto_files RELATIVE ${PROJECT_SOURCE_DIR} "ortools/pdlp/*.proto")
list(APPEND proto_files ${pdlp_proto_files})
endif()
Expand Down
31 changes: 31 additions & 0 deletions cmake/docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Create a virtual environment with all tools installed
# ref: https://hub.docker.com/_/archlinux/
FROM archlinux:latest AS env
# Install system build dependencies
ENV PATH=/usr/local/bin:$PATH
RUN pacman -Syu --noconfirm git base-devel cmake
RUN cmake -version
RUN pacman -Syu --noconfirm nodejs emscripten
ENV PATH=/usr/lib/emscripten:$PATH
RUN emcc -v

# Add the library src to our build env
FROM env AS devel
WORKDIR /home/project
COPY . .

FROM devel AS build
RUN emcmake cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=Release -DBUILD_DEPS=ON \
-DBUILD_EXAMPLES=OFF \
-DUSE_COINOR=OFF \
-DUSE_GLPK=OFF \
-DUSE_HIGHS=OFF \
-DUSE_PDLP=OFF \
-DUSE_SCIP=OFF
RUN cmake --build build --target all -v
#RUN cmake --build build --target install -v

FROM build AS test
#RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test
RUN cd build && ctest -V
16 changes: 3 additions & 13 deletions cmake/host.CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@ set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_TESTING OFF)

message(CHECK_START "Fetching ZLIB")
list(APPEND CMAKE_MESSAGE_INDENT " ")
FetchContent_Declare(
zlib
GIT_REPOSITORY "https://github.com/madler/ZLIB.git"
GIT_TAG "v1.2.13"
PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/../../../patches/ZLIB.patch")
FetchContent_MakeAvailable(zlib)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")

message(CHECK_START "Fetching Abseil-cpp")
list(APPEND CMAKE_MESSAGE_INDENT " ")
set(ABSL_ENABLE_INSTALL ON)
Expand All @@ -117,7 +106,7 @@ FetchContent_Declare(
absl
GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git"
GIT_TAG "20230802.0"
PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/../../../patches/abseil-cpp-20230802.0.patch")
PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/@PATCHES_PATH@/abseil-cpp-20230802.0.patch")
FetchContent_MakeAvailable(absl)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
Expand All @@ -128,12 +117,13 @@ set(protobuf_BUILD_TESTS OFF)
set(protobuf_BUILD_SHARED_LIBS ON)
set(protobuf_BUILD_EXPORT OFF)
set(protobuf_MSVC_STATIC_RUNTIME OFF)
set(protobuf_WITH_ZLIB OFF)
FetchContent_Declare(
protobuf
GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
GIT_TAG "v24.0"
GIT_SUBMODULES ""
PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/../../../patches/protobuf-v24.0.patch")
PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/@PATCHES_PATH@/protobuf-v24.0.patch")
FetchContent_MakeAvailable(protobuf)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
29 changes: 5 additions & 24 deletions cmake/host.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,18 @@ endif()

message(STATUS "Subproject: HostTools...")

#configure_file(
# ${CMAKE_CURRENT_SOURCE_DIR}/host.CMakeLists.txt
# ${CMAKE_CURRENT_BINARY_DIR}/host_tools/CMakeLists.txt)
#
#execute_process(
# COMMAND ${CMAKE_COMMAND} -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -G "${CMAKE_GENERATOR}" .
# RESULT_VARIABLE result
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_tools)
#if(result)
# message(FATAL_ERROR "CMake step for host tools failed: ${result}")
#endif()
#execute_process(
# COMMAND ${CMAKE_COMMAND} --build .
# RESULT_VARIABLE result
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_tools)
#if(result)
# message(FATAL_ERROR "Build step for host tools failed: ${result}")
#endif()

#file(COPY
# ${CMAKE_CURRENT_SOURCE_DIR}/cmake/host.CMakeLists.txt
# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/host_tools)
file(RELATIVE_PATH
PATCHES_PATH
${CMAKE_CURRENT_BINARY_DIR}/host_tools
${CMAKE_CURRENT_SOURCE_DIR}/patches)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/host.CMakeLists.txt
${CMAKE_CURRENT_BINARY_DIR}/host_tools/CMakeLists.txt
COPYONLY)
@ONLY)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/host_tools
#COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/host.CMakeLists.txt CMakeLists.txt
COMMAND ${CMAKE_COMMAND} -E remove_directory build
COMMAND ${CMAKE_COMMAND} -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CMAKE_CURRENT_BINARY_DIR}/host_tools/bin
COMMAND ${CMAKE_COMMAND} --build build --config Release -v
Expand Down
2 changes: 1 addition & 1 deletion ortools/base/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int64_t GetProcessMemoryUsage() {
int64_t resident_memory = t_info.resident_size;
return resident_memory;
}
#elif defined(__GNUC__) && !defined(__FreeBSD__) // LINUX
#elif defined(__GNUC__) && !defined(__FreeBSD__) && !defined(__EMSCRIPTEN__) // LINUX
int64_t GetProcessMemoryUsage() {
unsigned size = 0;
char buf[30];
Expand Down
16 changes: 16 additions & 0 deletions ortools/linear_solver/proto_solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
# limitations under the License.

file(GLOB _SRCS "*.h" "*.cc")
if(NOT USE_COINOR)
list(FILTER _SRCS EXCLUDE REGEX "/clp_proto_solver.")
list(FILTER _SRCS EXCLUDE REGEX "/cbc_proto_solver.")
endif()
if(NOT USE_GLPK)
list(FILTER _SRCS EXCLUDE REGEX "/glpk_proto_solver.")
endif()
if(NOT USE_HIGHS)
list(FILTER _SRCS EXCLUDE REGEX "/highs_proto_solver.")
endif()
if(NOT USE_PDLP)
list(FILTER _SRCS EXCLUDE REGEX "/pdlp_proto_solver.")
endif()
if(NOT USE_SCIP)
list(FILTER _SRCS EXCLUDE REGEX "/scip_proto_solver.")
endif()

set(NAME ${PROJECT_NAME}_linear_solver_proto_solver)

Expand Down
58 changes: 29 additions & 29 deletions ortools/math_opt/cpp/variable_and_expressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ class Variable {
VariableId id_;
};

namespace internal {

// The result of the equality comparison between two Variable.
//
// We use an object here to delay the evaluation of equality so that we can use
// the operator== in two use-cases:
//
// 1. when the user want to test that two Variable values references the same
// variable. This is supported by having this object support implicit
// conversion to bool.
//
// 2. when the user want to use the equality to create a constraint of equality
// between two variables.
struct VariablesEquality {
// Users are not expected to call this constructor. Instead they should only
// use the overload of `operator==` that returns this when comparing two
// Variable. For example `x == y`.
inline VariablesEquality(Variable lhs, Variable rhs);
inline operator bool() const; // NOLINT
Variable lhs;
Variable rhs;
};

} // namespace internal

inline internal::VariablesEquality operator==(const Variable& lhs,
const Variable& rhs);
inline bool operator!=(const Variable& lhs, const Variable& rhs);

template <typename V>
using VariableMap = absl::flat_hash_map<Variable, V>;

Expand Down Expand Up @@ -463,35 +492,6 @@ inline LinearExpression operator*(LinearExpression lhs, double rhs);
inline LinearExpression operator*(double lhs, LinearExpression rhs);
inline LinearExpression operator/(LinearExpression lhs, double rhs);

namespace internal {

// The result of the equality comparison between two Variable.
//
// We use an object here to delay the evaluation of equality so that we can use
// the operator== in two use-cases:
//
// 1. when the user want to test that two Variable values references the same
// variable. This is supported by having this object support implicit
// conversion to bool.
//
// 2. when the user want to use the equality to create a constraint of equality
// between two variables.
struct VariablesEquality {
// Users are not expected to call this constructor. Instead they should only
// use the overload of `operator==` that returns this when comparing two
// Variable. For example `x == y`.
inline VariablesEquality(Variable lhs, Variable rhs);
inline operator bool() const; // NOLINT
Variable lhs;
Variable rhs;
};

} // namespace internal

inline internal::VariablesEquality operator==(const Variable& lhs,
const Variable& rhs);
inline bool operator!=(const Variable& lhs, const Variable& rhs);

// A LinearExpression with a lower bound.
struct LowerBoundedLinearExpression {
// Users are not expected to use this constructor. Instead, they should build
Expand Down
Loading

0 comments on commit 4049eab

Please sign in to comment.