Skip to content
Open
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
20 changes: 15 additions & 5 deletions crates/rattler_build_jinja/src/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,20 @@ fn default_compiler(platform: Platform, language: &str) -> Option<Variable> {
Some(
match language {
// Platform agnostic compilers
"fortran" => "gfortran",
"fortran" => {
if platform.is_windows() {
"flang"
} else {
"gfortran"
}
}
lang if !["c", "cxx"].contains(&lang) => lang,
// Platform specific compilers
_ => {
if platform.is_windows() {
match language {
"c" => "vs2017",
"cxx" => "vs2017",
"c" => "vs2022",
"cxx" => "vs2022",
_ => unreachable!(),
}
} else if platform.is_osx() {
Expand Down Expand Up @@ -1984,16 +1990,20 @@ mod tests {

let platform = Platform::Win64;
assert_eq!(
"vs2017",
"vs2022",
default_compiler(platform, "cxx").unwrap().to_string()
);
assert_eq!(
"vs2017",
"vs2022",
default_compiler(platform, "c").unwrap().to_string()
);
assert_eq!(
"cuda",
default_compiler(platform, "cuda").unwrap().to_string()
);
assert_eq!(
"flang",
default_compiler(platform, "fortran").unwrap().to_string()
);
}
}
6 changes: 3 additions & 3 deletions docs/reference/jinja.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ full compiler will read `clang_linux-64 9.0` when compiling with
Rattler-Build defines some default compilers for the following languages
(inherited from `conda-build`):

- `c`: `gcc` on Linux, `clang` on `osx` and `vs2017` on Windows
- `cxx`: `gxx` on Linux, `clangxx` on `osx` and `vs2017` on Windows
- `fortran`: `gfortran` on Linux, `gfortran` on `osx` and `vs2017` on Windows
- `c`: `gcc` on Linux, `clang` on `osx` and `vs2022` on Windows
- `cxx`: `gxx` on Linux, `clangxx` on `osx` and `vs2022` on Windows
- `fortran`: `gfortran` on Linux, `gfortran` on `osx` and `flang` on Windows
- `rust`: `rust`

### The `stdlib` function
Expand Down
18 changes: 16 additions & 2 deletions docs/windows_quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ The MinGW C++ and Fortran compilers are **not ABI-compatible** with the default

| Use MinGW when... | Use MSVC when... |
| -------------------------------------------------- | ---------------------------------------------- |
| Porting Unix/Linux software with GCC-specific code | Building native Windows applications |
| Porting Unix/Linux software with GCC-specific code | Building native Windows applications |
| The project uses GNU autotools extensively | Integrating with other MSVC-compiled libraries |
| You need GCC-specific compiler extensions | Maximum compatibility with Windows ecosystem |
| You need GCC-specific compiler extensions | Maximum compatibility with Windows ecosystem |
| Building Fortran code (simpler than Flang setup) | Performance-critical Windows applications |
| Building R packages (requires MingW64) | |

Expand Down Expand Up @@ -195,3 +195,17 @@ The `clang-cl` frontend is particularly useful when:
- The build system expects MSVC-style compiler flags
- You're integrating with existing MSVC-compiled libraries

## Windows PATH length issues

When building on Windows, you may encounter failures caused by the **command line or `PATH` length limit**. This commonly happens in the following situations:

- Activating a **Visual Studio toolchain** (for example `vs2022`) whose activation scripts include `.bat` files such as `vcvars64.bat`.
- Building **Rust crates that contain C or C++ code**, which require the MSVC toolchain during compilation.

In these cases, the activation scripts and compiler environment setup may produce extremely long command lines or `PATH` values, which can exceed the limits of `cmd.exe` or Windows environment handling. This can result in errors such as failed activation, truncated PATH values, or build failures.

To reduce the risk of hitting these limits, keep build paths as **short as possible**. Recommended practices:

- `--output-dir` is short
- `CARGO_TARGET_DIR` is short
- `CARGO_HOME` is short
1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ RUSTC_WRAPPER = "sccache"
# Use cmake to build aws-lc-sys, because conda's CFLAGS inject -O2 which
# overrides the -O0 required by jitterentropy-base.c, causing a build failure.
AWS_LC_SYS_CMAKE_BUILDER = "1"
PYTHONIOENCODING = "utf-8"

[feature.lint.dependencies]
actionlint = ">=1.7.4,<2"
Expand Down
16 changes: 16 additions & 0 deletions test/end-to-end/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import os
import sys
from pathlib import Path

import pytest
from helpers import RattlerBuild
from syrupy.extensions.json import JSONSnapshotExtension


@pytest.fixture
def clean_path_on_win32():
# On Windows, clear path to avoid hitting the cmd.exe
# line-length limit during VS compiler activation (vcvars64.bat).
if sys.platform == "win32":
original_path = os.environ.get("PATH", "")
try:
os.environ["PATH"] = ""
yield
finally:
os.environ["PATH"] = original_path
else:
yield


@pytest.fixture
def rattler_build():
if os.environ.get("RATTLER_BUILD_PATH"):
Expand Down
6 changes: 4 additions & 2 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,9 @@ def test_relink_rpath(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
rattler_build.build(recipes / "test-relink", tmp_path)


def test_ignore_run_exports(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path):
def test_ignore_run_exports(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, clean_path_on_win32
):
rattler_build.build(
recipes / "test-parsing/recipe_ignore_run_exports.yaml",
tmp_path,
Expand All @@ -1869,7 +1871,7 @@ def test_ignore_run_exports(rattler_build: RattlerBuild, recipes: Path, tmp_path
elif current_subdir.startswith("osx"):
expected_compiler = f"clangxx_{current_subdir}"
elif current_subdir.startswith("win"):
expected_compiler = f"vs2017_{current_subdir}"
expected_compiler = f"vs2022_{current_subdir}"
else:
pytest.fail(f"Unsupported platform for compiler check: {current_subdir}")

Expand Down
6 changes: 3 additions & 3 deletions test/end-to-end/test_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_staging_with_variants(


def test_multiple_staging_caches(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, clean_path_on_win32
):
"""Test multiple independent staging outputs in one recipe.

Expand Down Expand Up @@ -327,7 +327,7 @@ def test_multiple_staging_caches(


def test_staging_with_top_level_inherit(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, clean_path_on_win32
):
"""Test mix of staging inheritance and top-level inheritance."""
rattler_build.build(
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_staging_work_dir_cache(


def test_staging_complex_deps(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, clean_path_on_win32
):
"""Test complex dependency scenarios with staging."""
rattler_build.build(
Expand Down