diff --git a/.github/workflows/runTests.yml b/.github/workflows/runTests.yml index 86cc8215d..b1e3d6173 100644 --- a/.github/workflows/runTests.yml +++ b/.github/workflows/runTests.yml @@ -11,53 +11,70 @@ 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 * + 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 }} - 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 + name: ${{ runner.os }}-${{ runner.arch }} retention-days: 1 - path: compile/fullCompile/cppDeploy/ + path: ${{ runner.os }}-${{ runner.arch }}.zip deploy-nightly: if: github.ref == 'refs/heads/master' runs-on: ubuntu-latest - needs: [test] + needs: [build_and_test_mex] permissions: contents: write steps: @@ -68,14 +85,14 @@ 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 }} 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..dbe4b9fad --- /dev/null +++ b/compile/fullCompile/generateMexFromCpp.m @@ -0,0 +1,36 @@ +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]; + +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 +cd(fullfile(root,'compile','customWrapper')); +wrapperMexBuild; +cd(curPath); 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);