Running CLP from Xcode for macOS #324
Replies: 4 comments 5 replies
-
|
Hey @theogscott, this is a really impressive piece of work! Getting CLP and its dependencies (CoinUtils, OSI) running smoothly with Swift Package Manager on macOS/Xcode is a great contribution, especially for those of us who prefer the Apple ecosystem over Windows/Visual Studio. I particularly like how you've handled the resource files for unit tests within the SPM structure—that's often one of the trickier parts of moving older C++ projects to modern package managers. Since you mentioned you're open to PRs, have you considered how this might work with CI/CD on GitHub Actions? It would be awesome to see these SPM builds automatically verified. Thanks for sharing this with the community! |
Beta Was this translation helpful? Give feedback.
-
|
@pratikrath126 Yes I have thought about it, if you want to configure a CI/CD pipeline that will run the units test on old and new devices which might include iOS and they different flavours of OS version, then I would suggest using Apple Xcode Cloud. That should be pretty easy, and mostly free for the COIN-OR Foundation, Inc., is a non-profit educational and scientific foundation because of Apple's Developer Program fee waiver. |
Beta Was this translation helpful? Give feedback.
-
|
@pratikrath126 – You asked whether—and how—a CI/CD pipeline can be used to verify that a build is valid. I mentioned that one option is Xcode Cloud, which runs on Apple’s development infrastructure; of course there are also other CI/CD servers that can handle macOS builds. Keep in mind that the next release of macOS will drop support for Intel‑based Macs, so you won’t be able to cross‑compile with the latest Xcode. Fortunately, SPM (Swift Package Manager) makes this more manageable because platform‑OS version compatibility is handled inside the package. Xcode automatically selects the newest package version that satisfies all constraints, including the macOS deployment target you have set (which is normally the macOS version installed on your machine). Let me give you an example of how this works, and I am sure you are familiar with it. Below is a pull request I created: The build will fail on purpose to demonstrate how a branch can be protected. The source code compiles without error ( libClp | Analyse PR to SPM | Analyze – macOS ), but the Release/Archive build fails ( libCIp | Analyse PR to SPM | Archive – macOS ) because of a linker error.
Consequently, a pull request will not be approved nor merged until the errors are resolved for a Release build. Things become a lot more complicated when there are inter‑dependent libraries, as in this case. For example, a PR that passes on CoinUtils might break Clp; how to handle such conflicts is a policy decision that the maintainer must define. @tkralphs – I see you’re the technical lead. How should we proceed with getting these changes into the main repository? It will probably require some planning, especially if we want to add a CI/CD pipeline for macOS (and other operating systems). I’m not sure how the current build process would accommodate that. |
Beta Was this translation helpful? Give feedback.
-
|
Hi. I'm also not familiar with Xcode nor SPM, but of course I see the point of supporting a popular IDE (..) About changing existing files/folders
Is it necessary to move those files? Wouldn't that move impact other build and test workflows that are already in place? Or maybe I misunderstand. About hardcoded referencesI see Xcode Package.resolved files mention URLs to your fork. Are these hardcoded references necessary? Would those work in forks? About CI/CDPart of the reason for the windows-msvs-ci.yml workflows is that the testing of the VS project files, so all still builds. And of course also to run the unit tests. Therefore, yes, I think it would be good to also a separate CI/CD for Xcode / SPM based builds--not just the coinbrew clang / gcc builds. Each of the coin-or dependencies of Cbc (Clp, Cgl, CoinUtils, Osi) has (almost exactly) the same workflow files files, for maintainability. This makes updating the workflow easier when a newer runner is released (like for macos-26 recently). Is something like this achievable, so the workflow, the Xcode and SPM would be similar? About Xcode CloudSince the macos-26 runner image includes Xcode, couldn't we define a github workflow that uses the SPM/Xcode CLI to run the build and test without needing Xcode Cloud? Using the github workflow yml is self-contained, so without external Xcode Cloud configuration. |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Revised Text
My goal is to be able to pull the source code, create a build in Xcode targeting macOS (and eventually iOS).
I am aware that binary/library distributions exist for macOS, and I am not trying to replace them. However, contributing, experimenting, or investigating becomes difficult when you only have a Mac—especially if you stopped using Windows PCs and Visual Studio a long time ago. Until recently I worked with the LP/MIP algorithms on IBM OSL on both PC (Visual Studio) and an IBM RS/6000 machine, mainly via Fortran 90 and XLC together with IBM ESSL in commercial and academic environments. That was many years ago.
My first goal was to fork all the repositories (CoinUtils, OSI, Clp, Test Data – NetLib, Sample), re‑compile them without having to run any shell commands or use Coinbrew, and keep the setup as similar as possible to the Visual Studio one, with minimal changes. I followed the MS Visual Studio structure to retain familiarity and so that I could learn how all the libraries fit together (using Windows 11 ARM and VS 2022 ARM in a VM). I converted each library into a Swift Package (SPM), preserving the original naming conventions—
libClp,libCoinUtils,libOsi,libOsiClp,libOsiCommonTest,osiUnitTestfrom Clp.sln—and placed them in an SPM branch for each repository.The Swift Package Manager (SPM) is named after Apple’s programming language Swift, but it can also build C and C++ source code. See the documentation: https://developer.apple.com/documentation/xcode/swift-packages.
In the end I managed to get everything to build without modifying any C++ code, except for:
configall_system_aaplxcode.h, similar toconfigall_system_msc.h(I’m not 100 % sure the file is complete; some macros may be missing).Package.swiftfile at the root of each GitHub repository—SPM cannot use aPackage.swiftthat lives in a subfolder (unlike Visual Studio, which can have project files underMSVisualStudio/{Version}/*.vcxproj). An SPM package may contain more than one library and can mix languages..mpsfiles into a subfolder calledResources.Clp Examples
If you have a Mac with Xcode 26 (or later), clone the repository:
Open
./Xcode/Clp/Clp.xcodeproj. At the top of the project you will see the targets ClpExampleMinimum and ClpExamplesTestBarrier. Both require an.mpsfile as a command‑line argument. Hold the Option key, click Run from the Product menu, and a dialog will appear where you can add the path to the.mpsfile under Arguments Passed on Launch.To run the unit tests:
Xcode/Clp/Clp.xcodeproj.Package.swift.The test harness will fetch all NetLib and sample data. If everything is set up correctly you should see output similar to:
If the maintainers of Clp, Osi, or CoinUtils would like me to open a pull request, I am happy to do so and to help further. Please feel free to ask any questions or point out anything I may have missed.
P.S. There is a function declaration:
The linker kept complaining about an undefined reference to this symbol, even though it is never called in the examples or unit‑test CLI. To silence the error I created a dummy implementation (
mainTest.cpp). It appears that the function is not needed for the current build, but I left the placeholder in case future code requires it.Beta Was this translation helpful? Give feedback.
All reactions