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

refactor!: no_std & no static msvcrt & remove download plugin #26

Merged
merged 8 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[build]
target = "i686-pc-windows-msvc"

[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
10 changes: 0 additions & 10 deletions .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@
}
]
},
"nsis_download": {
"path": "./crates/nsis-download",
"manager": "rust",
"assets": [
{
"path": "target/i686-pc-windows-msvc/release/${ pkg.pkg }.dll",
"name": "${ pkg.pkg }.dll"
}
]
},
"nsis_process": {
"path": "./crates/nsis-process",
"manager": "rust",
Expand Down
7 changes: 7 additions & 0 deletions .changes/no_std.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"nsis_tauri_utils": "minor"
"nsis_semvercompare": "minor"
"nsis_process": "minor"
---

Reduce the DLL size by using `no_std` and without static msvcrt.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
license = "MIT or Apache-2.0"

[workspace.dependencies]
pluginapi = { path = "./crates/pluginapi" }
nsis-plugin-api = { path = "./crates/nsis-plugin-api" }

[workspace.dependencies.windows-sys]
version = "0.52.0"
Expand All @@ -24,8 +24,8 @@ features = [
]

[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = "symbols"
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

A collection of NSIS plugins written in rust.

| Plugin | Description |
|---|---|
| [nsis-download](./crates/nsis-download/) | Download a file from an URL to a path |
| [nsis-process](./crates/nsis-process/) | Find and Kill processes |
| [nsis-semvercompare](./crates/nsis-semvercompare/) | Compare two semantic versions |
| [nsis-tauri-utils](./crates/nsis-tauri-utils/) | A collection of all the above plugins into a single DLL for smaller size |
| Plugin | Description |
| -------------------------------------------------- | ------------------------------------------------------------------------ |
| [nsis-process](./crates/nsis-process/) | Find and Kill processes |
| [nsis-semvercompare](./crates/nsis-semvercompare/) | Compare two semantic versions |
| [nsis-tauri-utils](./crates/nsis-tauri-utils/) | A collection of all the above plugins into a single DLL for smaller size |

## License

Apache-2.0/MIT
Apache-2.0/MIT
16 changes: 0 additions & 16 deletions crates/nsis-download/CHANGELOG.md

This file was deleted.

15 changes: 0 additions & 15 deletions crates/nsis-download/Cargo.toml

This file was deleted.

204 changes: 0 additions & 204 deletions crates/nsis-download/src/lib.rs

This file was deleted.

13 changes: 13 additions & 0 deletions crates/nsis-fn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "nsis-fn"
version = "0.0.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full"] }
48 changes: 48 additions & 0 deletions crates/nsis-fn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use syn::{parse::Parse, parse_macro_input, Ident, ItemFn};

struct NsisFn {
func: ItemFn,
}

impl Parse for NsisFn {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let func: ItemFn = input.parse()?;
Ok(Self { func })
}
}

#[proc_macro_attribute]
pub fn nsis_fn(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
let tokens = parse_macro_input!(tokens as NsisFn);
let NsisFn { func } = tokens;

let ident = func.sig.ident;
let block = func.block;
let attrs = func.attrs;

let new_ident = Ident::new(&format!("__{}", ident.to_string()), Span::call_site());

quote! {
#[inline(always)]
pub unsafe fn #new_ident() -> Result<(), ::nsis_plugin_api::Error> #block

#(#attrs)*
#[no_mangle]
#[allow(non_standard_style)]
pub unsafe extern "C" fn #ident(
hwnd_parent: ::windows_sys::Win32::Foundation::HWND,
string_size: core::ffi::c_int,
variables: *mut ::nsis_plugin_api::wchar_t,
stacktop: *mut *mut ::nsis_plugin_api::stack_t,
) {
::nsis_plugin_api::exdll_init(string_size, variables, stacktop);
if let Err(e) = #new_ident() {
e.push_err();
}
}
}
.into()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "pluginapi"
name = "nsis-plugin-api"
version = "0.0.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
windows-sys = { workspace = true }
nsis-fn = { path = "../nsis-fn" }
Loading
Loading