Skip to content

Commit

Permalink
printer: make compilation on non-unix, non-windows platforms work
Browse files Browse the repository at this point in the history
Some of the new hyperlink work caused ripgrep to stop compiling
on non-{Unix,Windows} platforms. The most popular of which is WASI.

This commit makes non-{Unix,Windows} compile again. And we add a
very basic WASI test in CI to catch regressions.

More work is needed to make tests on non-{Unix,Windows} platforms
work. And of course, this commit specifically takes the path of disabling
hyperlink support for non-{Unix,Windows} platforms.
  • Loading branch information
holzschu committed Apr 23, 2024
1 parent 02b47b7 commit bb8601b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -189,6 +189,21 @@ jobs:
shell: bash
run: ${{ env.CARGO }} test --bin rg ${{ env.TARGET_FLAGS }} flags::defs::tests::available_shorts -- --nocapture

# Setup and compile on the wasm32-wasi target
wasm:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi
- name: Basic build
run: cargo build --verbose

rustfmt:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/hostname.rs
Expand Up @@ -25,10 +25,10 @@ pub fn hostname() -> io::Result<OsString> {
}
#[cfg(not(any(windows, unix)))]
{
io::Error::new(
Err(io::Error::new(
io::ErrorKind::Other,
"hostname could not be found on unsupported platform",
)
))
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/printer/src/hyperlink.rs
Expand Up @@ -811,6 +811,13 @@ impl HyperlinkPath {
Some(HyperlinkPath::encode(with_slash.as_bytes()))
}

/// For other platforms (not windows, not unix), return None and log a debug message.
#[cfg(not(any(windows, unix)))]
pub(crate) fn from_path(original_path: &Path) -> Option<HyperlinkPath> {
log::debug!("hyperlinks are not supported on this platform");
None
}

/// Percent-encodes a path.
///
/// The alphanumeric ASCII characters and "-", ".", "_", "~" are unreserved
Expand Down

0 comments on commit bb8601b

Please sign in to comment.