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

Build Windows installer using cargo-wix #112

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 45 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ jobs:
run: brew install gtk4 pkg-config
if: matrix.os == 'macos-latest'

- name: Install cargo-wix (Windows)
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-wix
if: matrix.os == 'windows-latest'

- name: Install cargo-license (Windows)
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-license
if: matrix.os == 'windows-latest'

- name: Install dependencies (Windows)
uses: lukka/run-vcpkg@v11
with:
Expand Down Expand Up @@ -99,10 +111,41 @@ jobs:
with:
run: cargo test

- uses: actions/upload-artifact@v2
- name: Compile glib schemas (Windows)
run: |
& "$env:VCPKG_INSTALLED_DIR/x64-windows/tools/glib/glib-compile-schemas.exe" "$env:VCPKG_INSTALLED_DIR/x64-windows/share/glib-2.0/schemas"
if: matrix.os == 'windows-latest'

- name: Gather licenses (Windows)
run: |
pip install license-expression
python wix/rust_licenses.py > wix/LICENSE-static-libraries.txt
python wix/vcpkg_licenses.py > wix/LICENSE-dynamic-libraries.txt
if: matrix.os == 'windows-latest'

- name: Generate components (Windows)
run: |
python wix/generate_components.py
if: matrix.os == 'windows-latest'

- name: Build installer (Windows)
run: cargo wix --no-build --nocapture -v
if: matrix.os == 'windows-latest'

- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: Packetry ${{ matrix.os }}
name: Binary for ${{ matrix.os }}
path: |
target/release/packetry
target/release/packetry.exe
if-no-files-found: error

- name: Upload installer (Windows)
uses: actions/upload-artifact@v2
with:
name: Windows installer
path: |
target/wix/*.msi
if-no-files-found: error
if: runner.os == 'Windows'
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/target
/tests/*/output.txt
/tests/ui/*/output.txt
/wix/full-licenses
/wix/dll-components.wxi
/wix/dll-references.wxi
/wix/license-components.wxi
/wix/license-references.wxi
/wix/LICENSE-packetry.txt
/wix/LICENSE-static-libraries.txt
/wix/LICENSE-dynamic-libraries.txt
/vcpkg
14 changes: 0 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ include = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bufreaderwriter = "0.2.4"
bytemuck = "1.14.1"
bytemuck_derive = "1.5.0"
gtk = { version = "0.8.0", package = "gtk4" }
Expand All @@ -35,7 +34,6 @@ tempfile = "3.9.0"
bitfield = "0.14.0"
num-format = "0.4.4"
humansize = "2.1.3"
bisection = "0.1.0"
derive_more = "0.99.17"
nusb = "0.1.9"
futures-lite = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, Great Scott Gadgets
Copyright (c) 2022-2024, Great Scott Gadgets
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
10 changes: 8 additions & 2 deletions src/backend/cynthion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl CynthionQueue {
async fn process(&mut self, mut stop: oneshot::Receiver<()>)
-> Result<(), Error>
{
use TransferError::Cancelled;
use TransferError::{Cancelled, Unknown};
loop {
select_biased!(
_ = stop => {
Expand All @@ -434,7 +434,13 @@ impl CynthionQueue {
self.queue.submit(RequestBuffer::new(READ_LEN));
}
},
Err(Cancelled) if stop.is_terminated() => {
//
// As of nusb 0.1.9, TransferError::Unknown may be
// returned instead of TransferError::Cancelled when
// Windows returns ERROR_OPERATION_ABORTED. This should
// be fixed in a future nusb release; see nusb PR #63.
//
Err(Cancelled | Unknown) if stop.is_terminated() => {
// Transfer cancelled during shutdown. Drop it.
drop(completion);
if self.queue.pending() == 0 {
Expand Down
14 changes: 11 additions & 3 deletions src/compact_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::sync::atomic::{AtomicU64, Ordering::{Acquire, Release}};
use std::sync::Arc;

use anyhow::{Error, bail};
use bisection::bisect_left;
use itertools::multizip;

use crate::data_stream::{data_stream, DataReader, DataWriter};
Expand Down Expand Up @@ -382,8 +381,17 @@ where
values.push(base_value + delta);
}
// Bisect the values to find the position.
let offset = bisect_left(&values, value) as u64;
let position = delta_range.start + offset;
let mut lower_bound = 0;
let mut upper_bound = values.len();
while lower_bound < upper_bound {
let midpoint = (lower_bound + upper_bound) / 2;
if &values[midpoint] < value {
lower_bound = midpoint + 1;
} else {
upper_bound = midpoint;
}
}
let position = delta_range.start + lower_bound as u64;
Ok(position)
}
}
Expand Down
25 changes: 22 additions & 3 deletions src/index_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::marker::PhantomData;
use std::ops::Range;

use anyhow::Error;
use bisection::{bisect_left, bisect_right};

use crate::data_stream::{data_stream, DataReader, DataWriter};
use crate::id::Id;
Expand Down Expand Up @@ -173,7 +172,17 @@ where Position: Copy + From<u64> + Into<u64>,
midpoint = (block_end + search_end) / 2
}
} else {
break block_start + bisect_left(&block_values, &value) as u64;
let mut lower_bound = 0;
let mut upper_bound = block_values.len();
while lower_bound < upper_bound {
let midpoint = (lower_bound + upper_bound) / 2;
if block_values[midpoint] < value {
lower_bound = midpoint + 1;
} else {
upper_bound = midpoint;
}
}
break block_start + lower_bound as u64;
};
};
Ok(Position::from(position))
Expand Down Expand Up @@ -217,7 +226,17 @@ where Position: Copy + From<u64> + Into<u64>,
midpoint = block_end + length_after / 2;
}
} else {
break block_start + bisect_right(&block_values, &value) as u64;
let mut lower_bound = 0;
let mut upper_bound = block_values.len();
while lower_bound < upper_bound {
let midpoint = (lower_bound + upper_bound) / 2;
if value < block_values[midpoint] {
upper_bound = midpoint;
} else {
lower_bound = midpoint + 1;
}
}
break block_start + lower_bound as u64;
};
};
Ok(Position::from(position))
Expand Down
50 changes: 50 additions & 0 deletions wix/generate_components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from contextlib import redirect_stdout
import os

dll_components = open('wix/dll-components.wxi', 'w')
dll_references = open('wix/dll-references.wxi', 'w')
license_components = open('wix/license-components.wxi', 'w')
license_references = open('wix/license-references.wxi', 'w')

output_files = [
dll_components,
dll_references,
license_components,
license_references
]

def component_name(filename):
return filename.replace('-', '_').replace('+', '_')

for file in output_files:
print("<Include>", file=file)

bin_dir = '$(env.VCPKG_INSTALLED_DIR)/x64-windows/bin'

for line in open('wix/required-dlls.txt', 'r'):
filename, guid = line.rstrip().split(' ')
component = component_name(filename)
with redirect_stdout(dll_components):
print(f" <Component Id='{component}' Guid='{guid}'>")
print(f" <File Id='{component}'")
print(f" Name='{filename}'")
print(f" DiskId='1'")
print(f" Source='{bin_dir}/{filename}'/>")
print(f" </Component>")
with redirect_stdout(dll_references):
print(f" <ComponentRef Id='{component}'/>")

for filename in os.listdir('wix/full-licenses'):
component = component_name(filename)
with redirect_stdout(license_components):
print(f" <Component Id='{component}' Guid='*'>")
print(f" <File Id='{component}'")
print(f" Name='{filename}'")
print(f" DiskId='1'")
print(f" Source='wix/full-licenses/{filename}'/>")
print(f" </Component>")
with redirect_stdout(license_references):
print(f" <ComponentRef Id='{component}'/>")

for file in output_files:
print("</Include>", file=file)
Loading
Loading