Skip to content

Commit 7c0fe3f

Browse files
authored
Merge pull request #112 from martinling/windows-installer
Build Windows installer using cargo-wix
2 parents dffa1bd + 0b4a328 commit 7c0fe3f

22 files changed

Lines changed: 828 additions & 27 deletions

.github/workflows/rust.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ jobs:
6868
run: brew install gtk4 pkg-config
6969
if: matrix.os == 'macos-latest'
7070

71+
- name: Install cargo-wix (Windows)
72+
uses: taiki-e/cache-cargo-install-action@v2
73+
with:
74+
tool: cargo-wix
75+
if: matrix.os == 'windows-latest'
76+
77+
- name: Install cargo-license (Windows)
78+
uses: taiki-e/cache-cargo-install-action@v2
79+
with:
80+
tool: cargo-license
81+
if: matrix.os == 'windows-latest'
82+
7183
- name: Install dependencies (Windows)
7284
uses: lukka/run-vcpkg@v11
7385
with:
@@ -99,10 +111,41 @@ jobs:
99111
with:
100112
run: cargo test
101113

102-
- uses: actions/upload-artifact@v2
114+
- name: Compile glib schemas (Windows)
115+
run: |
116+
& "$env:VCPKG_INSTALLED_DIR/x64-windows/tools/glib/glib-compile-schemas.exe" "$env:VCPKG_INSTALLED_DIR/x64-windows/share/glib-2.0/schemas"
117+
if: matrix.os == 'windows-latest'
118+
119+
- name: Gather licenses (Windows)
120+
run: |
121+
pip install license-expression
122+
python wix/rust_licenses.py > wix/LICENSE-static-libraries.txt
123+
python wix/vcpkg_licenses.py > wix/LICENSE-dynamic-libraries.txt
124+
if: matrix.os == 'windows-latest'
125+
126+
- name: Generate components (Windows)
127+
run: |
128+
python wix/generate_components.py
129+
if: matrix.os == 'windows-latest'
130+
131+
- name: Build installer (Windows)
132+
run: cargo wix --no-build --nocapture -v
133+
if: matrix.os == 'windows-latest'
134+
135+
- name: Upload binary
136+
uses: actions/upload-artifact@v2
103137
with:
104-
name: Packetry ${{ matrix.os }}
138+
name: Binary for ${{ matrix.os }}
105139
path: |
106140
target/release/packetry
107141
target/release/packetry.exe
142+
if-no-files-found: error
108143

