Skip to content

Commit 4e5553b

Browse files
committed
refactor(rust): fix Provider lifecycle, improve cross-platform scripts, and address PR #44 review feedback
Rust bindings improvements: - Provider::open_device: clean up callbacks before destroying handle (prevents UAF/leaks) - set_resolution: add rollback logic to avoid partial state updates if height set fails - Global error callback: clarify process-global semantics with alias APIs - Add set_global_error_callback() and clear_global_error_callback() aliases - Always clear C-side callback in clear_error_callback() Build and test script improvements: - build_and_test.sh: cross-platform CPU core detection (nproc → sysctl/getconf fallback) - build_and_test.sh: robust CLI binary discovery (handle .exe on Windows) - build_and_test.sh: remove duplicate echo output - test_remote_crate.sh: fix cargo metadata version detection (remove --no-deps) - test_remote_crate.sh: improve cargo update error handling message Documentation fixes: - Wrap bare URLs in angle brackets (MD034) - Fix list indentation and table formatting (MD007/MD060) - Add blank lines around list features (MD032) Verified with: - cargo fmt (format all code) - cargo test (Rust bindings pass) - markdownlint (no errors remaining)
1 parent f8a8026 commit 4e5553b

12 files changed

Lines changed: 527 additions & 420 deletions

File tree

.vscode/tasks.json

Lines changed: 114 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@
157157
"problemMatcher": [],
158158
"windows": {
159159
"command": "cmd",
160-
"args": [
161-
"/c",
162-
"if not exist dev.cmake (copy cmake\\dev.cmake.example dev.cmake && echo dev.cmake created from template) else (echo dev.cmake already exists)"
163-
]
160+
"args": ["/c", "if not exist dev.cmake (copy cmake\\dev.cmake.example dev.cmake && echo dev.cmake created from template) else (echo dev.cmake already exists)"]
164161
}
165162
},
166163
{
@@ -178,10 +175,7 @@
178175
"problemMatcher": [],
179176
"windows": {
180177
"command": "cmd",
181-
"args": [
182-
"/c",
183-
"if exist dev.cmake del dev.cmake"
184-
]
178+
"args": ["/c", "if exist dev.cmake del dev.cmake"]
185179
}
186180
},
187181
{
@@ -1131,9 +1125,7 @@
11311125
"dependsOrder": "sequence",
11321126
"windows": {
11331127
"command": ".\\ccap.exe",
1134-
"args": [
1135-
"--help"
1136-
],
1128+
"args": ["--help"],
11371129
"problemMatcher": "$msCompile"
11381130
}
11391131
},
@@ -1158,9 +1150,7 @@
11581150
"dependsOrder": "sequence",
11591151
"windows": {
11601152
"command": ".\\ccap.exe",
1161-
"args": [
1162-
"--list-devices"
1163-
],
1153+
"args": ["--list-devices"],
11641154
"problemMatcher": "$msCompile"
11651155
}
11661156
},
@@ -1185,11 +1175,7 @@
11851175
"dependsOrder": "sequence",
11861176
"windows": {
11871177
"command": ".\\ccap.exe",
1188-
"args": [
1189-
"-d",
1190-
"0",
1191-
"--preview"
1192-
],
1178+
"args": ["-d", "0", "--preview"],
11931179
"problemMatcher": "$msCompile"
11941180
}
11951181
},
@@ -1214,14 +1200,7 @@
12141200
"dependsOrder": "sequence",
12151201
"windows": {
12161202
"command": ".\\ccap.exe",
1217-
"args": [
1218-
"-d",
1219-
"0",
1220-
"-c",
1221-
"5",
1222-
"-o",
1223-
".\\captures"
1224-
],
1203+
"args": ["-d", "0", "-c", "5", "-o", ".\\captures"],
12251204
"problemMatcher": "$msCompile"
12261205
}
12271206
},
@@ -1246,9 +1225,7 @@
12461225
"dependsOrder": "sequence",
12471226
"windows": {
12481227
"command": ".\\ccap.exe",
1249-
"args": [
1250-
"--help"
1251-
],
1228+
"args": ["--help"],
12521229
"problemMatcher": "$msCompile"
12531230
}
12541231
},
@@ -1273,9 +1250,7 @@
12731250
"dependsOrder": "sequence",
12741251
"windows": {
12751252
"command": ".\\ccap.exe",
1276-
"args": [
1277-
"--list-devices"
1278-
],
1253+
"args": ["--list-devices"],
12791254
"problemMatcher": "$msCompile"
12801255
}
12811256
},
@@ -1300,11 +1275,7 @@
13001275
"dependsOrder": "sequence",
13011276
"windows": {
13021277
"command": ".\\ccap.exe",
1303-
"args": [
1304-
"-d",
1305-
"0",
1306-
"--preview"
1307-
],
1278+
"args": ["-d", "0", "--preview"],
13081279
"problemMatcher": "$msCompile"
13091280
}
13101281
},
@@ -1329,17 +1300,110 @@
13291300
"dependsOrder": "sequence",
13301301
"windows": {
13311302
"command": ".\\ccap.exe",
1332-
"args": [
1333-
"-d",
1334-
"0",
1335-
"-c",
1336-
"5",
1337-
"-o",
1338-
".\\captures"
1339-
],
1303+
"args": ["-d", "0", "-c", "5", "-o", ".\\captures"],
13401304
"problemMatcher": "$msCompile"
13411305
}
13421306
},
1307+
{
1308+
"label": "Run Rust print_camera",
1309+
"type": "shell",
1310+
"command": "cargo",
1311+
"args": [
1312+
"run",
1313+
"--example",
1314+
"print_camera"
1315+
],
1316+
"options": {
1317+
"cwd": "${workspaceFolder}/bindings/rust"
1318+
},
1319+
"group": "build",
1320+
"problemMatcher": "$rustc"
1321+
},
1322+
{
1323+
"label": "Run Rust minimal_example",
1324+
"type": "shell",
1325+
"command": "cargo",
1326+
"args": [
1327+
"run",
1328+
"--example",
1329+
"minimal_example"
1330+
],
1331+
"options": {
1332+
"cwd": "${workspaceFolder}/bindings/rust"
1333+
},
1334+
"group": "build",
1335+
"problemMatcher": "$rustc"
1336+
},
1337+
{
1338+
"label": "Run Rust capture_grab",
1339+
"type": "shell",
1340+
"command": "cargo",
1341+
"args": [
1342+
"run",
1343+
"--example",
1344+
"capture_grab"
1345+
],
1346+
"options": {
1347+
"cwd": "${workspaceFolder}/bindings/rust"
1348+
},
1349+
"group": "build",
1350+
"problemMatcher": "$rustc"
1351+
},
1352+
{
1353+
"label": "Run Rust capture_callback",
1354+
"type": "shell",
1355+
"command": "cargo",
1356+
"args": [
1357+
"run",
1358+
"--example",
1359+
"capture_callback"
1360+
],
1361+
"options": {
1362+
"cwd": "${workspaceFolder}/bindings/rust"
1363+
},
1364+
"group": "build",
1365+
"problemMatcher": "$rustc"
1366+
},
1367+
{
1368+
"label": "Build Rust Bindings",
1369+
"type": "shell",
1370+
"command": "cargo",
1371+
"args": [
1372+
"build"
1373+
],
1374+
"options": {
1375+
"cwd": "${workspaceFolder}/bindings/rust"
1376+
},
1377+
"group": "build",
1378+
"problemMatcher": "$rustc"
1379+
},
1380+
{
1381+
"label": "Build Rust Examples",
1382+
"type": "shell",
1383+
"command": "cargo",
1384+
"args": [
1385+
"build",
1386+
"--examples"
1387+
],
1388+
"options": {
1389+
"cwd": "${workspaceFolder}/bindings/rust"
1390+
},
1391+
"group": "build",
1392+
"problemMatcher": "$rustc"
1393+
},
1394+
{
1395+
"label": "Test Rust Bindings",
1396+
"type": "shell",
1397+
"command": "cargo",
1398+
"args": [
1399+
"test"
1400+
],
1401+
"options": {
1402+
"cwd": "${workspaceFolder}/bindings/rust"
1403+
},
1404+
"group": "build",
1405+
"problemMatcher": "$rustc"
1406+
},
13431407
{
13441408
"label": "Run ccap CLI --video test.mp4 (Debug)",
13451409
"type": "shell",
@@ -1361,14 +1425,7 @@
13611425
"dependsOrder": "sequence",
13621426
"windows": {
13631427
"command": ".\\ccap.exe",
1364-
"args": [
1365-
"--video",
1366-
"test.mp4",
1367-
"-c",
1368-
"10",
1369-
"-o",
1370-
".\\video_frames"
1371-
],
1428+
"args": ["--video", "test.mp4", "-c", "10", "-o", ".\\video_frames"],
13721429
"options": {
13731430
"cwd": "${workspaceFolder}/build/Debug"
13741431
},
@@ -1396,14 +1453,7 @@
13961453
"dependsOrder": "sequence",
13971454
"windows": {
13981455
"command": ".\\ccap.exe",
1399-
"args": [
1400-
"--video",
1401-
"test.mp4",
1402-
"-c",
1403-
"10",
1404-
"-o",
1405-
".\\video_frames"
1406-
],
1456+
"args": ["--video", "test.mp4", "-c", "10", "-o", ".\\video_frames"],
14071457
"options": {
14081458
"cwd": "${workspaceFolder}/build/Release"
14091459
},
@@ -1431,11 +1481,7 @@
14311481
"dependsOrder": "sequence",
14321482
"windows": {
14331483
"command": ".\\ccap.exe",
1434-
"args": [
1435-
"-i",
1436-
"test.mp4",
1437-
"--preview"
1438-
],
1484+
"args": ["-i", "test.mp4", "--preview"],
14391485
"options": {
14401486
"cwd": "${workspaceFolder}/build/Debug"
14411487
},
@@ -1463,116 +1509,12 @@
14631509
"dependsOrder": "sequence",
14641510
"windows": {
14651511
"command": ".\\ccap.exe",
1466-
"args": [
1467-
"-i",
1468-
"test.mp4",
1469-
"--preview"
1470-
],
1512+
"args": ["-i", "test.mp4", "--preview"],
14711513
"options": {
14721514
"cwd": "${workspaceFolder}/build/Release"
14731515
},
14741516
"problemMatcher": "$msCompile"
14751517
}
1476-
},
1477-
{
1478-
"label": "Run Rust print_camera",
1479-
"type": "shell",
1480-
"command": "cargo",
1481-
"args": [
1482-
"run",
1483-
"--example",
1484-
"print_camera"
1485-
],
1486-
"options": {
1487-
"cwd": "${workspaceFolder}/bindings/rust"
1488-
},
1489-
"group": "build",
1490-
"problemMatcher": "$rustc"
1491-
},
1492-
{
1493-
"label": "Run Rust minimal_example",
1494-
"type": "shell",
1495-
"command": "cargo",
1496-
"args": [
1497-
"run",
1498-
"--example",
1499-
"minimal_example"
1500-
],
1501-
"options": {
1502-
"cwd": "${workspaceFolder}/bindings/rust"
1503-
},
1504-
"group": "build",
1505-
"problemMatcher": "$rustc"
1506-
},
1507-
{
1508-
"label": "Run Rust capture_grab",
1509-
"type": "shell",
1510-
"command": "cargo",
1511-
"args": [
1512-
"run",
1513-
"--example",
1514-
"capture_grab"
1515-
],
1516-
"options": {
1517-
"cwd": "${workspaceFolder}/bindings/rust"
1518-
},
1519-
"group": "build",
1520-
"problemMatcher": "$rustc"
1521-
},
1522-
{
1523-
"label": "Run Rust capture_callback",
1524-
"type": "shell",
1525-
"command": "cargo",
1526-
"args": [
1527-
"run",
1528-
"--example",
1529-
"capture_callback"
1530-
],
1531-
"options": {
1532-
"cwd": "${workspaceFolder}/bindings/rust"
1533-
},
1534-
"group": "build",
1535-
"problemMatcher": "$rustc"
1536-
},
1537-
{
1538-
"label": "Build Rust Bindings",
1539-
"type": "shell",
1540-
"command": "cargo",
1541-
"args": [
1542-
"build"
1543-
],
1544-
"options": {
1545-
"cwd": "${workspaceFolder}/bindings/rust"
1546-
},
1547-
"group": "build",
1548-
"problemMatcher": "$rustc"
1549-
},
1550-
{
1551-
"label": "Build Rust Examples",
1552-
"type": "shell",
1553-
"command": "cargo",
1554-
"args": [
1555-
"build",
1556-
"--examples"
1557-
],
1558-
"options": {
1559-
"cwd": "${workspaceFolder}/bindings/rust"
1560-
},
1561-
"group": "build",
1562-
"problemMatcher": "$rustc"
1563-
},
1564-
{
1565-
"label": "Test Rust Bindings",
1566-
"type": "shell",
1567-
"command": "cargo",
1568-
"args": [
1569-
"test"
1570-
],
1571-
"options": {
1572-
"cwd": "${workspaceFolder}/bindings/rust"
1573-
},
1574-
"group": "build",
1575-
"problemMatcher": "$rustc"
15761518
}
15771519
]
15781520
}

0 commit comments

Comments
 (0)