From 6d9f049cc2d97372f6e5d5d849a7390e0c0d3294 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Tue, 11 Nov 2025 13:23:38 +0000 Subject: [PATCH 1/2] Revamp the build system --- .github/workflows/runTests.yml | 61 ++++++++++++------- buildScript.m | 8 +-- compile/fullCompile/generateCpps.m | 12 ++++ compile/fullCompile/generateMexFromCpp.m | 34 +++++++++++ .../reflectivityCalculationMexBuild.m | 10 +-- cppDeploy.m | 25 +++++--- 6 files changed, 109 insertions(+), 41 deletions(-) create mode 100644 compile/fullCompile/generateCpps.m create mode 100644 compile/fullCompile/generateMexFromCpp.m diff --git a/.github/workflows/runTests.yml b/.github/workflows/runTests.yml index 86cc8215d..120e54f21 100644 --- a/.github/workflows/runTests.yml +++ b/.github/workflows/runTests.yml @@ -11,23 +11,52 @@ concurrency: cancel-in-progress: true jobs: - test: + build_cpp: + runs-on: Linux + steps: + - name: Checkout RAT + uses: actions/checkout@v4 + - name: Generate CPP + uses: matlab-actions/run-command@v2 + with: + command: addPaths; generateCpps; + - name: Upload cppDeploy + uses: actions/upload-artifact@v4 + with: + name: cppDeploy + retention-days: 1 + path: compile/fullCompile/cppDeploy/ + - name: Upload cppDeploy + uses: actions/upload-artifact@v4 + with: + name: codegen + retention-days: 1 + path: compile/fullCompile/codegen/ + + build_and_test_mex: strategy: matrix: - platform: [Windows, Linux, macOS] + platform: [windows-latest, ubuntu-latest, macos-15-intel, macos-latest] runs-on: ${{ matrix.platform }} + needs: [build_cpp] steps: - name: Checkout RAT uses: actions/checkout@v4 - - name: Build Mex - uses: matlab-actions/run-command@v2 + - name: Download Mex CPP + uses: actions/download-artifact@v4 + with: + name: codegen + path: compile/fullCompile/codegen/ + - name: Set up MATLAB + uses: matlab-actions/setup-matlab@v2 with: - command: buildScript - - name: Run tests + release: R2023a + products: Parallel_Computing_Toolbox + - name: Build Mex and Run Tests uses: matlab-actions/run-command@v2 with: - command: testScript + command: addPaths; generateMexFromCpp; testScript - name: Create build archive (Windows and macOS) if: runner.os != 'Linux' run: tar --exclude="**/-lang:c++.zip" --exclude=".git*/" --exclude="htmlcov/" -acvf ../${{ runner.os }}.zip * @@ -41,23 +70,11 @@ jobs: name: ${{ runner.os }} retention-days: 1 path: ${{ runner.os }}.zip - - name: Create cppDeploy - if: runner.os == 'Linux' - uses: matlab-actions/run-command@v2 - with: - command: cppDeploy - - name: Upload cppDeploy - if: runner.os == 'Linux' - uses: actions/upload-artifact@v4 - with: - name: cppDeploy - retention-days: 1 - path: compile/fullCompile/cppDeploy/ deploy-nightly: if: github.ref == 'refs/heads/master' runs-on: ubuntu-latest - needs: [test] + needs: [build_and_test_mex] permissions: contents: write steps: @@ -75,7 +92,7 @@ jobs: cpp-deploy: if: github.ref == 'refs/heads/master' runs-on: ubuntu-latest - needs: [test] + needs: [build_and_test_mex] steps: - name: Checkout Source uses: actions/checkout@v4 @@ -96,4 +113,4 @@ jobs: git config user.email github-actions@github.com git add -A git commit -m "Deploy Source Code" || true - git push + git push \ No newline at end of file diff --git a/buildScript.m b/buildScript.m index b3b701f1f..dedfe0c8e 100644 --- a/buildScript.m +++ b/buildScript.m @@ -1,20 +1,20 @@ -pwd; addPaths; +root = getappdata(0,'root'); % Save this path thisPath = pwd; % Go to the correct compile directory -compilePath = fullfile(thisPath,'compile','reflectivityCalculation'); +compilePath = fullfile(root,'compile','reflectivityCalculation'); cd(compilePath); reflectivityCalculationMexBuild; -compilePath = fullfile(thisPath,'compile','fullCompile'); +compilePath = fullfile(root,'compile','fullCompile'); cd(compilePath); ratMainMexBuild; ratMainCodeGen; -compilePath = fullfile(thisPath,'compile','customWrapper'); +compilePath = fullfile(root,'compile','customWrapper'); cd(compilePath); wrapperMexBuild; diff --git a/compile/fullCompile/generateCpps.m b/compile/fullCompile/generateCpps.m new file mode 100644 index 000000000..87563762b --- /dev/null +++ b/compile/fullCompile/generateCpps.m @@ -0,0 +1,12 @@ +% Save this path +curPath = pwd; + +[compilePath, ~, ~] = fileparts(mfilename("fullpath")); + +cd(compilePath); +ratMainMexBuild; +ratMainCodeGen; +cppDeploy; + +% Return to initial directory +cd(curPath); diff --git a/compile/fullCompile/generateMexFromCpp.m b/compile/fullCompile/generateMexFromCpp.m new file mode 100644 index 000000000..dc0c3e6e2 --- /dev/null +++ b/compile/fullCompile/generateMexFromCpp.m @@ -0,0 +1,34 @@ +root = getappdata(0, 'root'); +mex_path = [fullfile(root, 'compile', 'fullCompile', 'codegen', 'mex', 'RATMain'), filesep]; +mex_interface_path = [fullfile(mex_path, 'interface'), filesep]; + +includeDirs = getappdata(0,'includeDirs'); +includes = strcat(repmat({'-I'}, 1, length(includeDirs)), includeDirs); +includes{end+1} = ['-I', mex_path]; +includes{end+1} = ['-I', fullfile(mex_path, 'interface')]; + +sources = {dir([mex_path, '*.cpp']).name}; +sources = strcat(repmat({mex_path}, 1, length(sources)), sources); +sources{end+1} = [mex_interface_path, '_coder_RATMain_api.cpp']; +sources{end+1} = [mex_interface_path, '_coder_RATMain_info.cpp']; + +main_file = [mex_interface_path, '_coder_RATMain_mex.cpp']; +if ismac + if strcmp(computer('arch'), 'maci64') + ompLib = {['-L', fullfile(matlabroot, 'sys', 'os', 'maci64')], '-liomp5'}; + else + ompLib = {['-L', fullfile(matlabroot, 'toolbox', 'eml', 'externalDependency', 'omp', 'maca64', 'lib')], '-lomp'}; + end + includes{end+1} = ['-I', fullfile(matlabroot, 'toolbox', 'eml', 'externalDependency', 'omp', computer('arch'), 'include')]; + 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{:}) +elseif isunix + 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') +else + 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') +end + +% Build custom file wrapper +thisPath = pwd; +cd(fullfile(root,'compile','customWrapper')); +wrapperMexBuild; +cd(thisPath); diff --git a/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m b/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m index c00ddeab7..a0d3bdf8e 100644 --- a/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m +++ b/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m @@ -3,11 +3,11 @@ % Generates MEX-function (reflectivityCalculation_mex) from reflectivityCalculation. % Create configuration object of class 'coder.MexCodeConfig'. -cfg = coder.config('mex'); -cfg.GenerateReport = true; -cfg.EnableJIT = false; -cfg.EnableOpenMP = true; -cfg.TargetLang = 'C++'; +% cfg = coder.config('mex'); +% cfg.GenerateReport = true; +% cfg.EnableJIT = false; +% cfg.EnableOpenMP = true; +% cfg.TargetLang = 'C++'; % Define the input argument types.. ARGS = makeCompileArgs(); diff --git a/cppDeploy.m b/cppDeploy.m index 25fa0678d..49a7a9cb9 100644 --- a/cppDeploy.m +++ b/cppDeploy.m @@ -1,16 +1,21 @@ % Copies all files required to build cpp to 'cppDeploy' folder -[~, ~, ~] = rmdir('compile/fullCompile/cppDeploy', 's'); -load compile/fullCompile/codegen/lib/RATMain/buildInfo.mat; +root = getappdata(0, 'root'); +compileDir = fullfile(root, 'compile'); +curPath = pwd; +cd(compileDir) +[~, ~, ~] = rmdir('fullCompile/cppDeploy', 's'); +load fullCompile/codegen/lib/RATMain/buildInfo.mat; packNGo(buildInfo,'fileName','deploy.zip'); -unzip('compile/fullCompile/deploy.zip', 'compile/fullCompile/cppDeploy'); +unzip('fullCompile/deploy.zip', 'fullCompile/cppDeploy'); % Copy events -mkdir('compile/fullCompile/cppDeploy/events/'); -copyfile('compile/events/eventManager.cpp', 'compile/fullCompile/cppDeploy/events/eventManager.cpp'); -copyfile('compile/events/eventManager.h', 'compile/fullCompile/cppDeploy/events/eventManager.h'); -copyfile('compile/events/eventManagerImpl.hpp', 'compile/fullCompile/cppDeploy/events/eventManagerImpl.hpp'); +mkdir('fullCompile/cppDeploy/events/'); +copyfile('events/eventManager.cpp', 'fullCompile/cppDeploy/events/eventManager.cpp'); +copyfile('events/eventManager.h', 'fullCompile/cppDeploy/events/eventManager.h'); +copyfile('events/eventManagerImpl.hpp', 'fullCompile/cppDeploy/events/eventManagerImpl.hpp'); % Clean up -delete 'compile/fullCompile/deploy.zip' 'compile/fullCompile/cppDeploy/buildInfo.mat'... - 'compile/fullCompile/cppDeploy/rtw_proj.tmw' 'compile/fullCompile/cppDeploy/defines.txt'... - 'compile/fullCompile/cppDeploy/RATMain.a' 'compile/fullCompile/cppDeploy/RATMain.lib'; +delete 'fullCompile/deploy.zip' 'fullCompile/cppDeploy/buildInfo.mat'... + 'fullCompile/cppDeploy/rtw_proj.tmw' 'fullCompile/cppDeploy/defines.txt'... + 'fullCompile/cppDeploy/RATMain.a' 'fullCompile/cppDeploy/RATMain.lib'; +cd(curPath); From 8b7c8ba830937a2faa7d07dedafd7cf70c10cf75 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Fri, 14 Nov 2025 09:33:58 +0000 Subject: [PATCH 2/2] add arch --- .github/workflows/runTests.yml | 12 ++++++------ compile/fullCompile/generateMexFromCpp.m | 8 +++++--- .../reflectivityCalculationMexBuild.m | 10 +++++----- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/runTests.yml b/.github/workflows/runTests.yml index 120e54f21..b1e3d6173 100644 --- a/.github/workflows/runTests.yml +++ b/.github/workflows/runTests.yml @@ -59,17 +59,17 @@ jobs: command: addPaths; generateMexFromCpp; testScript - name: Create build archive (Windows and macOS) if: runner.os != 'Linux' - run: tar --exclude="**/-lang:c++.zip" --exclude=".git*/" --exclude="htmlcov/" -acvf ../${{ runner.os }}.zip * + run: tar --exclude="**/-lang:c++.zip" --exclude=".git*/" --exclude="**/codegen/" --exclude="htmlcov/" -acvf ../${{ runner.os }}-${{ runner.arch }}.zip * - name: Create build archive (Linux) if: runner.os == 'Linux' - run: zip -r ../${{ runner.os }}.zip * -x "**/-lang:c++.zip" ".git*/" "htmlcov/*" - - run: mv ../${{ runner.os }}.zip ${{ runner.os }}.zip + run: zip -r ../${{ runner.os }}-${{ runner.arch }}.zip * -x "**/-lang:c++.zip" ".git*/" "htmlcov/*" "**/codegen/*" + - run: mv ../${{ runner.os }}-${{ runner.arch }}.zip ${{ runner.os }}-${{ runner.arch }}.zip - name: Upload releases uses: actions/upload-artifact@v4 with: - name: ${{ runner.os }} + name: ${{ runner.os }}-${{ runner.arch }} retention-days: 1 - path: ${{ runner.os }}.zip + path: ${{ runner.os }}-${{ runner.arch }}.zip deploy-nightly: if: github.ref == 'refs/heads/master' @@ -85,7 +85,7 @@ jobs: - name: Create nightly release run: | output=$(gh release delete nightly --cleanup-tag --yes --repo ${{ github.repository }} 2>&1) || [[ "${output}" == "release not found" ]] - gh release create nightly Windows.zip Linux.zip macOS.zip --prerelease --title "Nightly Build" --latest=false --repo ${{ github.repository }} + 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 }} env: GH_TOKEN: ${{ github.token }} diff --git a/compile/fullCompile/generateMexFromCpp.m b/compile/fullCompile/generateMexFromCpp.m index dc0c3e6e2..dbe4b9fad 100644 --- a/compile/fullCompile/generateMexFromCpp.m +++ b/compile/fullCompile/generateMexFromCpp.m @@ -1,4 +1,7 @@ +curPath = pwd; root = getappdata(0, 'root'); +cd(fullfile(root,'compile','fullCompile')); + mex_path = [fullfile(root, 'compile', 'fullCompile', 'codegen', 'mex', 'RATMain'), filesep]; mex_interface_path = [fullfile(mex_path, 'interface'), filesep]; @@ -27,8 +30,7 @@ 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') end -% Build custom file wrapper -thisPath = pwd; +% Build custom file wrapper cd(fullfile(root,'compile','customWrapper')); wrapperMexBuild; -cd(thisPath); +cd(curPath); diff --git a/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m b/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m index a0d3bdf8e..c00ddeab7 100644 --- a/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m +++ b/compile/reflectivityCalculation/reflectivityCalculationMexBuild.m @@ -3,11 +3,11 @@ % Generates MEX-function (reflectivityCalculation_mex) from reflectivityCalculation. % Create configuration object of class 'coder.MexCodeConfig'. -% cfg = coder.config('mex'); -% cfg.GenerateReport = true; -% cfg.EnableJIT = false; -% cfg.EnableOpenMP = true; -% cfg.TargetLang = 'C++'; +cfg = coder.config('mex'); +cfg.GenerateReport = true; +cfg.EnableJIT = false; +cfg.EnableOpenMP = true; +cfg.TargetLang = 'C++'; % Define the input argument types.. ARGS = makeCompileArgs();