Skip to content

Commit bb8601b

Browse files
authored
printer: make compilation on non-unix, non-windows platforms work
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.
1 parent 02b47b7 commit bb8601b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

.github/workflows/ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ jobs:
189189
shell: bash
190190
run: ${{ env.CARGO }} test --bin rg ${{ env.TARGET_FLAGS }} flags::defs::tests::available_shorts -- --nocapture
191191

192+
# Setup and compile on the wasm32-wasi target
193+
wasm:
194+
runs-on: ubuntu-latest
195+
steps:
196+
- name: Checkout repository
197+
uses: actions/checkout@v4
198+
- name: Install Rust
199+
uses: dtolnay/rust-toolchain@master
200+
with:
201+
toolchain: stable
202+
- name: Add wasm32-wasi target
203+
run: rustup target add wasm32-wasi
204+
- name: Basic build
205+
run: cargo build --verbose
206+
192207
rustfmt:
193208
runs-on: ubuntu-latest
194209
steps:

crates/cli/src/hostname.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pub fn hostname() -> io::Result<OsString> {
2525
}
2626
#[cfg(not(any(windows, unix)))]
2727
{
28-
io::Error::new(
28+
Err(io::Error::new(
2929
io::ErrorKind::Other,
3030
"hostname could not be found on unsupported platform",
31-
)
31+
))
3232
}
3333
}
3434

crates/printer/src/hyperlink.rs

+7
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,13 @@ impl HyperlinkPath {
811811
Some(HyperlinkPath::encode(with_slash.as_bytes()))
812812
}
813813

814+
/// For other platforms (not windows, not unix), return None and log a debug message.
815+
#[cfg(not(any(windows, unix)))]
816+
pub(crate) fn from_path(original_path: &Path) -> Option<HyperlinkPath> {
817+
log::debug!("hyperlinks are not supported on this platform");
818+
None
819+
}
820+
814821
/// Percent-encodes a path.
815822
///
816823
/// The alphanumeric ASCII characters and "-", ".", "_", "~" are unreserved

0 commit comments

Comments
 (0)