Skip to content

Commit 821e83a

Browse files
committed
Revamp the build system
1 parent bc65f6d commit 821e83a

File tree

6 files changed

+109
-41
lines changed

6 files changed

+109
-41
lines changed

.github/workflows/runTests.yml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,52 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14-
test:
14+
build_cpp:
15+
runs-on: Linux
16+
steps:
17+
- name: Checkout RAT
18+
uses: actions/checkout@v4
19+
- name: Generate CPP
20+
uses: matlab-actions/run-command@v2
21+
with:
22+
command: addPaths; generateCpps;
23+
- name: Upload cppDeploy
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: cppDeploy
27+
retention-days: 1
28+
path: compile/fullCompile/cppDeploy/
29+
- name: Upload cppDeploy
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: codegen
33+
retention-days: 1
34+
path: compile/fullCompile/codegen/
35+
36+
build_and_test_mex:
1537
strategy:
1638
matrix:
17-
platform: [Windows, Linux, macOS]
39+
platform: [windows-latest, ubuntu-latest, macos-15-intel, macos-latest]
1840
runs-on: ${{ matrix.platform }}
41+
needs: [build_cpp]
1942

2043
steps:
2144
- name: Checkout RAT
2245
uses: actions/checkout@v4
23-
- name: Build Mex
24-
uses: matlab-actions/run-command@v2
46+
- name: Download Mex CPP
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: codgen
50+
path: compile/fullCompile/codegen/
51+
- name: Set up MATLAB
52+
uses: matlab-actions/setup-matlab@v2
2553
with:
26-
command: buildScript
27-
- name: Run tests
54+
release: R2023a
55+
products: Parallel_Computing_Toolbox
56+
- name: Build Mex and Run Tests
2857
uses: matlab-actions/run-command@v2
2958
with:
30-
command: testScript
59+
command: addPaths; generateMexFromCpp; testScript
3160
- name: Create build archive (Windows and macOS)
3261
if: runner.os != 'Linux'
3362
run: tar --exclude="**/-lang:c++.zip" --exclude=".git*/" --exclude="htmlcov/" -acvf ../${{ runner.os }}.zip *
@@ -41,23 +70,11 @@ jobs:
4170
name: ${{ runner.os }}
4271
retention-days: 1
4372
path: ${{ runner.os }}.zip
44-
- name: Create cppDeploy
45-
if: runner.os == 'Linux'
46-
uses: matlab-actions/run-command@v2
47-
with:
48-
command: cppDeploy
49-
- name: Upload cppDeploy
50-
if: runner.os == 'Linux'
51-
uses: actions/upload-artifact@v4
52-
with:
53-
name: cppDeploy
54-
retention-days: 1
55-
path: compile/fullCompile/cppDeploy/
5673

5774
deploy-nightly:
5875
if: github.ref == 'refs/heads/master'
5976
runs-on: ubuntu-latest
60-
needs: [test]
77+
needs: [build_and_test_mex]
6178
permissions:
6279
contents: write
6380
steps:
@@ -75,7 +92,7 @@ jobs:
7592
cpp-deploy:
7693
if: github.ref == 'refs/heads/master'
7794
runs-on: ubuntu-latest
78-
needs: [test]
95+
needs: [build_and_test_mex]
7996
steps:
8097
- name: Checkout Source
8198
uses: actions/checkout@v4
@@ -96,4 +113,4 @@ jobs:
96113
git config user.email github-actions@github.com
97114
git add -A
98115
git commit -m "Deploy Source Code" || true
99-
git push
116+
git push

buildScript.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
pwd;
21
addPaths;
2+
root = getappdata(0,'root');
33

44
% Save this path
55
thisPath = pwd;
66

77
% Go to the correct compile directory
8-
compilePath = fullfile(thisPath,'compile','reflectivityCalculation');
8+
compilePath = fullfile(root,'compile','reflectivityCalculation');
99
cd(compilePath);
1010
reflectivityCalculationMexBuild;
1111

12-
compilePath = fullfile(thisPath,'compile','fullCompile');
12+
compilePath = fullfile(root,'compile','fullCompile');
1313
cd(compilePath);
1414
ratMainMexBuild;
1515
ratMainCodeGen;
1616

17-
compilePath = fullfile(thisPath,'compile','customWrapper');
17+
compilePath = fullfile(root,'compile','customWrapper');
1818
cd(compilePath);
1919
wrapperMexBuild;
2020

