Skip to content

Commit 099febf

Browse files
authored
fix: Fix Rust 1.82 builds on Linux. (#282)
Rust 1.82 removed a linker option (`--whole-archive`) which has broken linking on Linux. This reorders the building / linking so that the linker finds the correct libraries. See rust-lang/rust#128400
1 parent 09a553b commit 099febf

File tree

1 file changed

+54
-138
lines changed

1 file changed

+54
-138
lines changed

coin-or-sys/build.rs

+54-138
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashSet;
12
use std::env;
23

34
fn make_builder() -> cc::Build {
@@ -226,18 +227,60 @@ fn compile_clp() {
226227
}
227228

228229
const CGL_SRC_PATH: &str = "vendor/Cgl/Cgl/src";
229-
const CGL_SRCS: [&str; 5] = [
230+
const CGL_SRCS: [&str; 34] = [
230231
"CglCutGenerator.cpp",
231232
"CglMessage.cpp",
232233
"CglParam.cpp",
233234
"CglStored.cpp",
234235
"CglTreeInfo.cpp",
236+
"CglAllDifferent/CglAllDifferent.cpp",
237+
"CglClique/CglClique.cpp",
238+
"CglClique/CglCliqueHelper.cpp",
239+
"CglDuplicateRow/CglDuplicateRow.cpp",
240+
"CglFlowCover/CglFlowCover.cpp",
241+
"CglGMI/CglGMI.cpp",
242+
"CglGMI/CglGMIParam.cpp",
243+
"CglGomory/CglGomory.cpp",
244+
"CglKnapsackCover/CglKnapsackCover.cpp",
245+
"CglLandP/CglLandP.cpp",
246+
"CglLandP/CglLandPMessages.cpp",
247+
"CglLandP/CglLandPSimplex.cpp",
248+
"CglLandP/CglLandPTabRow.cpp",
249+
"CglLandP/CglLandPUtils.cpp",
250+
"CglLandP/CglLandPValidator.cpp",
251+
"CglMixedIntegerRounding/CglMixedIntegerRounding.cpp",
252+
"CglMixedIntegerRounding2/CglMixedIntegerRounding2.cpp",
253+
"CglOddHole/CglOddHole.cpp",
254+
"CglPreProcess/CglPreProcess.cpp",
255+
"CglProbing/CglProbing.cpp",
256+
"CglRedSplit/CglRedSplit.cpp",
257+
"CglRedSplit/CglRedSplitParam.cpp",
258+
"CglRedSplit2/CglRedSplit2.cpp",
259+
"CglRedSplit2/CglRedSplit2Param.cpp",
260+
"CglResidualCapacity/CglResidualCapacity.cpp",
261+
"CglSimpleRounding/CglSimpleRounding.cpp",
262+
"CglTwomir/CglTwomir.cpp",
263+
"CglZeroHalf/CglZeroHalf.cpp",
264+
"CglZeroHalf/Cgl012cut.cpp",
235265
];
236266

237-
fn compile_cgl() -> Vec<String> {
238-
let mut builder = make_builder();
267+
/// Returns the include directories for Cgl.
268+
fn cgl_include_dirs() -> Vec<String> {
269+
let mut include_dirs: HashSet<String> = HashSet::new();
270+
271+
include_dirs.insert(CGL_SRC_PATH.to_string());
272+
for src in CGL_SRCS.iter() {
273+
let split: Vec<_> = src.split("/").collect();
274+
if split.len() == 2 {
275+
include_dirs.insert(format!("{}/{}", CGL_SRC_PATH, split[0]));
276+
}
277+
}
239278

240-
let mut extra_include_dirs = vec![];
279+
include_dirs.into_iter().collect()
280+
}
281+
282+
fn compile_cgl() {
283+
let mut builder = make_builder();
241284

242285
builder
243286
.include(COIN_UTILS_PATH)
@@ -250,134 +293,8 @@ fn compile_cgl() -> Vec<String> {
250293
builder.file(format!("{}/{}", CGL_SRC_PATH, src));
251294
}
252295

253-
{
254-
let pth = format!("{}/CglAllDifferent", CGL_SRC_PATH);
255-
builder.file(format!("{}/CglAllDifferent.cpp", pth));
256-
extra_include_dirs.push(pth);
257-
}
258-
259-
{
260-
let pth = format!("{}/CglClique", CGL_SRC_PATH);
261-
builder.file(format!("{}/CglClique.cpp", pth));
262-
builder.file(format!("{}/CglCliqueHelper.cpp", pth));
263-
extra_include_dirs.push(pth);
264-
}
265-
266-
{
267-
let pth = format!("{}/CglDuplicateRow", CGL_SRC_PATH);
268-
builder.file(format!("{}/CglDuplicateRow.cpp", pth));
269-
extra_include_dirs.push(pth);
270-
}
271-
272-
{
273-
let pth = format!("{}/CglFlowCover", CGL_SRC_PATH);
274-
builder.file(format!("{}/CglFlowCover.cpp", pth));
275-
extra_include_dirs.push(pth);
276-
}
277-
278-
{
279-
let pth = format!("{}/CglGMI", CGL_SRC_PATH);
280-
builder.file(format!("{}/CglGMI.cpp", pth));
281-
builder.file(format!("{}/CglGMIParam.cpp", pth));
282-
extra_include_dirs.push(pth);
283-
}
284-
285-
{
286-
let pth = format!("{}/CglGomory", CGL_SRC_PATH);
287-
builder.file(format!("{}/CglGomory.cpp", pth));
288-
extra_include_dirs.push(pth);
289-
}
290-
291-
{
292-
let pth = format!("{}/CglKnapsackCover", CGL_SRC_PATH);
293-
builder.file(format!("{}/CglKnapsackCover.cpp", pth));
294-
extra_include_dirs.push(pth);
295-
}
296-
297-
{
298-
let pth = format!("{}/CglLandP", CGL_SRC_PATH);
299-
builder.file(format!("{}/CglLandP.cpp", pth));
300-
builder.file(format!("{}/CglLandPMessages.cpp", pth));
301-
builder.file(format!("{}/CglLandPSimplex.cpp", pth));
302-
builder.file(format!("{}/CglLandPTabRow.cpp", pth));
303-
builder.file(format!("{}/CglLandPUtils.cpp", pth));
304-
builder.file(format!("{}/CglLandPValidator.cpp", pth));
305-
extra_include_dirs.push(pth);
306-
}
307-
308-
{
309-
let pth = format!("{}/CglMixedIntegerRounding", CGL_SRC_PATH);
310-
builder.file(format!("{}/CglMixedIntegerRounding.cpp", pth));
311-
extra_include_dirs.push(pth);
312-
}
313-
314-
{
315-
let pth = format!("{}/CglMixedIntegerRounding2", CGL_SRC_PATH);
316-
builder.file(format!("{}/CglMixedIntegerRounding2.cpp", pth));
317-
extra_include_dirs.push(pth);
318-
}
319-
320-
{
321-
let pth = format!("{}/CglOddHole", CGL_SRC_PATH);
322-
builder.file(format!("{}/CglOddHole.cpp", pth));
323-
extra_include_dirs.push(pth);
324-
}
325-
326-
{
327-
let pth = format!("{}/CglPreProcess", CGL_SRC_PATH);
328-
builder.file(format!("{}/CglPreProcess.cpp", pth));
329-
extra_include_dirs.push(pth);
330-
}
331-
332-
{
333-
let pth = format!("{}/CglProbing", CGL_SRC_PATH);
334-
builder.file(format!("{}/CglProbing.cpp", pth));
335-
extra_include_dirs.push(pth);
336-
}
337-
338-
{
339-
let pth = format!("{}/CglRedSplit", CGL_SRC_PATH);
340-
builder.file(format!("{}/CglRedSplit.cpp", pth));
341-
builder.file(format!("{}/CglRedSplitParam.cpp", pth));
342-
extra_include_dirs.push(pth);
343-
}
344-
345-
{
346-
let pth = format!("{}/CglRedSplit2", CGL_SRC_PATH);
347-
builder.file(format!("{}/CglRedSplit2.cpp", pth));
348-
builder.file(format!("{}/CglRedSplit2Param.cpp", pth));
349-
extra_include_dirs.push(pth);
350-
}
351-
352-
{
353-
let pth = format!("{}/CglResidualCapacity", CGL_SRC_PATH);
354-
builder.file(format!("{}/CglResidualCapacity.cpp", pth));
355-
extra_include_dirs.push(pth);
356-
}
357-
358-
{
359-
let pth = format!("{}/CglSimpleRounding", CGL_SRC_PATH);
360-
builder.file(format!("{}/CglSimpleRounding.cpp", pth));
361-
extra_include_dirs.push(pth);
362-
}
363-
364-
{
365-
let pth = format!("{}/CglTwomir", CGL_SRC_PATH);
366-
builder.file(format!("{}/CglTwomir.cpp", pth));
367-
extra_include_dirs.push(pth);
368-
}
369-
370-
{
371-
let pth = format!("{}/CglZeroHalf", CGL_SRC_PATH);
372-
builder.file(format!("{}/CglZeroHalf.cpp", pth));
373-
builder.file(format!("{}/Cgl012cut.cpp", pth));
374-
extra_include_dirs.push(pth);
375-
}
376-
377-
builder.includes(&extra_include_dirs);
296+
builder.includes(cgl_include_dirs());
378297
builder.compile("Cgl");
379-
380-
extra_include_dirs
381298
}
382299

383300
const CBC_SRC_PATH: &str = "vendor/Cbc/Cbc/src";
@@ -462,18 +379,17 @@ const CBC_SRCS: [&str; 75] = [
462379
"CbcTreeLocal.cpp",
463380
];
464381

465-
fn compile_cbc(cgl_include_dirs: &[String]) {
382+
fn compile_cbc() {
466383
let mut builder = make_builder();
467384

468385
builder
469386
.include(COIN_UTILS_PATH)
470387
.include(OSI_SRC_PATH)
471388
.include(CLP_SRC_PATH)
472389
.include(CLP_OSI_SRC_PATH)
473-
.include(CGL_SRC_PATH)
474390
.include(CBC_SRC_PATH);
475391

476-
builder.includes(cgl_include_dirs);
392+
builder.includes(cgl_include_dirs());
477393

478394
for src in CBC_SRCS.iter() {
479395
builder.file(format!("{}/{}", CBC_SRC_PATH, src));
@@ -484,9 +400,9 @@ fn compile_cbc(cgl_include_dirs: &[String]) {
484400
}
485401

486402
fn main() {
487-
compile_coin_utils();
488-
compile_clp();
403+
compile_cbc();
404+
compile_cgl();
489405
compile_osi();
490-
let cgl_include_dirs = compile_cgl();
491-
compile_cbc(&cgl_include_dirs);
406+
compile_clp();
407+
compile_coin_utils();
492408
}

0 commit comments

Comments
 (0)