Skip to content

Commit 4c7f159

Browse files
authored
Revamp the build system (#428)
1 parent 6270487 commit 4c7f159

5 files changed

Lines changed: 114 additions & 44 deletions

File tree

.github/workflows/runTests.yml

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,70 @@ 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@v5
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
22-
uses: actions/checkout@v4
23-
- name: Build Mex
24-
uses: matlab-actions/run-command@v2
45+
uses: actions/checkout@v5
46+
- name: Download Mex CPP
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: codegen
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'
33-
run: tar --exclude="**/-lang:c++.zip" --exclude=".git*/" --exclude="htmlcov/" -acvf ../${{ runner.os }}.zip *
62+
run: tar --exclude="**/-lang:c++.zip" --exclude=".git*/" --exclude="**/codegen/" --exclude="htmlcov/" -acvf ../${{ runner.os }}-${{ runner.arch }}.zip *
3463
- name: Create build archive (Linux)
3564
if: runner.os == 'Linux'
36-
run: zip -r ../${{ runner.os }}.zip * -x "**/-lang:c++.zip" ".git*/" "htmlcov/*"
37-
- run: mv ../${{ runner.os }}.zip ${{ runner.os }}.zip
65+
run: zip -r ../${{ runner.os }}-${{ runner.arch }}.zip * -x "**/-lang:c++.zip" ".git*/" "htmlcov/*" "**/codegen/*"
66+
- run: mv ../${{ runner.os }}-${{ runner.arch }}.zip ${{ runner.os }}-${{ runner.arch }}.zip
3867
- name: Upload releases
3968
uses: actions/upload-artifact@v4
4069
with:
41-
name: ${{ runner.os }}
42-
retention-days: 1
43-
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
70+
name: ${{ runner.os }}-${{ runner.arch }}
5471
retention-days: 1
55-
path: compile/fullCompile/cppDeploy/
72+
path: ${{ runner.os }}-${{ runner.arch }}.zip
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:
@@ -68,17 +85,17 @@ jobs:
6885
- name: Create nightly release
6986
run: |
7087
output=$(gh release delete nightly --cleanup-tag --yes --repo ${{ github.repository }} 2>&1) || [[ "${output}" == "release not found" ]]
71-
gh release create nightly Windows.zip Linux.zip macOS.zip --prerelease --title "Nightly Build" --latest=false --repo ${{ github.repository }}
88+
gh release create nightly Windows-X64.zip Linux-X64.zip macOS-X64.zip macOS-ARM64.zip --prerelease --title "Nightly Build" --latest=false --repo ${{ github.repository }}
7289
env:
7390
GH_TOKEN: ${{ github.token }}
7491

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
81-
uses: actions/checkout@v4
98+
uses: actions/checkout@v5
8299
with:
83100
ref: generated_source
84101
path: rat_source
@@ -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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
curPath = pwd;
2+
root = getappdata(0, 'root');
3+
cd(fullfile(root,'compile','fullCompile'));
4+
5+
mex_path = [fullfile(root, 'compile', 'fullCompile', 'codegen', 'mex', 'RATMain'), filesep];
6+
mex_interface_path = [fullfile(mex_path, 'interface'), filesep];
7+
8+
includeDirs = getappdata(0,'includeDirs');
9+
includes = strcat(repmat({'-I'}, 1, length(includeDirs)), includeDirs);
10+
includes{end+1} = ['-I', mex_path];
11+
includes{end+1} = ['-I', fullfile(mex_path, 'interface')];
12+
13+
sources = {dir([mex_path, '*.cpp']).name};
14+
sources = strcat(repmat({mex_path}, 1, length(sources)), sources);
15+
sources{end+1} = [mex_interface_path, '_coder_RATMain_api.cpp'];
16+
sources{end+1} = [mex_interface_path, '_coder_RATMain_info.cpp'];
17+
18+
main_file = [mex_interface_path, '_coder_RATMain_mex.cpp'];
19+
if ismac
20+
if strcmp(computer('arch'), 'maci64')
21+
ompLib = {['-L', fullfile(matlabroot, 'sys', 'os', 'maci64')], '-liomp5'};
22+
else
23+
ompLib = {['-L', fullfile(matlabroot, 'toolbox', 'eml', 'externalDependency', 'omp', 'maca64', 'lib')], '-lomp'};
24+
end
25+
includes{end+1} = ['-I', fullfile(matlabroot, 'toolbox', 'eml', 'externalDependency', 'omp', computer('arch'), 'include')];
26+
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{:})
27+
elseif isunix
28+
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')
29+
else
30+
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')
31+
end
32+
33+
% Build custom file wrapper
34+
cd(fullfile(root,'compile','customWrapper'));
35+
wrapperMexBuild;
36+
cd(curPath);

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)