compile/fullCompile/generateCpps.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
% Save this path
2+
curPath = pwd;
3+
4+
[compilePath, ~, ~] = fileparts(mfilename("fullpath"));
5+
6+
cd(compilePath);
7+
ratMainMexBuild;
8+
ratMainCodeGen;
9+
cppDeploy;
10+
11+
% Return to initial directory
12+
cd(curPath);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
root = getappdata(0, 'root');
2+
mex_path = [fullfile(root, 'compile', 'fullCompile', 'codegen', 'mex', 'RATMain'), filesep];
3+
mex_interface_path = [fullfile(mex_path, 'interface'), filesep];
4+
5+
includeDirs = getappdata(0,'includeDirs');
6+
includes = strcat(repmat({'-I'}, 1, length(includeDirs)), includeDirs);
7+
includes{end+1} = ['-I', mex_path];
8+
includes{end+1} = ['-I', fullfile(mex_path, 'interface')];
9+
10+
sources = {dir([mex_path, '*.cpp']).name};
11+
sources = strcat(repmat({mex_path}, 1, length(sources)), sources);
12+
sources{end+1} = [mex_interface_path, '_coder_RATMain_api.cpp'];
13+
sources{end+1} = [mex_interface_path, '_coder_RATMain_info.cpp'];
14+
15+
main_file = [mex_interface_path, '_coder_RATMain_mex.cpp'];
16+
if ismac
17+
if strcmp(computer('arch'), 'maci64')
18+
ompLib = {['-L', fullfile(matlabroot, 'sys', 'os', 'maci64')], '-liomp5'};
19+
else
20+
ompLib = {['-L', fullfile(matlabroot, 'toolbox', 'eml', 'externalDependency', 'omp', 'maca64', 'lib')], '-lomp'};
21+
end
22+
includes{end+1} = ['-I', fullfile(matlabroot, 'toolbox', 'eml', 'externalDependency', 'omp', computer('arch'), 'include')];
23+
mex(includes{:}, 'CXXFLAGS=$CXXFLAGS -fPIC -Xpreprocessor -fopenmp -fvisibility=default -ffp-contract=off -std=c++11 -stdlib=libc++', main_file, sources{:}, '-output', 'RATMain_mex', '-v', '-lemlrt', '-lmwmathutil', '-lmwblas', '-lmwlapack', ompLib{:})
24+
elseif isunix
25+
mex(includes{:}, 'CXXFLAGS=$CXXFLAGS -fopenmp -fvisibility=default -std=c++11', main_file, sources{:}, '-output', 'RATMain_mex', '-v', '-lemlrt', '-lmwmathutil', '-lmwblas', '-lmwlapack', ['-L"', matlabroot, '/sys/os/glnxa64"'], '-liomp5')
26+
else
27+
mex(includes{:}, 'COMPFLAGS=$COMPFLAGS /openmp -DHAVE_LAPACK_CONFIG_H -DLAPACK_COMPLEX_STRUCTURE -DMW_HAVE_LAPACK_DECLS -DMW_NEEDS_VERSION_H', main_file, sources{:}, '-output', 'RATMain_mex', '-v', '-llibemlrt', '-llibmwmathutil', '-lmwblas', '-lmwlapack')
28+
end
29+
30+
% Build custom file wrapper
31+
thisPath = pwd;
32+
cd(fullfile(root,'compile','customWrapper'));
33+
wrapperMexBuild;
34+
cd(thisPath);

compile/reflectivityCalculation/reflectivityCalculationMexBuild.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
% Generates MEX-function (reflectivityCalculation_mex) from reflectivityCalculation.
44

55
% Create configuration object of class 'coder.MexCodeConfig'.
6-
cfg = coder.config('mex');
7-
cfg.GenerateReport = true;
8-
cfg.EnableJIT = false;
9-
cfg.EnableOpenMP = true;
10-
cfg.TargetLang = 'C++';
6+
% cfg = coder.config('mex');
7+
% cfg.GenerateReport = true;
8+
% cfg.EnableJIT = false;
9+
% cfg.EnableOpenMP = true;
10+
% cfg.TargetLang = 'C++';
1111

1212
% Define the input argument types..
1313
ARGS = makeCompileArgs();

cppDeploy.m

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
% Copies all files required to build cpp to 'cppDeploy' folder
2-
[~, ~, ~] = rmdir('compile/fullCompile/cppDeploy', 's');
3-
load compile/fullCompile/codegen/lib/RATMain/buildInfo.mat;
2+
root = getappdata(0, 'root');
3+
compileDir = fullfile(root, 'compile');
4+
curPath = pwd;
5+
cd(compileDir)
6+
[~, ~, ~] = rmdir('fullCompile/cppDeploy', 's');
7+
load fullCompile/codegen/lib/RATMain/buildInfo.mat;
48
packNGo(buildInfo,'fileName','deploy.zip');
5-
unzip('compile/fullCompile/deploy.zip', 'compile/fullCompile/cppDeploy');
9+
unzip('fullCompile/deploy.zip', 'fullCompile/cppDeploy');
610

711
% Copy events
8-
mkdir('compile/fullCompile/cppDeploy/events/');
9-
copyfile('compile/events/eventManager.cpp', 'compile/fullCompile/cppDeploy/events/eventManager.cpp');
10-
copyfile('compile/events/eventManager.h', 'compile/fullCompile/cppDeploy/events/eventManager.h');
11-
copyfile('compile/events/eventManagerImpl.hpp', 'compile/fullCompile/cppDeploy/events/eventManagerImpl.hpp');
12+
mkdir('fullCompile/cppDeploy/events/');
13+
copyfile('events/eventManager.cpp', 'fullCompile/cppDeploy/events/eventManager.cpp');
14+
copyfile('events/eventManager.h', 'fullCompile/cppDeploy/events/eventManager.h');
15+
copyfile('events/eventManagerImpl.hpp', 'fullCompile/cppDeploy/events/eventManagerImpl.hpp');
1216

1317
% Clean up
14-
delete 'compile/fullCompile/deploy.zip' 'compile/fullCompile/cppDeploy/buildInfo.mat'...
15-
'compile/fullCompile/cppDeploy/rtw_proj.tmw' 'compile/fullCompile/cppDeploy/defines.txt'...
16-
'compile/fullCompile/cppDeploy/RATMain.a' 'compile/fullCompile/cppDeploy/RATMain.lib';
18+
delete 'fullCompile/deploy.zip' 'fullCompile/cppDeploy/buildInfo.mat'...
19+
'fullCompile/cppDeploy/rtw_proj.tmw' 'fullCompile/cppDeploy/defines.txt'...
20+
'fullCompile/cppDeploy/RATMain.a' 'fullCompile/cppDeploy/RATMain.lib';
21+
cd(curPath);

0 commit comments

Comments
 (0)