Skip to content

Commit 40bfab3

Browse files
committed
ci: CXXMEX env var to hint C++ compiler
this is mainly for test / CI systems as the compiler auto-detect is overidden
1 parent 1b21716 commit 40bfab3

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,8 @@ jobs:
4242

4343
- uses: ./.github/workflows/composite-install-matlab
4444

45-
- uses: ./.github/workflows/composite-buildtool
46-
47-
48-
prerelease:
49-
if: false
50-
timeout-minutes: 15
51-
runs-on: ${{ matrix.os }}
52-
53-
strategy:
54-
fail-fast: false
55-
matrix:
56-
os: [ubuntu-22.04, macos-latest, windows-latest]
57-
release: [latest-including-prerelease]
58-
59-
steps:
60-
- uses: actions/checkout@v4
61-
62-
- uses: ./.github/workflows/composite-install-matlab
45+
- name: Linux CXX
46+
if: ${{ matrix.os == 'ubuntu-22.04' }}
47+
run: echo "CXXMEX=g++-10" >> $GITHUB_ENV
6348

6449
- uses: ./.github/workflows/composite-buildtool

buildfile.m

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
%% MexTask
3131
bindir = fullfile(plan.RootFolder, pkg_name);
32-
[compiler_id, compiler_opt, linker_opt] = get_compiler_options();
32+
[compiler_opt, linker_opt] = get_compiler_options();
3333

3434
if isMATLABReleaseOlderThan("R2024b")
3535
% dummy task to allow "buildtool mex" to build all MEX targets
@@ -46,13 +46,13 @@
4646
mex_name = "mex_" + name;
4747
% specifying .Inputs and .Outputs enables incremental builds
4848
% https://www.mathworks.com/help/matlab/matlab_prog/improve-performance-with-incremental-builds.html
49-
plan(mex_name) = matlab.buildtool.Task(Actions=@(context) legacyMexTask(context, compiler_id, compiler_opt, linker_opt));
49+
plan(mex_name) = matlab.buildtool.Task(Actions=@(context) legacyMexTask(context, compiler_opt, linker_opt));
5050
plan(mex_name).Inputs = src;
5151
plan(mex_name).Outputs = fullfile(bindir, name + "." + mexext());
5252
mex_deps(end+1) = mex_name; %#ok<AGROW>
5353
else
5454
plan("mex:" + name) = matlab.buildtool.tasks.MexTask(src, bindir, ...
55-
Options=[compiler_id, compiler_opt, linker_opt]);
55+
Options=[compiler_opt, linker_opt]);
5656
end
5757
end
5858

@@ -63,9 +63,9 @@
6363
end
6464

6565

66-
function legacyMexTask(context, compiler_id, compiler_opt, linker_opt)
66+
function legacyMexTask(context, compiler_opt, linker_opt)
6767
bindir = fileparts(context.Task.Outputs.Path);
68-
mex(context.Task.Inputs.Path, "-outdir", bindir, compiler_id, compiler_opt, linker_opt)
68+
mex(context.Task.Inputs.Path, "-outdir", bindir, compiler_opt{:}, linker_opt)
6969
end
7070

7171

@@ -130,7 +130,7 @@ function publishTask(context)
130130
end
131131

132132

133-
function [compiler_id, compiler_opt, linker_opt] = get_compiler_options()
133+
function [compiler_opt, linker_opt] = get_compiler_options()
134134

135135
cxx = mex.getCompilerConfigurations('c++');
136136
flags = cxx.Details.CompilerFlags;
@@ -141,6 +141,14 @@ function publishTask(context)
141141
% mex() can't handle string.empty
142142
compiler_id = "";
143143
linker_opt = "";
144+
145+
% this override is mostly for CI. Ensure auto-compiler flags are still correct if using this.
146+
cxxenv = getenv("CXXMEX");
147+
if ~isempty(cxxenv)
148+
compiler_id = "CXX=" + cxxenv;
149+
disp("MEX compiler override: " + compiler_id)
150+
end
151+
144152
if msvc
145153
std = "/std:c++17";
146154
% on Windows, Matlab doesn't register unsupported MSVC or oneAPI
@@ -151,7 +159,7 @@ function publishTask(context)
151159
end
152160
end
153161
elseif isunix
154-
if cxx.ShortName == "g++" && ~stdlib.version_atleast(cxx.Version, "9")
162+
if ~strlength(compiler_id) && cxx.ShortName == "g++" && ~stdlib.version_atleast(cxx.Version, "9")
155163
linker_opt = "-lstdc++fs";
156164
end
157165
end
@@ -163,4 +171,8 @@ function publishTask(context)
163171
compiler_opt = "CXXFLAGS=" + opt;
164172
end
165173

174+
if strlength(compiler_id)
175+
compiler_opt = [compiler_id, compiler_opt];
176+
end
177+
166178
end

0 commit comments

Comments
 (0)