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

Implement for {Free,Net,Open}BSD and Dragonfly #39

Merged
merged 1 commit into from
Jun 29, 2022
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
33 changes: 33 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,39 @@ jobs:
- run: which wasm-pack || cargo install wasm-pack
- run: wasm-pack test --node

build-cross:
strategy:
matrix:
target: [x86_64-unknown-freebsd, x86_64-unknown-netbsd]
runs-on: ubuntu-latest
name: "Build for ${{ matrix.target }}"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
id: actions-rs
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ matrix.target }}-${{ steps.actions-rs.outputs.rustc_hash }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-${{ steps.actions-rs.outputs.rustc_hash }}-
${{ runner.os }}-${{ matrix.target }}-
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/bin/
target/
- run: which cross || cargo install cross
- run: cross build --target ${{ matrix.target }} --examples

check:
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ mod tz_wasm32;
#[cfg(target_arch = "wasm32")]
use tz_wasm32 as platform;

#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
mod tz_freebsd;
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
use tz_freebsd as platform;

#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
mod tz_netbsd;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
use tz_netbsd as platform;

/// Error types
#[derive(Debug)]
pub enum GetTimezoneError {
Expand Down
7 changes: 7 additions & 0 deletions src/tz_freebsd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
// see https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/19
let mut contents = std::fs::read_to_string("/var/db/zoneinfo")?;
// Trim to the correct length without allocating.
contents.truncate(contents.trim_end().len());
Ok(contents)
}
18 changes: 18 additions & 0 deletions src/tz_netbsd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::fs::read_link;

const PREFIX: &str = "/usr/share/zoneinfo/";

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
// see https://www.cyberciti.biz/faq/openbsd-time-zone-howto/
let mut s = read_link("/etc/localtime")?
.into_os_string()
.into_string()
.map_err(|_| crate::GetTimezoneError::FailedParsingString)?;
if !s.starts_with(PREFIX) {
return Err(crate::GetTimezoneError::FailedParsingString);
}

// Trim to the correct length without allocating.
s.replace_range(..PREFIX.len(), "");
Ok(s)
}