144+
- name: Upload installer (Windows)
145+
uses: actions/upload-artifact@v2
146+
with:
147+
name: Windows installer
148+
path: |
149+
target/wix/*.msi
150+
if-no-files-found: error
151+
if: runner.os == 'Windows'

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
/target
22
/tests/*/output.txt
33
/tests/ui/*/output.txt
4+
/wix/full-licenses
5+
/wix/dll-components.wxi
6+
/wix/dll-references.wxi
7+
/wix/license-components.wxi
8+
/wix/license-references.wxi
9+
/wix/LICENSE-packetry.txt
10+
/wix/LICENSE-static-libraries.txt
11+
/wix/LICENSE-dynamic-libraries.txt
12+
/vcpkg

Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ include = [
2424
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2525

2626
[dependencies]
27-
bufreaderwriter = "0.2.4"
2827
bytemuck = "1.14.1"
2928
bytemuck_derive = "1.5.0"
3029
gtk = { version = "0.8.0", package = "gtk4" }
@@ -35,7 +34,6 @@ tempfile = "3.9.0"
3534
bitfield = "0.14.0"
3635
num-format = "0.4.4"
3736
humansize = "2.1.3"
38-
bisection = "0.1.0"
3937
derive_more = "0.99.17"
4038
nusb = "0.1.9"
4139
futures-lite = "2.0.1"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2022, Great Scott Gadgets
3+
Copyright (c) 2022-2024, Great Scott Gadgets
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

src/backend/cynthion.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl CynthionQueue {
416416
async fn process(&mut self, mut stop: oneshot::Receiver<()>)
417417
-> Result<(), Error>
418418
{
419-
use TransferError::Cancelled;
419+
use TransferError::{Cancelled, Unknown};
420420
loop {
421421
select_biased!(
422422
_ = stop => {
@@ -434,7 +434,13 @@ impl CynthionQueue {
434434
self.queue.submit(RequestBuffer::new(READ_LEN));
435435
}
436436
},
437-
Err(Cancelled) if stop.is_terminated() => {
437+
//
438+
// As of nusb 0.1.9, TransferError::Unknown may be
439+
// returned instead of TransferError::Cancelled when
440+
// Windows returns ERROR_OPERATION_ABORTED. This should
441+
// be fixed in a future nusb release; see nusb PR #63.
442+
//
443+
Err(Cancelled | Unknown) if stop.is_terminated() => {
438444
// Transfer cancelled during shutdown. Drop it.
439445
drop(completion);
440446
if self.queue.pending() == 0 {

src/compact_index.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::sync::atomic::{AtomicU64, Ordering::{Acquire, Release}};
77
use std::sync::Arc;
88

99
use anyhow::{Error, bail};
10-
use bisection::bisect_left;
1110
use itertools::multizip;
1211

1312
use crate::data_stream::{data_stream, DataReader, DataWriter};
@@ -382,8 +381,17 @@ where
382381
values.push(base_value + delta);
383382
}
384383
// Bisect the values to find the position.
385-
let offset = bisect_left(&values, value) as u64;
386-
let position = delta_range.start + offset;
384+
let mut lower_bound = 0;
385+
let mut upper_bound = values.len();
386+
while lower_bound < upper_bound {
387+
let midpoint = (lower_bound + upper_bound) / 2;
388+
if &values[midpoint] < value {
389+
lower_bound = midpoint + 1;
390+
} else {
391+
upper_bound = midpoint;
392+
}
393+
}
394+
let position = delta_range.start + lower_bound as u64;
387395
Ok(position)
388396
}
389397
}

src/index_stream.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::marker::PhantomData;
33
use std::ops::Range;
44

55
use anyhow::Error;
6-
use bisection::{bisect_left, bisect_right};
76

87
use crate::data_stream::{data_stream, DataReader, DataWriter};
98
use crate::id::Id;
@@ -173,7 +172,17 @@ where Position: Copy + From<u64> + Into<u64>,
173172
midpoint = (block_end + search_end) / 2
174173
}
175174
} else {
176-
break block_start + bisect_left(&block_values, &value) as u64;
175+
let mut lower_bound = 0;
176+
let mut upper_bound = block_values.len();
177+
while lower_bound < upper_bound {
178+
let midpoint = (lower_bound + upper_bound) / 2;
179+
if block_values[midpoint] < value {
180+
lower_bound = midpoint + 1;
181+
} else {
182+
upper_bound = midpoint;
183+
}
184+
}
185+
break block_start + lower_bound as u64;
177186
};
178187
};
179188
Ok(Position::from(position))
@@ -217,7 +226,17 @@ where Position: Copy + From<u64> + Into<u64>,
217226
midpoint = block_end + length_after / 2;
218227
}
219228
} else {
220-
break block_start + bisect_right(&block_values, &value) as u64;
229+
let mut lower_bound = 0;
230+
let mut upper_bound = block_values.len();
231+
while lower_bound < upper_bound {
232+
let midpoint = (lower_bound + upper_bound) / 2;
233+
if value < block_values[midpoint] {
234+
upper_bound = midpoint;
235+
} else {
236+
lower_bound = midpoint + 1;
237+
}
238+
}
239+
break block_start + lower_bound as u64;
221240
};
222241
};
223242
Ok(Position::from(position))

wix/generate_components.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from contextlib import redirect_stdout
2+
import os
3+
4+
dll_components = open('wix/dll-components.wxi', 'w')
5+
dll_references = open('wix/dll-references.wxi', 'w')
6+
license_components = open('wix/license-components.wxi', 'w')
7+
license_references = open('wix/license-references.wxi', 'w')
8+
9+
output_files = [
10+
dll_components,
11+
dll_references,
12+
license_components,
13+
license_references
14+
]
15+
16+
def component_name(filename):
17+
return filename.replace('-', '_').replace('+', '_')
18+
19+
for file in output_files:
20+
print("<Include>", file=file)
21+
22+
bin_dir = '$(env.VCPKG_INSTALLED_DIR)/x64-windows/bin'
23+
24+
for line in open('wix/required-dlls.txt', 'r'):
25+
filename, guid = line.rstrip().split(' ')
26+
component = component_name(filename)
27+
with redirect_stdout(dll_components):
28+
print(f" <Component Id='{component}' Guid='{guid}'>")
29+
print(f" <File Id='{component}'")
30+
print(f" Name='{filename}'")
31+
print(f" DiskId='1'")
32+
print(f" Source='{bin_dir}/{filename}'/>")
33+
print(f" </Component>")
34+
with redirect_stdout(dll_references):
35+
print(f" <ComponentRef Id='{component}'/>")
36+
37+
for filename in os.listdir('wix/full-licenses'):
38+
component = component_name(filename)
39+
with redirect_stdout(license_components):
40+
print(f" <Component Id='{component}' Guid='*'>")
41+
print(f" <File Id='{component}'")
42+
print(f" Name='{filename}'")
43+
print(f" DiskId='1'")
44+
print(f" Source='wix/full-licenses/{filename}'/>")
45+
print(f" </Component>")
46+
with redirect_stdout(license_references):
47+
print(f" <ComponentRef Id='{component}'/>")
48+
49+
for file in output_files:
50+
print("</Include>", file=file)

0 commit comments

Comments
 (0)