Skip to content

fix(cli/mobile): normalize gradlew CRLF on Windows hosts too - #16017

Merged
Legend-Master merged 11 commits into
tauri-apps:devfrom
k6G52m4Dz75W:fix/gradlew-crlf-normalization-all-platforms
Sep 21, 2026
Merged

Legend-Master merged 11 commits into
tauri-apps:devfrom
k6G52m4Dz75W:fix/gradlew-crlf-normalization-all-platforms

Conversation

@k6G52m4Dz75W

Copy link
Copy Markdown
Contributor

Summary

ensure_gradlew — which rewrites CRLF to LF in the Android gradlew
wrapper — is gated behind #[cfg(unix)], both at the call site in
ensure_init and on the function itself. On Windows hosts the
normalization silently never runs, so a gradlew with CRLF endings
breaks sh ./gradlew invocations from Git-Bash/WSL with
/usr/bin/env: ‘sh\r’: No such file or directory.

This splits the function so the platform-neutral LF rewrite runs on
every host, while the unix exec-bit fix remains gated.

Why this matters

A CRLF gradlew breaks every sh-based invocation. Windows users
cloning a project whose committed gradlew carries CRLF (or checking
out with core.autocrlf=true) hit this on the first
tauri android build. The normalization is cheap, platform-neutral,
and the function already existed — it just never ran off-unix.

Changes

  • removed the #[cfg(unix)] gate on the ensure_gradlew call site so
    the CRLF rewrite runs on all hosts;
  • moved the unix-only exec-bit fix inside the function body, gated with
    #[cfg(unix)] (exec bits are a unix permission concept);
  • the LF rewrite itself is unchanged.

Verification

On a Windows host:

  • placed a CRLF gradlew in a project's gen/android, ran
    tauri android build, and confirmed the file was rewritten to LF
    during ensure_init;
  • the subsequent Android build proceeded normally.

PS

Adds a change file under .changes as per the contribution guidelines.

ensure_gradlew was gated behind #[cfg(unix)], so the CRLF-to-LF
normalization only ran on unix hosts. The CRLF rewrite itself is
platform-neutral: a CRLF gradlew breaks sh ./gradlew on every host,
including Git-Bash on Windows.

Split the function so the unix-only exec-bit fix stays gated while the
LF rewrite runs everywhere. This unblocks Windows hosts that previously
failed at the gradlew invocation with
"'gradlew' is not recognized as an internal or external command" when
gradlew carried CRLF endings.
OCR review: the unconditional rewrite churned the file's mtime on
every tauri android dev/build even when it was already LF, and could
fail on read-only or AV-locked files. Gate the write on the CRLF
check.
Hoist gradlew_path above the cfg(unix) block and downgrade CRLF
normalization failures to warnings: on Windows the CLI invokes
gradlew.bat, so a locked or read-only gradlew must not abort builds
that would otherwise succeed. Read failures are logged at debug level.
@k6G52m4Dz75W
k6G52m4Dz75W requested a review from a team as a code owner September 14, 2026 03:58
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Package Changes Through 6f227cb

There are 14 changes which include tauri-cli with minor, @tauri-apps/cli with minor, tauri with minor, tauri-build with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, @tauri-apps/api with minor, tauri-bundler with minor, tauri-macos-sign with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.11.1 2.12.0
tauri-utils 2.9.3 2.10.0
tauri-macos-sign 2.3.4 2.4.0
tauri-bundler 2.9.4 2.10.0
tauri-runtime 2.11.3 2.12.0
tauri-runtime-wry 2.11.4 2.12.0
tauri-codegen 2.6.3 2.7.0
tauri-macros 2.6.3 2.7.0
tauri-plugin 2.6.3 2.7.0
tauri-build 2.6.3 2.7.0
tauri 2.11.5 2.12.0
@tauri-apps/cli 2.11.4 2.12.0
tauri-cli 2.11.4 2.12.0
tauri-driver 2.0.6 2.1.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Legend-Master Legend-Master left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a few nitpicks and we can get this merged.

Comment thread crates/tauri-cli/src/mobile/mod.rs Outdated
Comment on lines 605 to 619
// The CRLF→LF rewrite is platform-neutral: a CRLF gradlew breaks `sh
// ./gradlew` on every host (including Git-Bash on Windows), and bash
// scripts must always use LF. Best effort: only rewrite when a CRLF is
// actually present, and warn instead of failing so a locked or read-only
// file cannot abort builds that would otherwise succeed.
match std::fs::read_to_string(&gradlew_path) {
Ok(contents) => {
if contents.contains("\r\n") {
if let Err(error) = std::fs::write(&gradlew_path, contents.replace("\r\n", "\n")) {
log::warn!("failed to normalize gradlew CRLF line endings: {error}");
}
}
}
Err(error) => log::debug!("failed to read gradlew for CRLF normalization: {error}"),
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve the old fs_context at least on unix platforms.

Comment thread crates/tauri-cli/src/mobile/mod.rs Outdated
Comment on lines +605 to +609
// The CRLF→LF rewrite is platform-neutral: a CRLF gradlew breaks `sh
// ./gradlew` on every host (including Git-Bash on Windows), and bash
// scripts must always use LF. Best effort: only rewrite when a CRLF is
// actually present, and warn instead of failing so a locked or read-only
// file cannot abort builds that would otherwise succeed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove LLM marks, just say why do it on all platforms, and link this PR.

On unix a gradlew that cannot be rewritten will fail the build anyway
with a cryptic sh error, so restore the previous fs_context errors
there; on Windows the CLI invokes gradlew.bat, so failures only warn.
Also reword the comment to plainly state why the rewrite runs on all
platforms and reference this PR.
@k6G52m4Dz75W

Copy link
Copy Markdown
Contributor Author

Both addressed in adaa8b2: unix failures now propagate with the original fs_context messages again (only Windows warns, since the CLI invokes gradlew.bat there), and the comment now plainly states why the rewrite runs on all platforms with a link back to this PR.

@Legend-Master
Legend-Master merged commit 5d995ed into tauri-apps:dev Sep 21, 2026
20 checks passed
@k6G52m4Dz75W
k6G52m4Dz75W deleted the fix/gradlew-crlf-normalization-all-platforms branch September 22, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants