Repository navigation
Reduce native files size #196
Description
Activity
- changed the title
[-]Reduce native .so files size[/-][+]Reduce native files size[/+]on Jul 23, 2025 I'd be happy to add anything to reduce the file size - got any concrete ideas in mind?
Notice that the current default
--configurationis "Debug" and you'll likely get a smaller binary if you pass--configuration Releaseto ferric.I know that there are also possibilities of shaving off size with link-time optimization (LTO) when building the final app.
I suggested the repo which already should contain all the possible ways. Whichever you choose and works.
Maybe leave
Releaseas default?Reacted by Kræn Hansen> ferric build --configuration release ╭─────────────────────────╮ │░█▀▀░█▀▀░█▀▄░█▀▄░▀█▀░█▀▀░│ │░█▀▀░█▀▀░█▀▄░█▀▄░░█░░█░░░│ │░▀░░░▀▀▀░▀░▀░▀░▀░▀▀▀░▀▀▀░│ ╰─────────────────────────╯ ℹ Using default targets, pass --android, --apple or individual --target options, to avoid this. Using cargo 1.88.0 (873a06493 2025-05-10) ✖ Failed to build: Expected /react-native-node-api/packages/ferric-example/target/x86_64-linux-android/release to existCould be that the bug is that you are passing
releaseand not--releasetocargo build, so it's only generating the debug folder.❯ ll target/x86_64-linux-android/ Octal Permissions Links Size User Group Date Modified Git Name 0755 drwxr-xr-x 1 - user user 24 jul 12:40 -I debug/ 0644 .rw-r--r-- 1 177 user user 24 jul 12:40 -I CACHEDIR.TAGIt seems encapsulated, perhaps if you had a flag to show all the actual commands being run in the background, through logging.
Also add a
.toLowerCase()because,Releasedo not work.Various common tricks for reducing binary size include these Cargo build settings:
[profile.release] lto = true strip = "symbols" opt-level = "z" codegen-units = 1 panic = "abort"
With those settings, I was able to get a Hello World Node-API module down to 304 KB for iOS or macOS (can't remember). Can't be sure what size that might mean for Android, however.
Reacted by Douglas GaldinoI checked, for android, it was reduced to ~330kb.
In
packages/ferric-example- Run
npm run build - Run
cargo build --release - Run
mv target/release target/x86_64-linux-android/ - Run
npm run buildif the script has--configuration release
Reacted by Jamie Birch- Run
Maybe
ferric-exampleshouldnotexist. But be generated by theferric-cli, that wayCargo.tomland other files could be better managed.
Then suggest
npm install --save-dev ferric-cli "scripts": { "generate:project": "ferric generate folder_name", "build": "ferric build folder_name", "build:release": "npm run build --configuration release", },Reacted by Kræn HansenIf I am able to finish this PR, there should be plenty of improvements added.
#200 - List inside.
In the init/generate command, do you prefer that it provide a package.json to be a standalone lib or can it be as the idea I had, you suggest the scripts as in the previous comment, then that package import the lib from the dist/ in the actual project?
In the init/generate command, do you prefer that it provide a package.json to be a standalone lib or can it be as the idea I had, you suggest the scripts as in the previous comment, then that package import the lib from the dist/ in the actual project?
Sorry, not quite clear what you mean. Could you illustrate the two alternatives?
1- Not a standalone package, without a package.json. But, managed by the package.json root of the app. Where the root package as suggested #196 (comment) managed as if it were an additional like android or ios.
project_name │ Cargo.toml │ build.rs │ .gitignore └───src │ │ lib.rs └───dist (after build) │ │ index.js │ │ index.d.ts │ │ native_android_folder │ │ native_ios_folder
2- With a package.json to be a standalone lib.
I took the with second approach. Let me know if you preferred the first.
I think I am done with the PRs, feel free to review them.
I will probably wait for them to maybe get merged and released before using the tool.
I will close this issue as done. Added through one of the PRs.
Hi,
I was testing out
ferric-cli, just with theferric-exampleit seems to generate a big.sofile just for android. In this case it were6.1mb.I suppose this can negatively affect the final build size of RN apps.
Is there a way or if possible, could you add rust flags to the CLI, or whatever that it can be done to help reduce size of the native generated file(s),
.soor otherwise?https://github.com/johnthagen/min-sized-rust
Thanks.