Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host Platform build.rs for Cross Build #214

Merged
merged 11 commits into from Nov 29, 2021
Merged

Conversation

psionic-k
Copy link
Member

@psionic-k psionic-k commented Nov 14, 2021

This PR strips out the localFilters because:

  1. it's useless for independent sources
  2. frequently a source of breakage for users
  3. flakes already respect .gitignore
  4. the more likely use pattern people wanted all along is to filter something out (which can be done during unpack) rather than to select something via regex

I used the static resources example and just built with cargo to get a target dir. Zero effect on the resutls of nix builds. target did not need to be filtered from sources. Flakes 馃コ

So Example 3 is Now Cross-Compiling!

The third example's use of a build.rs script is perfect for debugging the host and build platform offsets. We will fix everything. 馃憡

The cross compiling example with wasi linking can now be compiled on Linux and run with wasmtime

Lets fix....

@psionic-k psionic-k added enhancement New feature or request help wanted Extra attention is needed labels Nov 14, 2021
@psionic-k

This comment has been minimized.

@psionic-k

This comment has been minimized.

@psionic-k
Copy link
Member Author

Latest changes add explicit target configuration.

I think we need to split up the target for selecting a Rust toolchain and the target configuration for the code output, if these are not the same. Judging by the weird vendor targets people brought up elsewhere, I'm convinced that the Rust toolchain selected by one of its targets doesn't always match what code that toolchain will be used to generate. We can mostly handle this for Rust crates without much extra work I expect.

For C deps, there may be more work in the form of providing a linker or some lib without bringing in a whole stdenv.

buildPhase overrides for mkcrate.nix can probably handle any extra changes necessary for outputing code or linking that go beyond merely passing options to rustc

@psionic-k
Copy link
Member Author

psionic-k commented Nov 15, 2021

There's two places we translate between nix platforms & rust triples. /overlay/lib/real-host-triple.nix and /src/platform.rs Both need some maintenance many targets were added.

I'm working on web assembly right now.

List of triples Rust probably comprehends (at least a bit)
our nix mapping (which is moving to /overlay/lib/rust-triple.nix
our Rust mapping from parsed cargo platforms to nix platforms

@psionic-k

This comment has been minimized.

@psionic-k

This comment has been minimized.

@psionic-k
Copy link
Member Author

Evidently there is now a toRustTarget function in nixpkgs https://github.com/oxalica/rust-overlay/search?q=toRustTarget

@psionic-k

This comment has been minimized.

@psionic-k psionic-k force-pushed the host-platform-build-rs branch 2 times, most recently from 036c1ed to 8eb3261 Compare November 19, 2021 09:33
@psionic-k

This comment has been minimized.

@psionic-k

This comment has been minimized.

@psionic-k

This comment has been minimized.

moving static-resources -> cross-compiling

This tests the feature correctness of cross builds

point to nixpkgs master for the wasi build.  Because of an upstream fix to toRustTriple
This stuff was from back when there was some kind of airplain mode.  It would
replace the remote registry with a local registry.  Marginal use if you have the
crate sources in your cache.
This change enables overriding the target for rustc, making it build different
than whatever `crossPlatform` and `platform` would otherwise go for.

The rust toolchain may not have such a target, so this feature is incomplete
where the rust toolchain needs to be selected with one target and told to build
for another (because it's a target that toolchain can be configured to cross
for)

Builds for cross should build identically if the target is set explicitly to the
same value as the crossSystem config.

note about explicit target
This function's entire job is to convert the nix triple to a rust triple.
"real" was confusing.  "Real" to what?  It's also not always used to map a host
triple and sometimes was used to map a build triple.

The world is a bit better now.

Second, the generation of the synthetic Cargo.toml used to build each crate drv
in mkcrate.nix was using a combination of rustTriple and the explicit target
override.  That has been slightly normalized.

There is still a problem in pkgsBuild in make-package-set/simple.nix.  I don't
think the explicit target we set for the host output needs to even touch the
depsBuildBuild outputs.

The detection for when to enable multiple targets when generating the Cargo.toml
for build was changed to compare the two triples we generate.  This means even
if crossSystem is not set but the explicit target is used, the difference will
be picked up and both target entries will be present in the toml.

I'm concerned about the CC flags becuase it may mean we provide a triple that
Rust understands and the cc cannot.  This is especially true if the explicit
target is provided by the user.
Rust supports a ton of platforms.  At least the stuff with crossSystem examples
should work.

Some of these like wasm64 are pure fantasy until Rust supports it.
null out explicit target for build packages so that it doesn't become an
explicit override
Use nixpkgs-<version>-darwin for darwin builds

And logic gate the Rust Analyzer build so that only successful operating systems
are used

use local cargo2nix in exmaples.  This is overriden by CI

use darwin nixpkgs for all examples

update cachix action

Flakes are built in as of 15.  Using authenticated requests was on the updated
README.  Much, much better.
Breaks the linking behavior.  Could instead just not st the linker.  More
testing needed with better examples.
More generated

Explicit target from latest overlay breaks them

update generated

clean this out of the final history

update-generated

updated generated
They can't build things
@psionic-k psionic-k marked this pull request as ready for review November 29, 2021 13:05
@psionic-k psionic-k merged commit 51f81fa into master Nov 29, 2021
@psionic-k psionic-k deleted the host-platform-build-rs branch November 29, 2021 13:13
@psionic-k psionic-k mentioned this pull request Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
1 participant