diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8f25dab..20ee66b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,9 @@ name: build on: [push] +env: + CARGO_TERM_COLOR: always + jobs: build_mac: runs-on: macos-latest @@ -26,3 +29,18 @@ jobs: with: name: windows path: target/release/display_switch.exe + + build_linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install build dependencies + run: sudo apt-get install libudev-dev + - name: Build + run: cargo build --verbose --release + - name: Run tests + run: cargo test --verbose + - uses: actions/upload-artifact@v1 + with: + name: linux + path: target/release/display_switch diff --git a/Cargo.toml b/Cargo.toml index 55cfe40..7e66c21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,12 +22,12 @@ simplelog = "^0.8" ddc = "^0.2" rusb = "^0.6" -[target.'cfg(linux)'.dependencies] +[target.'cfg(target_os = "linux")'.dependencies] ddc-hi = "^0.1" ddc-i2c = "^0.2" nvapi = "^0.1" -[target.'cfg(windows)'.dependencies] +[target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "^0.3", features = ["winuser", "libloaderapi"] } ddc-hi = "^0.1" ddc-winapi = "^0.2" diff --git a/src/configuration.rs b/src/configuration.rs index c9e8322..c09a763 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -38,27 +38,29 @@ impl Configuration { } pub fn config_file_name() -> Result { - #[cfg(target_os = "macos")] - let config_dir = dirs::preference_dir().ok_or(anyhow!("Config directory not found"))?; - #[cfg(target_os = "windows")] - let config_dir = dirs::config_dir() - .ok_or(anyhow!("Config directory not found"))? - .join("display-switch"); + let config_dir = if cfg!(target_os = "macos") { + dirs::preference_dir().ok_or(anyhow!("Config directory not found"))? + } else { + dirs::config_dir() + .ok_or(anyhow!("Config directory not found"))? + .join("display-switch") + }; std::fs::create_dir_all(&config_dir)?; Ok(config_dir.join("display-switch.ini")) } pub fn log_file_name() -> Result { - #[cfg(target_os = "macos")] - let log_dir = dirs::home_dir() - .ok_or(anyhow!("Home directory not found"))? - .join("Library") - .join("Logs") - .join("display-switch"); - #[cfg(target_os = "windows")] - let log_dir = dirs::data_local_dir() - .ok_or(anyhow!("Data-local directory not found"))? - .join("display-switch"); + let log_dir = if cfg!(target_os = "macos") { + dirs::home_dir() + .ok_or(anyhow!("Home directory not found"))? + .join("Library") + .join("Logs") + .join("display-switch") + } else { + dirs::data_local_dir() + .ok_or(anyhow!("Data-local directory not found"))? + .join("display-switch") + }; std::fs::create_dir_all(&log_dir)?; Ok(log_dir.join("display-switch.log")) }