Skip to content
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
20 changes: 11 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test

on: [pull_request]
on: [push, pull_request]

env:
CARGO_TERM_COLOR: always
Expand All @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04 ]
os: [ ubuntu-24.04, macos-15-intel ]
feature: [ "4_1_5", "4_5_4", "4_6_2", "4_7_0" ]

steps:
Expand All @@ -23,25 +23,27 @@ jobs:
- uses: Swatinem/rust-cache@v1.2.0
with:
key: ${{ matrix.feature }}${{ matrix.os }}
if: ${{ matrix.os != 'macos-10.15' }} # issue with hard-links on mac
if: ${{ matrix.os != 'macos-15-intel' }} # issue with hard-links on mac
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- run: echo "TEMPDIR_ROOT=/dev/shm" >> $GITHUB_ENV
if: ${{ matrix.os != 'macos-10.15' }}
- run: |
echo "TEMPDIR_ROOT=/dev/shm" >> $GITHUB_ENV
echo "APPIMAGE_EXTRACT_AND_RUN=1" >> $GITHUB_ENV
if: ${{ matrix.os != 'macos-15-intel' }}
- uses: actions-rs/cargo@v1
with:
command: test
args: --features ${{ matrix.feature }}
- run: echo "ELECTRUMD_EXE=$(find ./target/debug -name electrum.AppImage)" >> $GITHUB_ENV
- run: echo "ELECTRUMD_EXE=$(find ./target/debug \( -name electrum.AppImage -o -name run_electrum \))" >> $GITHUB_ENV
- uses: actions-rs/cargo@v1
with:
command: test


cosmetics:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1.2.0
Expand All @@ -57,11 +59,11 @@ jobs:
run: cargo clippy -- -D warnings

rust-version:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
toolchain: [ "1.70", "stable", "nightly" ]
toolchain: [ "1.88", "stable", "nightly" ]

steps:
- uses: actions/checkout@v2
Expand Down
89 changes: 83 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ use std::fs;
use std::io::Read;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
#[cfg(target_os = "macos")]
use std::path::PathBuf;
use std::str::FromStr;

include!("src/versions.rs");

#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
fn download_filename() -> String {
format!("electrum-{}-x86_64.AppImage", &VERSION)
format!("electrum-{}-x86_64.AppImage", VERSION)
}

#[cfg(target_os = "macos")]
fn download_filename() -> String {
format!("electrum-{}.dmg", &VERSION)
Comment on lines +17 to +19
}
// other platforms are currently unsupported

