-
Notifications
You must be signed in to change notification settings - Fork 6
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
Best practices for distributing MEX files with toolboxes #10
Comments
Absolutely! We definitely want to offer recommendations around building and distributing toolboxes that include MEX. They are a little tricky since they need to be built on all platforms that your toolbox supports. |
Yep, building the platforms can be tricky. I think that is slightly compensated for now since there are the Matlab runners on GitHub actions. Those would be a good way to build GitHub-hosted toolboxes in a CI environment (and that is what I am going to look into doing). |
Yes -- I'm hoping to put together an example that does just this in the future. |
Just wanted to check in and see if this was still on the horizon? |
I've been working on a toolbox for wrapping a C library for use in MATLAB, following along with the guidelines here and I think I've got a good start on distributing. There are a few walls, however, that I do not think are possible to get past at the moment for uploading to the file exchange or running in MATLAB online. My project, matlab-igraph, wraps the igraph library. It uses CMake for building all the components and github actions for building on different OSes and releasing pre-compiled toolboxes. The results should be independent of any non-standard external dependencies so I believe all that is required to run them is downloading the correct package, unzipping, and adding to MATLAB's path. Some of the problems I have run into:
Overall it's close to working. On MathWorks side, we would need them to allow mex files and be able to upload OS specific toolboxes to get it to work on the file exchange. |
I have modified my actions workflow to distribute mltbx files instead of tarballs using the package toolbox command*. I can confirm the actions built toolbox installs and runs fine on my linux computer. It also does run fine in MATLAB online (with exception to the above mentioned issue with stdlibc). File Exchange has accepted the toolbox. File Exchange only grabs the first toolbox it finds though, so it should not be possible to install correctly on another OS from the toolbox add-ons interface. At the moment the Windows build is not working but that's an issue on my side related to needing to package DLLs. If MATLAB were to provide a method for allowing File Exchange packages to be associated with multiple toolboxes (and a naming convention for distinguishing between architectures), I think everything else is ready for distributing toolboxes dependent on MEX files. We could also just dump all the compiled files into a single toolbox and let MATLAB select the architect specific file at runtime but that increases the size of the toolbox. *For some reason on macOS the package command failed with a permissions error related to not having a license for the MATLAB_Distrib_Comp_Engine, which is for running MATLAB on clusters, I can't understand why that license would have been needed. But that's the reason everything gets packaged at the end in a linux runner. |
@DavidRConnell Do you or anyone else have an example of a post install script? |
I managed to get something working, because my toolbox is a simulink blockset I was able to set a callback function when the library is loaded, in this callback function I can compile my mex files, this is my compilation script. |
@SpieringsAE I don't remember the exact details but I came to the conclusion there wasn't a way to automate running a My not-so-great solution was to provide a In the past, when I have rewritten MATLAB code into C, I usually keep the mex function private then have a public MATLAB function that calls the mex function if available. Then the MATLAB function can check if the mex function is compiled and if not can handle that in someway such as warning the user they can compile it or running the mex build command itself. So an alternative to postinstall would be having users run a make all function, but if they don't, build it for them the first time they try to use a mex function. |
@DavidRConnell Yeah I found that one too, I did consider providing a function like that, but because mine are level 2 s functions ment for use with simulink code generation it was easy to include in a library startup callback. It also makes it impossible to provide a matlab script shim inbetween. The only annoying part of my method is that it will run every time simulink is opened, so I built a little mechanism that checks if it has been compiled already so it exits pretty much instantly if it doesn't need to do anything. |
We are actively working on MEX advice for toolboxes. Please stay tuned! |
Some toolboxes are wrappers around C/C++ code compiled in MEX files. Currently, there isn't really a good set of documentation/practices for how to integrate these platform-specific MEX files into a packaged toolbox that is suitable for hosting on File Exchange. It would be good to add this to the best practices document.
The text was updated successfully, but these errors were encountered: