Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the cdylib no_std #59

Merged
merged 7 commits into from
Dec 3, 2024
Merged

Make the cdylib no_std #59

merged 7 commits into from
Dec 3, 2024

Conversation

bjorn3
Copy link
Collaborator

@bjorn3 bjorn3 commented Dec 3, 2024

No description provided.

@bjorn3 bjorn3 requested a review from folkertdev December 3, 2024 10:58
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libbzip2-rs-sys/src/lib.rs 0.00% 7 Missing ⚠️
Files with missing lines Coverage Δ
libbzip2-rs-sys/src/lib.rs 87.30% <0.00%> (-10.92%) ⬇️

... and 2 files with indirect coverage changes

@bjorn3 bjorn3 force-pushed the no_std_cdylib branch 3 times, most recently from a65d24d to 75fcfe0 Compare December 3, 2024 11:33
The default features includes both c-allocator and (through std)
rust-allocator. Rust-allocator wins when both are given, so remove
c-allocator from the default features.
This reduces the size of libbz2_rs.so by 408KB in release mode.
Comment on lines 413 to 421
- name: "cdylib: no_std"
env:
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
working-directory: libbzip2-rs-sys-cdylib
run: |
cargo build --release --target ${{matrix.target}} --no-default-features
cc -DNO_STD -o bzpipe bzpipe.c target/${{matrix.target}}/release/deps/libbz2_rs.so -I ../
./bzpipe < Cargo.toml | ./bzpipe -d > out.txt
cmp -s Cargo.toml out.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now we never build wit h-DNO_STD right? we just always use the c allocator; in practice that means we test less (because the rust allocator was also dropped).

Why make that change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this example is not really practical, it's just for demonstration and testing purposes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add back a -DNO_STD C example, but with this PR the cdylib will always be compiled with #![no_std], which implies that we always have to use the C allocator as the Rust allocator is part of libstd. There is no benefit to building the cdylib with std. It only adds extra work and increases the size of the dylib.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well the NO_STD flag is maybe misnamed then, but I'd like to test the use of custom allocators.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added back testing of the no-stdio mode.

@bjorn3 bjorn3 mentioned this pull request Dec 3, 2024
@folkertdev folkertdev merged commit d4f1fcc into main Dec 3, 2024
15 of 16 checks passed
@folkertdev folkertdev deleted the no_std_cdylib branch December 3, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants