Skip to content

Commit

Permalink
Merge #39: Add support for compilation to windows
Browse files Browse the repository at this point in the history
Add support for compilation to windows
  • Loading branch information
KolbyML authored Jul 22, 2021
2 parents ea546e5 + 21052ac commit bb8a935
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 6 deletions.
59 changes: 55 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 2.1
orbs:
rust: circleci/rust@1.1.1
win: circleci/windows@2.2.0
jobs:
lint-build-test:
description: |
Expand Down Expand Up @@ -28,10 +29,14 @@ jobs:
- run:
name: Run rustfmt
command: cargo fmt -- --check
- rust/clippy:
# Force a failure on clippy warnings
flags: "-- --deny warnings"
with_cache: false
# Run the sub-commands of the orb jobs separately, since the combined steps for Clippy can be long enough to trigger a timeout (>10min). Building the source is the main contributor.
- run:
name: Install Clippy
command: rustup component add clippy
- run:
name: Run Clippy
command: cargo clippy -- --deny warnings
no_output_timeout: 20m
- rust/build:
release: false
with_cache: false
Expand All @@ -42,7 +47,53 @@ jobs:
paths:
- ~/.cargo
- target
win-build:
description: |
Build the crate for windows.
executor:
name: win/default
shell: powershell.exe
steps:
- checkout
- restore_cache:
keys:
- cargo-{{ checksum "Cargo.lock" }}-v1
- run:
name: Install rustup
command: choco install rustup.install
- run:
name: Install clang
command: choco install llvm
- run:
name: Add target
command: rustup target add x86_64-pc-windows-msvc
- run:
name: Install target toolchain
command: rustup toolchain install stable-x86_64-pc-windows-msvc
# Run the sub-commands of the orb jobs separately, since the combined steps for Clippy can be long enough to trigger a timeout (>10min). Building the source is the main contributor.
- run:
name: Install Clippy
command: rustup component add clippy
- run:
name: Run Clippy
# Remove the first two lines of gitconfig as work around
command: |
(gc ..\.gitconfig | select -Skip 2) | sc ..\.gitconfig
cargo clippy -- --deny warnings
no_output_timeout: 20m
- run:
name: Cargo Build --target x86_64-pc-windows-msvc
command: cargo build --target x86_64-pc-windows-msvc
- run:
name: Cargo Test --target x86_64-pc-windows-msvc
command: cargo test --target x86_64-pc-windows-msvc
- save_cache:
key: cargo-{{ checksum "Cargo.lock" }}-v1
paths:
- ~/.cargo
- target
workflows:
merge-test:
jobs:
- lint-build-test
- win-build
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ eth2_ssz = "0.1.2"
eth2_ssz_derive = "0.1.0"
futures = "0.3.13"
hex = "0.4.3"
interfaces = "0.0.7"
lazy_static = "1.4.0"
log = "0.4.14"
reqwest = { version = "0.11.0", features = ["blocking"] }
Expand All @@ -31,6 +30,14 @@ tokio = {version = "1.8.0", features = ["full"]}
uint = { version = "0.8.5", default-features = false }
validator = { version = "0.13.0", features = ["derive"] }


[target.'cfg(windows)'.dependencies]
ipconfig = "0.2.2"
uds_windows = "1.0.1"

[target.'cfg(unix)'.dependencies]
interfaces = "0.0.7"

[dependencies.discv5]
version = "0.1.0-beta.5"
git = "https://github.com/sigp/discv5"
15 changes: 14 additions & 1 deletion src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use serde_json::{json, Value};
use std::fs;
use std::io::{self, Read, Write};
use std::net::{TcpListener, TcpStream};

#[cfg(unix)]
use std::os::unix;

use std::sync::Mutex;
use std::{panic, process};
use threadpool::ThreadPool;
Expand Down Expand Up @@ -72,13 +75,23 @@ fn set_ipc_cleanup_handlers(ipc_path: &str) {
}));
}

#[cfg(unix)]
fn get_listener_result(ipc_path: &str) -> tokio::io::Result<unix::net::UnixListener> {
unix::net::UnixListener::bind(ipc_path)
}

#[cfg(windows)]
fn get_listener_result(ipc_path: &str) -> tokio::io::Result<uds_windows::UnixListener> {
uds_windows::UnixListener::bind(ipc_path)
}

fn launch_ipc_client(
pool: ThreadPool,
infura_project_id: String,
ipc_path: &str,
portal_tx: UnboundedSender<PortalEndpoint>,
) {
let listener_result = unix::net::UnixListener::bind(ipc_path);
let listener_result = get_listener_result(ipc_path);
let listener = match listener_result {
Ok(listener) => {
set_ipc_cleanup_handlers(ipc_path);
Expand Down
21 changes: 21 additions & 0 deletions src/portalnet/socket.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use log::debug;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};

#[cfg(unix)]
use interfaces::{self, Interface};

#[cfg(windows)]
use ipconfig;

const STUN_SERVER: &str = "143.198.142.185:3478";

/// Ping a STUN server on the public network. This does two things:
Expand All @@ -24,6 +28,7 @@ pub fn default_local_address(port: u16) -> SocketAddr {
SocketAddr::new(ip, port)
}

#[cfg(unix)]
fn find_assigned_ip() -> Option<IpAddr> {
let online_nics = Interface::get_all()
.unwrap_or(vec![])
Expand All @@ -44,3 +49,19 @@ fn find_assigned_ip() -> Option<IpAddr> {
}
None
}

#[cfg(windows)]
fn find_assigned_ip() -> Option<IpAddr> {
let adapters = ipconfig::get_adapters().unwrap_or(vec![]);

for adapter in adapters.iter() {
if adapter.gateways().len() > 0 {
for ip in adapter.ip_addresses().iter() {
if let IpAddr::V4(_) = ip {
return Some(*ip);
}
}
}
}
None
}

0 comments on commit bb8a935

Please sign in to comment.