How to run OpenGL based tests on Github Actions
Hi
My name is amir and this is the first time I trying to write on medium in English.
I writing this article because when I faced the error I didn’t find any tutorial about how should I do this and took me about 2 days to find out and hopefully I can save people's time in the future.
I’m working on a hobby C++project that uses OpenGL for rendering.
I started writing unit tests for the rendering part of my project. All tests on my local machine passed but when I pushed my code on Github tests didn’t pass and this is the error I got in my CI build.
Error: WGL: The driver does not appear to support OpenGL
After a lot of researches, I found out two things that I didn’t know about Github Actions.
First: windows-latest
OS on Github Actions is the windows server, not the regular windows we use for our PC.
Second: Github Action servers don’t support any GPU based codes.
At first, The solution I found was I should use a self-hosted runner which needed to buy a server with GPU support.
But As I mentioned my project is just a hobby project just for learning and not earning money.
So I searched how I can use CPU to run OpenGL based application instead of GPU and found a project called Mesa3D which is an OpenGL implementation that allows running OpenGL commands on CPU.
Now I knew all I need to do is install Mesa3D on the Github Actions server one step before running my unit tests.
By default, Mesa3D officially doesn’t have any precompiled libraries and you should Build it yourself.
Thankfully, I found recent prebuild libraries on Github built by pal1000.
And all I did was Updating my Github Actions workflow. I just added a step before running my tests.
First, we should download prebuilt libraries from GitHub and save the zip file. I used the latest version (20.3.2) when I writing this article but you can check for the latest builds on the project releases page and replace the URL if needed.
curl.exe -L — output mesa.7z — url https://github.com/pal1000/mesa-dist-win/releases/download/20.3.2/mesa3d-20.3.2-release-msvc.7z
Second, we should extract the zip file using 7zip. You should install 7zip before this step.
There is a complete workflow sample at end of this article.
"C:\Program Files\7-Zip\7z.exe" x mesa.7z
Then we should put DLL files in the same folder as the test binary files.
I used the symbolic links to do this.
Make sure You are using the right working directory.
mklink opengl32.dll "x64\opengl32.dll"
mklink libglapi.dll "x64\libglapi.dll"
A sample workflow using CMake and Mesa3D to run OpenGL based tests on Github Actions:
Also If you are interested, you can check out my project on GitHub and use the workflow codes I use for my project.
In end, Excuse me if I had any misspell/issues with my articles.
I still learning English :)