Commit f6745a6
committed
cxx: implement slice support for nostd
OVERVIEW:
This patch adds experimental support for us to use `slices` in a nostd/freestanding environment, aim is to run
c++ <=> cxx-rs <=> rust on a baremental target environment and use
slices, with the intention of supporting more features later.
In the application `Cargo.toml` file, the following feature cfgs are required:
```
[dependencies]
cxx = { ... , default-features = false }
[build-dependencies]
cxx-build = { ... , default-features = false }
```
Then build with:
```
RUSTFLAGS='--cfg cxx_experimental_no_alloc' cargo build
```
and in the particular `.cpp` file you may need to declare the following
```
void __assert_func (const char *__a, int, const char *__b, const char *__c) {
while (true) {}
}
void *__gxx_personality_v0;
```
FUNCTIONALITY:
Currently, this only supports slices (outside of trivial features).
TESTING:
Tested by compiling:
- cargo test (run existing tests)
- cxx/demo/ running it.
- compiling with a arm toolchain setup with cmake/corrosion
and running the binary on QEMU arm with basic logic assertions [1].
Current testing has been done in the direction of C++ -> Rust with a
simple callback test to C++. A
simple test setup can be seen here [2].
TODO:
- Get features such as `Results<Ok, Err>` working.
- When we build for the none `std` case (no `default-features`), instead of creating a symlink
to the original `cxx.h` file, we copy it over and define the macro to
disable stdlib dependencies. Perhaps there's a better way to do this?
NOTES:
By default, all the standard features are enabled gaurded by the
`#ifndef CXXBRIDGE1_RUST_STD`, so this **shoudn't** break anything.
[1] https://github.com/twilfredo/qemu_misc/tree/master/bm_arm
[2] https://github.com/twilfredo/qemu_misc/blob/master/bm_arm/main.cpp
Signed-off-by: Wilfred Mallawa <[email protected]>1 parent c7060d4 commit f6745a6
File tree
5 files changed
+82
-26
lines changed- gen/build
- src
- include
- src
5 files changed
+82
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
393 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
394 | 411 | | |
395 | 412 | | |
396 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | | - | |
8 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
12 | | - | |
13 | | - | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| |||
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
412 | 417 | | |
413 | 418 | | |
414 | 419 | | |
| 420 | + | |
415 | 421 | | |
416 | 422 | | |
| 423 | + | |
417 | 424 | | |
418 | 425 | | |
419 | 426 | | |
| |||
465 | 472 | | |
466 | 473 | | |
467 | 474 | | |
468 | | - | |
469 | | - | |
470 | 475 | | |
471 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
472 | 480 | | |
473 | 481 | | |
474 | 482 | | |
475 | 483 | | |
| 484 | + | |
| 485 | + | |
476 | 486 | | |
477 | 487 | | |
478 | 488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| |||
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| |||
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
76 | 87 | | |
77 | 88 | | |
78 | 89 | | |
| |||
85 | 96 | | |
86 | 97 | | |
87 | 98 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| |||
377 | 382 | | |
378 | 383 | | |
379 | 384 | | |
| 385 | + | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| |||
406 | 412 | | |
407 | 413 | | |
408 | 414 | | |
| 415 | + | |
409 | 416 | | |
410 | 417 | | |
411 | 418 | | |
412 | 419 | | |
413 | 420 | | |
| 421 | + | |
414 | 422 | | |
415 | 423 | | |
416 | 424 | | |
| |||
448 | 456 | | |
449 | 457 | | |
450 | 458 | | |
| 459 | + | |
451 | 460 | | |
452 | 461 | | |
453 | 462 | | |
| |||
494 | 503 | | |
495 | 504 | | |
496 | 505 | | |
| 506 | + | |
497 | 507 | | |
498 | 508 | | |
499 | 509 | | |
| |||
513 | 523 | | |
514 | 524 | | |
515 | 525 | | |
| 526 | + | |
516 | 527 | | |
517 | 528 | | |
518 | 529 | | |
| 530 | + | |
519 | 531 | | |
520 | 532 | | |
521 | 533 | | |
| |||
530 | 542 | | |
531 | 543 | | |
532 | 544 | | |
533 | | - | |
| 545 | + | |
534 | 546 | | |
535 | 547 | | |
536 | 548 | | |
| |||
547 | 559 | | |
548 | 560 | | |
549 | 561 | | |
| 562 | + | |
550 | 563 | | |
551 | 564 | | |
552 | 565 | | |
| |||
559 | 572 | | |
560 | 573 | | |
561 | 574 | | |
| 575 | + | |
562 | 576 | | |
563 | 577 | | |
564 | 578 | | |
| |||
790 | 804 | | |
791 | 805 | | |
792 | 806 | | |
| 807 | + | |
0 commit comments