fn get_expected_sha256() -> Result<sha256::Hash, ()> {
let sha256sum_filename = format!("sha256/electrum-{}-SHA256SUM", &VERSION);
fn get_expected_sha256(download_filename: &str) -> Result<sha256::Hash, ()> {
let sha256sum_filename = format!("sha256/{}-SHA256SUM", download_filename);
let contents = fs::read_to_string(sha256sum_filename).expect("SHA256SUM file to exists");
let hash = sha256::Hash::from_str(&contents).expect("SHA256SUM file to be valid");
Ok(hash)
Expand All @@ -25,15 +32,16 @@ fn main() {
return;
}
let download_filename = download_filename();
let expected_hash = get_expected_sha256().unwrap();
let expected_hash = get_expected_sha256(&download_filename).unwrap();
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let download_dir = Path::new(&out_dir)
.join("electrum")
.join(format!("electrum-{}", VERSION));
if !download_dir.exists() {
fs::create_dir_all(&download_dir).unwrap();
}
let filepath = download_dir.join("electrum.AppImage");

let filepath = download_dir.join(EXE_REL_PATH);

if !filepath.exists() {
println!(
Expand All @@ -55,11 +63,80 @@ fn main() {

let downloaded_hash = sha256::Hash::hash(&downloaded_bytes);
assert_eq!(expected_hash, downloaded_hash);
fs::write(&filepath, downloaded_bytes).unwrap();

#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
{
fs::write(&filepath, downloaded_bytes).unwrap();
}

#[cfg(target_os = "macos")]
{
let dmg_path = download_dir.join("electrum.dmg");
let mount_point = download_dir.join("mounted-dmg");
fs::write(&dmg_path, &downloaded_bytes).unwrap();
fs::create_dir_all(&mount_point).unwrap();

// Mount the DMG (use -nobrowse to keep it out of Finder)
let output = std::process::Command::new("hdiutil")
.arg("attach")
.arg(&dmg_path)
.arg("-mountpoint")
.arg(&mount_point)
.arg("-nobrowse")
.output()
.expect("failed to run hdiutil attach");
assert!(
output.status.success(),
"hdiutil attach failed: {}",
String::from_utf8_lossy(&output.stderr)
);
let mounted_dmg = MountedDmg(mount_point);

// Copy the entire Electrum.app bundle out of the DMG
let app_dest = download_dir.join("Electrum.app");
let app_src = mounted_dmg.0.join("Electrum.app");
let cp_output = std::process::Command::new("cp")
.args(["-R", app_src.to_str().unwrap(), app_dest.to_str().unwrap()])
.output()
.expect("failed to copy Electrum.app");
assert!(
cp_output.status.success(),
"cp -R failed: {}",
String::from_utf8_lossy(&cp_output.stderr)
);
Comment on lines +96 to +106

drop(mounted_dmg);

// Clean up the DMG file
let _ = fs::remove_file(&dmg_path);
}

// chmod +x
let mut perms = fs::metadata(&filepath).unwrap().permissions();
perms.set_mode(0o744);
fs::set_permissions(&filepath, perms).unwrap();
}
}

#[cfg(target_os = "macos")]
struct MountedDmg(PathBuf);

#[cfg(target_os = "macos")]
impl Drop for MountedDmg {
fn drop(&mut self) {
match std::process::Command::new("hdiutil")
.arg("detach")
.arg(&self.0)
.output()
{
Ok(output) if output.status.success() => {
let _ = fs::remove_dir(&self.0);
}
Ok(output) => eprintln!(
"hdiutil detach failed during cleanup: {}",
String::from_utf8_lossy(&output.stderr)
),
Err(error) => eprintln!("failed to run hdiutil detach during cleanup: {}", error),
}
}
}
1 change: 1 addition & 0 deletions sha256/electrum-4.1.5.dmg-SHA256SUM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cbc98ceb3aad57e2d48ed7418d2952d0bd283749e0d27a0d3a37b959d31ac8d0
1 change: 1 addition & 0 deletions sha256/electrum-4.5.4.dmg-SHA256SUM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
767ec1917600f90d70645eb110e82b3912a89532006362bf8174dc5f0b9400d6
1 change: 1 addition & 0 deletions sha256/electrum-4.6.2.dmg-SHA256SUM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c0cb271e9de5915d3bff740385efc6676cc802977a8218bbb3a5a83152d159fc
1 change: 1 addition & 0 deletions sha256/electrum-4.7.0.dmg-SHA256SUM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7f7923abf8cac06ee33bc6f5c7c8aa2593cf211f098243dbd680aab45064fdc9
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ pub fn downloaded_exe_path() -> Result<String, Error> {
Err(Error::NoFeature)
} else {
Ok(format!(
"{}/electrum/electrum-{}/electrum.AppImage",
"{}/electrum/electrum-{}/{}",
env!("OUT_DIR"),
versions::VERSION
versions::VERSION,
versions::EXE_REL_PATH
))
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/versions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
pub const HAS_FEATURE: bool = cfg!(any(feature = "4_1_5", feature = "4_5_4", feature = "4_6_2", feature = "4_7_0"));
pub const HAS_FEATURE: bool = cfg!(any(
feature = "4_1_5",
feature = "4_5_4",
feature = "4_6_2",
feature = "4_7_0"
));

#[cfg(not(any(feature = "4_1_5", feature = "4_5_4", feature = "4_6_2", feature = "4_7_0")))]
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
pub const EXE_REL_PATH: &str = "electrum.AppImage";

#[cfg(target_os = "macos")]
pub const EXE_REL_PATH: &str = "Electrum.app/Contents/MacOS/run_electrum";
Comment on lines +11 to +12

#[cfg(not(any(
feature = "4_1_5",
feature = "4_5_4",
feature = "4_6_2",
feature = "4_7_0"
)))]
pub const VERSION: &str = "N/A";

#[cfg(feature = "4_1_5")]
Expand Down
Loading