Skip to content

Commit 920740d

Browse files
committed
WIP: compile and test for Windows
1 parent 916fe92 commit 920740d

File tree

7 files changed

+202
-1
lines changed

7 files changed

+202
-1
lines changed

.github/julia/build_tarballs.jl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Note that this script can accept some limited command-line arguments, run
2+
# `julia build_tarballs.jl --help` to see a usage message.
3+
using BinaryBuilder, Pkg
4+
5+
name = "MiniZinc"
6+
7+
version = v"2.8.5"
8+
9+
sources = [
10+
GitSource(
11+
"https://github.com/MiniZinc/libminizinc.git",
12+
"2fdef7b40921981f3f9ea82017e9d84937ddab77",
13+
),
14+
DirectorySource("./bundled"),
15+
]
16+
17+
script = raw"""
18+
cd $WORKSPACE/srcdir/libminizinc
19+
20+
atomic_patch -p1 ${WORKSPACE}/srcdir/patches/fixes.patch
21+
22+
# Patch for MinGW toolchain
23+
find .. -type f -exec sed -i 's/Windows.h/windows.h/g' {} +
24+
25+
# FAST_BUILD is needed when linking HiGHS, because that's what
26+
# we used when compiling HiGHS_jll.
27+
cmake -B build \
28+
-DCMAKE_INSTALL_PREFIX=${prefix} \
29+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
30+
-DCMAKE_BUILD_TYPE=Release \
31+
-DCMAKE_CXX_FLAGS="-I${includedir}/highs" \
32+
-DFAST_BUILD=ON
33+
cmake --build build --parallel ${nproc}
34+
cmake --install build
35+
"""
36+
37+
products = [
38+
ExecutableProduct("minizinc", :minizinc),
39+
]
40+
41+
# These are the platforms we will build for by default, unless further
42+
# platforms are passed in on the command line
43+
platforms = expand_cxxstring_abis(
44+
supported_platforms(; exclude = p -> arch(p) == "i686" && Sys.iswindows(p)),
45+
)
46+
47+
dependencies = [
48+
Dependency("CompilerSupportLibraries_jll"),
49+
# Use an exact version for HiGHS. @odow has observed segfaults with
50+
# HiGHS_jll v1.5.3 when libminizinc compiled with v1.5.1.
51+
Dependency("HiGHS_jll"; compat="=1.7.1"),
52+
]
53+
54+
build_tarballs(
55+
ARGS,
56+
name,
57+
version,
58+
sources,
59+
script,
60+
platforms,
61+
products,
62+
dependencies;
63+
preferred_gcc_version = v"6",
64+
julia_compat = "1.6",
65+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
--- a/include/minizinc/file_utils.hh
2+
+++ b/include/minizinc/file_utils.hh
3+
@@ -15,12 +15,16 @@
4+
#include <vector>
5+
6+
// Macro so that we can use overloaded wide versions of fstream::open for Windows
7+
-#ifdef _WIN32
8+
+#if defined(_WIN32) && !defined(__MINGW32__)
9+
#define FILE_PATH(path) MiniZinc::FileUtils::utf8_to_wide(path)
10+
#else
11+
#define FILE_PATH(path) (path)
12+
#endif
13+
14+
+#ifdef __MINGW32__
15+
+ #define realpath(N,R) _fullpath((R),(N),PATH_MAX)
16+
+#endif
17+
+
18+
namespace MiniZinc {
19+
namespace FileUtils {
20+
21+
--- a/minizinc.cpp
22+
+++ b/minizinc.cpp
23+
@@ -89,7 +89,7 @@ int run(const std::string& exe, const std::vector<std::string>& args, bool jsonS
24+
25+
} // namespace
26+
27+
-#ifdef _WIN32
28+
+#if defined(_WIN32) && !defined(__MINGW32__)
29+
#include <minizinc/interrupt.hh>
30+
31+
int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {
32+
@@ -121,7 +121,9 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {
33+
}
34+
#else
35+
int main(int argc, const char** argv) {
36+
+ #if !defined(__MINGW32__)
37+
OverflowHandler::install(argv);
38+
+ #endif
39+
std::vector<std::string> args(argc - 1);
40+
bool jsonStream = false;
41+
for (int i = 1; i < argc; i++) {
42+
--- a/include/minizinc/process.hh
43+
+++ b/include/minizinc/process.hh
44+
@@ -225,11 +225,11 @@ public:
45+
std::condition_variable cv;
46+
47+
std::deque<std::string> outputQueue;
48+
- thread thrStdout(&ReadPipePrint<S2O>, g_hChildStd_OUT_Rd, &doneStdout, nullptr, &outputQueue,
49+
+ std::thread thrStdout(&ReadPipePrint<S2O>, g_hChildStd_OUT_Rd, &doneStdout, nullptr, &outputQueue,
50+
&pipeMutex, &cv_mutex, &cv);
51+
- thread thrStderr(&ReadPipePrint<S2O>, g_hChildStd_ERR_Rd, &doneStderr, &_pS2Out->getLog(),
52+
+ std::thread thrStderr(&ReadPipePrint<S2O>, g_hChildStd_ERR_Rd, &doneStderr, &_pS2Out->getLog(),
53+
nullptr, &pipeMutex, nullptr, nullptr);
54+
- thread thrTimeout([&] {
55+
+ std::thread thrTimeout([&] {
56+
auto shouldStop = [&] { return hadInterrupt || (doneStderr && doneStdout); };
57+
std::unique_lock<std::mutex> lck(_interruptMutex);
58+
if (_timelimit != 0) {
59+
--- a/solvers/MIP/MIP_cplex_wrap.cpp
60+
+++ b/solvers/MIP/MIP_cplex_wrap.cpp
61+
@@ -61,7 +61,7 @@ void* dll_open(const std::string& file) {
62+
}
63+
void* dll_sym(void* dll, const char* sym) {
64+
#ifdef _WIN32
65+
- void* ret = GetProcAddress((HMODULE)dll, sym);
66+
+ void* ret = (void*)GetProcAddress((HMODULE)dll, sym);
67+
#else
68+
void* ret = dlsym(dll, sym);
69+
#endif
70+
--- a/solvers/MIP/MIP_gurobi_wrap.cpp
71+
+++ b/solvers/MIP/MIP_gurobi_wrap.cpp
72+
@@ -263,7 +263,7 @@ void* dll_open(const char* file) {
73+
}
74+
void* dll_sym(void* dll, const char* sym) {
75+
#ifdef _WIN32
76+
- void* ret = GetProcAddress((HMODULE)dll, sym);
77+
+ void* ret = (void*)GetProcAddress((HMODULE)dll, sym);
78+
#else
79+
void* ret = dlsym(dll, sym);
80+
#endif
File renamed without changes.
File renamed without changes.

.github/workflows/test-windows.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build on Linux, Run on Windows
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
permissions:
8+
actions: write
9+
contents: read
10+
jobs:
11+
build-linux:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: julia-actions/setup-julia@v2
16+
with:
17+
version: "1.7"
18+
arch: x64
19+
- uses: julia-actions/cache@v2
20+
- run: |
21+
# Replace as needed
22+
PACKAGE=MiniZinc_jll
23+
PLATFORM=x86_64-w64-mingw32-cxx11
24+
julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")'
25+
julia --color=yes .github/julia/build_tarballs.jl ${PLATFORM} --verbose --deploy=local
26+
file=/home/runner/.julia/dev/${PACKAGE}/Artifacts.toml
27+
sha1=$(grep '^git-tree-sha1' "$file" | cut -d '"' -f2)
28+
echo "ARTIFACT_SHA=${sha1}" >> $GITHUB_ENV
29+
- uses: actions/upload-artifact@v4
30+
with:
31+
name: artifacts
32+
path: '/home/runner/.julia/artifacts/${ env.ARTIFACT_SHA }'
33+
run-windows:
34+
runs-on: windows-latest
35+
needs: build-linux
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: julia-actions/setup-julia@v2
39+
with:
40+
version: "1"
41+
arch: x64
42+
- uses: julia-actions/cache@v2
43+
- uses: julia-actions/julia-buildpkg@v1
44+
- uses: actions/download-artifact@v4
45+
with:
46+
name: artifacts
47+
path: override
48+
- shell: julia --color=yes --project=. {0}
49+
run: |
50+
import MiniZinc_jll
51+
artifact_dir = MiniZinc_jll.artifact_dir
52+
sha = last(splitpath(artifact_dir))
53+
dir = escape_string(joinpath(ENV["GITHUB_WORKSPACE"], "override"))
54+
content = "$sha = \"$(dir)\"\n"
55+
write(replace(artifact_dir, sha => "Overrides.toml"), content)
56+
- uses: julia-actions/julia-runtest@v1

src/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function _minizinc_exe(f::F) where {F}
6161
else
6262
return f(joinpath(user_dir, "minizinc"))
6363
end
64-
elseif Sys.islinux() || Sys.isapple()
64+
else MiniZinc_jll.is_available()
6565
return f(MiniZinc_jll.minizinc())
6666
end
6767
return error(

0 commit comments

Comments
 (0)