Skip to content

Commit

Permalink
use the correct target-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Jan 15, 2024
1 parent 79fc6b6 commit a33f654
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 24 deletions.
18 changes: 9 additions & 9 deletions docs/experimental_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ Jinja functions
### `load_from_file(<file_path>)`

The jinja function `load_from_file` allows loading from files, specifically, it allows loading from `toml`, `json`
and `yaml` to an object to allow to fetch things directly from it.
and `yaml` to an object to allow to fetch things directly from it.
While it loads all other files as strings.

#### Usage
#### Usage

This is useful when you have the project description in a well defined project file, such as, `Cargo.toml`, `package.json`, `pyproject.toml`, `package.yaml`, or `stack.yaml`. And would like to keep the recipe as simple as possible, while not worrying about keeping changes in sync, perhaps using it with CI/CD.

Or, from some other source that provides a well-defined output format.
Or, from some other source that provides a well-defined output format.

Example against `Cargo.toml` inside `rattler-build` github repository:

``` yaml title="recipe.yaml"
context:
name: ${{ load_from_file("Cargo.toml").package.name }}
name: ${{ load_from_file("Cargo.toml").package.name }}
version: ${{ load_from_file("Cargo.toml").package.version }}
source_url: ${{ load_from_file("Cargo.toml").package.homepage }}
rust_toolchain: ${{ load_from_file("rust-toolchains") }}
Expand All @@ -55,8 +55,8 @@ test:
about:
home: ${{ source_url }}
repository: ${{ source_url }}
documentation: ${{ load_from_file("Cargo.toml").package.documentation }}
summary: ${{ load_from_file("Cargo.toml").package.description }}
documentation: ${{ load_from_file("Cargo.toml").package.documentation }}
summary: ${{ load_from_file("Cargo.toml").package.description }}
license: ${{ load_from_file("Cargo.toml").package.license }}
```
Expand All @@ -75,7 +75,7 @@ from the git repository.
git.latest_tag_rev(<git_repo_url>)
# latest commit revision(aka, hash of head commit) in the repo
git.head_rev(<git_repo_url>)
git.head_rev(<git_repo_url>)
```

#### Usage
Expand All @@ -90,12 +90,12 @@ context:
package:
name: "rattler-build"
version: ${{ latest_tag }}
version: ${{ latest_tag }}
source:
git: ${{ git_repo_url }}
tag: ${{ latest_tag }}
```

Though it's important to understand currently we don't guarantee caching for repo fetch for git functions
this may lead to some performance issues.
this may lead to some performance issues.
6 changes: 3 additions & 3 deletions docs/recipe_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ scripts for different platforms.

```yaml
build:
script:
script:
python setup.py install --single-version-externally-managed --record=record.txt
```

Expand Down Expand Up @@ -496,7 +496,7 @@ requirements:
- python
```

!!! note
!!! note
When both build and host sections are defined, the build section can
be thought of as "build tools" - things that run on the native platform, but output results for the target platform.
For example, a cross-compiler that runs on linux-64, but targets linux-armv7.
Expand Down Expand Up @@ -1141,7 +1141,7 @@ tests:
Experimental features
---------------------

!!! warning
!!! warning
These are experimental features of `rattler-build` and may change or go away completely.

### Jinja functions
Expand Down
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub async fn run_build(
&result,
&TestConfiguration {
test_prefix: test_dir.clone(),
target_platform: Some(output.build_configuration.target_platform),
target_platform: Some(output.build_configuration.host_platform),
keep_test_prefix: tool_configuration.no_clean,
channels,
tool_configuration: tool_configuration.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/package_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ async fn run_shell_test(
format!("{}={}={}", pkg.name, pkg.version, pkg.build_string).as_str(),
)?);

let platform = Platform::current();
let platform = config.target_platform.unwrap_or_else(Platform::current);

create_environment(
&dependencies,
Expand Down
8 changes: 4 additions & 4 deletions src/recipe/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ mod tests {
fn git_setup(path: &Path) -> anyhow::Result<()> {
let git_config = r#"
[user]
name = John Doe
name = John Doe
email = [email protected]
"#;
std::fs::write(path.join(".git/config"), git_config)?;
Expand Down Expand Up @@ -686,23 +686,23 @@ mod tests {
assert_eq!(
jinja.eval(&format!("load_from_file('{}')['hello']", path_str)).expect("test 1").as_str(),
Some("world"),
);
);

let path = temp_dir.path().join("test.yaml");
std::fs::write(&path, "hello: world").unwrap();
let path_str = to_forward_slash_lossy(&path);
assert_eq!(
jinja.eval(&format!("load_from_file('{}')['hello']", path_str)).expect("test 2").as_str(),
Some("world"),
);
);

let path = temp_dir.path().join("test.toml");
let path_str = to_forward_slash_lossy(&path);
std::fs::write(&path, "hello = 'world'").unwrap();
assert_eq!(
jinja.eval(&format!("load_from_file('{}')['hello']", path_str)).expect("test 2").as_str(),
Some("world"),
);
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion test-data/recipes/correct-sha/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ source:
build:
number: 0
script:
- echo "Hello world!"
- echo "Hello world!"
4 changes: 2 additions & 2 deletions test-data/recipes/run_exports/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package:

requirements:
host:
- zlib
- zlib
run_exports:
- ${{ pin_subpackage("run_exports_test", exact=True) }}
# avoid adding libzlib
ignore_run_exports:
by_name:
- libzlib
- libzlib
4 changes: 2 additions & 2 deletions test-data/recipes/run_exports_from/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package:

requirements:
host:
- zlib
- zlib
run_exports:
- ${{ pin_subpackage("run_exports_test", exact=True) }}
# avoid from package
ignore_run_exports:
from_package:
- zlib
- zlib
24 changes: 23 additions & 1 deletion test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ def build(
output_folder: Path,
variant_config: Optional[Path] = None,
custom_channels: list[str] | None = None,
extra_args: list[str] = None,
):
args = ["build", "--recipe", str(recipe_folder)]
if extra_args is None:
extra_args = []
args = ["build", "--recipe", str(recipe_folder), *extra_args]
if variant_config is not None:
args += ["--variant-config", str(variant_config)]
args += ["--output-dir", str(output_folder)]
Expand Down Expand Up @@ -275,3 +278,22 @@ def test_anaconda_upload(
)

assert requests.get(URL).status_code == 200


@pytest.mark.skipif(
os.name == "nt", reason="recipe does not support execution on windows"
)
def test_cross_testing(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, monkeypatch
) -> None:
native_platform = host_subdir()
if native_platform.startswith("linux"):
target_platform = "osx-64"
elif native_platform.startswith("osx"):
target_platform = "linux-64"

rattler_build.build(
recipes / "test-execution/recipe-test-succeed.yaml",
tmp_path,
extra_args=["--target-platform", target_platform],
)

0 comments on commit a33f654

Please sign in to comment.