Skip to content

Commit c948854

Browse files
authored
Merge pull request #4 from mathworks/dev_Pablo
Minor improvements in API and modularity
2 parents ddc5d38 + 41aa267 commit c948854

9 files changed

Lines changed: 87 additions & 35 deletions

File tree

.github/workflows/main.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
paths-ignore:
99
- '*.md'
1010
- '.github/workflows/release.yml'
11-
- 'toolbox/overlay-triplets/**'
1211
- 'toolbox/*.mlx'
1312

1413
pull_request:
@@ -51,3 +50,29 @@ jobs:
5150
# Optional category for the results
5251
# Used to differentiate multiple results for one commit
5352
category: matlab
53+
54+
- name: Upload Test Results
55+
if: success() || failure()
56+
uses: actions/upload-artifact@v7
57+
with:
58+
if-no-files-found: error
59+
path: testResults.xml
60+
61+
publish-test-results:
62+
needs: check-and-test
63+
runs-on: ubuntu-latest
64+
permissions:
65+
checks: write
66+
# only needed unless run with comment_mode: off
67+
pull-requests: write
68+
if: (!cancelled())
69+
steps:
70+
- name: Download Test Results
71+
uses: actions/download-artifact@v8
72+
with:
73+
path: artifacts
74+
75+
- name: Publish Test Results
76+
uses: EnricoMi/publish-unit-test-result-action@v2
77+
with:
78+
files: "artifacts/**/*.xml"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![View vcpkg Wrapper for MATLAB on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/182780-vcpkg-wrapper-for-matlab)
44

55
This simple toolbox wraps [vcpkg - Open source C/C++ dependency manager from Microsoft®](https://vcpkg.io/en/index.html) to ease the integration into MATLAB projects that use vcpkg [manifest mode](https://learn.microsoft.com/en-us/vcpkg/concepts/manifest-mode) to define its dependencies.
6-
The wrapper toolbox figures out the host and target triplets as well as the compiler paths automatically. It only required vcpkg to be available on the system's path.
6+
The wrapper toolbox figures out the host and target triplets as well as the compiler paths automatically. You can also pass an explicit target triplet when automatic detection is not the desired behavior. It only requires vcpkg to be available on the system's path.
77

88
## Setup
99
Download toolbox installer from releases in GitHub or File Exchange and install in MATLAB.

buildfile.m

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
function plan = buildfile
22
import matlab.buildtool.Task
3-
import matlab.buildtool.tasks.CodeIssuesTask
4-
import matlab.buildtool.tasks.TestTask
5-
import matlab.unittest.Verbosity
3+
import matlab.buildtool.tasks.*
64

75
% Create a plan with no tasks
86
plan = buildplan;
97

108
% Add a task to identify and export the code issues
11-
plan("check") = CodeIssuesTask(["toolbox", "tests"],...
12-
WarningThreshold=0,...
9+
plan("check") = CodeIssuesTask(["toolbox", "tests"], ...
10+
WarningThreshold=0, ...
1311
Results="code-issues/results.sarif");
1412

15-
plan("test") = Task(...
16-
"Description","Build toolbox dependencies with vcpkg",...
17-
"Inputs",["toolbox", "tests/vcpkg.json"],...
18-
"Outputs",[fullfile("work",vcpkg.getHostTriplet), fullfile("work",vcpkg.getTargetTriplet)],...
19-
Actions = {@(~) vcpkg.buildVcpkgDeps('tests','--x-install-root=../work')});
13+
plan("unit") = TestTask( "tests", ...
14+
Description="Run MATLAB unit tests", ...
15+
SourceFiles="toolbox", ...
16+
TestResults="testResults.xml");
17+
18+
plan("integration") = Task( ...
19+
Description="Build sample toolbox dependencies with vcpkg", ...
20+
Inputs=["toolbox", "tests/vcpkg.json"], ...
21+
Outputs=[fullfile("work", vcpkg.getHostTriplet), fullfile("work", vcpkg.getTargetTriplet)], ...
22+
Actions={@(~) vcpkg.buildVcpkgDeps('tests', '--x-install-root=../work')});
23+
24+
plan("test") = Task( ...
25+
Description="Run all tests", ...
26+
Dependencies=["unit" "integration"]);
2027

2128
% Package toolbox
22-
plan("package") = Task(...
23-
Description = "Package toolbox", ...
24-
Dependencies = ["check" "test"], ...
25-
Actions = {@(~,toolboxVersion) packageToolbox(erase(toolboxVersion,"v"))});
29+
plan("package") = Task( ...
30+
Description="Package toolbox", ...
31+
Dependencies=["check" "test"], ...
32+
Actions={@(~, toolboxVersion) packageToolbox(erase(toolboxVersion, "v"))});
2633

27-
% Make the "test" task the default task in the plan
34+
% Make check and test the default tasks in the plan
2835
plan.DefaultTasks = ["check" "test"];
2936

3037
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info Ref="tests" Type="Relative"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info location="0c2237cf-1193-46a8-a375-3db856a5559f" type="Reference"/>

toolbox/+vcpkg/getHostTriplet.m

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
function triplet = getHostTriplet
2+
%getHostTriplet Return the vcpkg triplet for the selected MATLAB C++ compiler.
3+
% TRIPLET = vcpkg.getHostTriplet returns the vcpkg host triplet that
4+
% matches the current platform and the selected MATLAB C++ MEX compiler.
5+
% On Windows, MSVC and MinGW are distinguished from the selected compiler.
26

37
% Copyright 2025 The MathWorks, Inc.
48

59
cfg = mex.getCompilerConfigurations('C++', 'Selected');
610

7-
assert(~isempty(cfg), 'No compiler was found for this MATLAB installation. Please run "mex -setup" on the MATLAB command window first, and install a supported C/C++ compiler.');
11+
if isempty(cfg)
12+
error('vcpkg:getHostTriplet:CompilerNotFound', ...
13+
['No compiler was found for this MATLAB installation. Please run ', ...
14+
'"mex -setup" on the MATLAB command window first, and install a ', ...
15+
'supported C/C++ compiler.']);
16+
end
817

918
if ispc
10-
if contains(cfg.ShortName,'MSVC','IgnoreCase',true)
19+
if contains(cfg.ShortName, 'MSVC', 'IgnoreCase', true)
1120
triplet = 'x64-windows-static-md';
12-
elseif contains(cfg.ShortName,'mingw','IgnoreCase',true)
21+
elseif contains(cfg.ShortName, 'mingw', 'IgnoreCase', true)
1322
triplet = 'x64-mingw-static';
1423
else
15-
error('Compiler %s not supported', cfg.Name);
24+
error('vcpkg:getHostTriplet:UnsupportedCompiler', ...
25+
'Compiler %s not supported.', cfg.Name);
1626
end
1727
elseif isunix && ~ismac
1828
triplet = 'x64-linux';
1929
elseif ismac
20-
triplet = 'x64-osx';
30+
if strcmp(computer('arch'), 'maca64')
31+
triplet = 'arm64-osx';
32+
else
33+
triplet = 'x64-osx';
34+
end
2135
else
22-
error('Platform not supported');
23-
end
24-
36+
error('vcpkg:getHostTriplet:UnsupportedPlatform', 'Platform not supported.');
2537
end
2638

39+
end

toolbox/+vcpkg/getTargetTriplet.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
function triplet = getTargetTriplet
2+
%getTargetTriplet Return the default vcpkg target triplet for this MATLAB setup.
3+
% TRIPLET = vcpkg.getTargetTriplet returns the target triplet implied by
4+
% the installed target support package and MATLAB release. If no supported
5+
% target environment is detected, TRIPLET is empty.
26

37
% Copyright 2025 The MathWorks, Inc.
48

5-
% Initialize target triplet
69
triplet = '';
710

8-
% Get simple list of installed toolboxes
9-
listToolbox = ver;
10-
listToolbox = {listToolbox.Name}';
11+
installedProducts = ver;
12+
installedProductNames = {installedProducts.Name}';
1113

12-
% Figure out target triplet based on installed target toolbox
13-
if any(contains(listToolbox,'Simulink Real-Time'))
14+
if any(contains(installedProductNames, 'Simulink Real-Time'))
1415
if isMATLABReleaseOlderThan('R2026a') && ~isMATLABReleaseOlderThan('R2020b')
1516
triplet = 'x64-qnx-static';
1617
elseif isMATLABReleaseOlderThan('R2020b')
1718
triplet = 'x86-windows-static';
1819
else
19-
% MATLAB R2026a or later
2020
triplet = 'x64-speedgoat-linux-static';
2121
end
2222
end

toolbox/+vcpkg/getToolboxRoot.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
function toolboxRoot = getToolboxRoot
2+
%getToolboxRoot Return the root folder of the installed vcpkg toolbox.
3+
% ROOT = vcpkg.getToolboxRoot returns the folder that contains the +vcpkg
4+
% package and shipped overlay triplets.
25

36
% Copyright 2025 The MathWorks, Inc.
47

utils/packageToolbox.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
toolboxOptions.ToolboxName = "vcpkg Wrapper for MATLAB";
1111
toolboxOptions.ToolboxVersion = toolboxVersion.string;
12-
toolboxOptions.Summary = "This toolbox wraps vcpkg to enable easy packet management in MATLAB projects.";
12+
toolboxOptions.Summary = "This toolbox wraps vcpkg to enable easy package management in MATLAB projects.";
1313
toolboxOptions.AuthorName = 'Pablo Romero';
1414
toolboxOptions.AuthorEmail = "promero@mathworks.com";
1515
toolboxOptions.AuthorCompany = "The MathWorks";
1616
% toolboxOptions.ToolboxImageFile = "toolbox/toolboxIcon.jpeg";
1717
toolboxOptions.ToolboxGettingStartedGuide = "toolbox/gettingStarted.mlx";
18-
toolboxOptions.OutputFile = sprintf("vcpkg-wrapper-toolbox-v%s.mltbx",toolboxVersion.string);
18+
toolboxOptions.OutputFile = sprintf("vcpkg-wrapper-toolbox-v%s.mltbx", toolboxVersion.string);
1919

20-
toolboxOptions.MinimumMatlabRelease = "R2019b"; % R2024b is minimum required because of "arguments"
20+
toolboxOptions.MinimumMatlabRelease = "R2019b";
2121
% toolboxOptions.MaximumMatlabRelease = "R2023a"; % Won't limit maximum MATLAB release
2222
toolboxOptions.SupportedPlatforms.Glnxa64 = true;
2323
toolboxOptions.SupportedPlatforms.Maci64 = true;

0 commit comments

Comments
 (0)