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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not passing rustflags to build commands. #80

Closed
pauldemarco opened this issue Jan 1, 2023 · 9 comments
Closed

Not passing rustflags to build commands. #80

pauldemarco opened this issue Jan 1, 2023 · 9 comments

Comments

@pauldemarco
Copy link

pauldemarco commented Jan 1, 2023

I am on Windows, trying to compile a program with tokio (unstable enabled) for Android.
This builds successfully when using cargo build, but I can't seem to get cargo ndk ... to include the required --cfg tokio_unstable flags when building.

Steps to reproduce:
In my <project_root>/.cargo/config.toml file:

[build]
rustflags = ["--cfg", "tokio_unstable"]

When I run this command:
cargo ndk -t x86_64 -o ./out build -v

I am not seeing --cfg tokio_unstable in the build commands, and my program fails to compile since it's using the 'unstable' features of tokio.

@pauldemarco pauldemarco changed the title Not passing rustc_flags to build commands. Not passing rustflags to build commands. Jan 1, 2023
@bbqsrc
Copy link
Owner

bbqsrc commented Jan 6, 2023

Strange. I don't have time to look into this at the moment, but if someone can investigate why this is happening a fix should be straightforward.

Try exporting RUSTFLAGS on the command line directly as a potential workaround for now.

@MarijnS95
Copy link

There are multiple ways of setting RUSTFLAGS, which are mutually exclusive. cargo-ndk sets CARGO_ENCODED_RUSTFLAGS as copied from a dated ndk-build commit:

cargo_cmd.env("CARGO_ENCODED_RUSTFLAGS", rustflags);

ndk-build also accepts and merges with RUSTFLAGS, and we could "trivially" start parsing rustflags in .cargo/config.toml and appending it, since even though they are mutually exclusive, to the user the RUSTFLAGS set by cargo-apk/cargo-ndk are just an implementation detail.

@KronicDeth
Copy link

👋🏻 I'm having the same issue with tokio too.

I tried setting RUSTFLAGS and it didn't affect the build at all

╭─kronic.deth@Macintosh ~/github/liveviewnative/phoenix-channels-client ‹github-actions) ✗› 
╰─$ export RUSTFLAGS="--cfg tokio_unstable"
╭─kronic.deth@Macintosh ~/github/liveviewnative/phoenix-channels-client ‹github-actions) ✗› 
╰─$ cargo-tai tests --target x86_64-linux-android --android-api-lvl ${ANDROID_API} --android-ndk ${ANDROID_NDK_HOME}
[2023-01-23T16:05:42Z INFO  cargo_ndk::cli] Using NDK at path: /usr/local/share/android-ndk (ANDROID_NDK_HOME)
[2023-01-23T16:05:42Z INFO  cargo_ndk::cli] NDK API level: 21
[2023-01-23T16:05:42Z INFO  cargo_ndk::cli] Building targets: x86_64
[2023-01-23T16:05:42Z INFO  cargo_ndk::cli] Building x86_64 (x86_64-linux-android)
   Compiling phoenix_channels_client v0.1.0 (/Users/kronic.deth/github/liveviewnative/phoenix-channels-client)
error: Broken pipe (os error 32)
warning: build failed, waiting for other jobs to finish...
error: could not compile `phoenix_channels_client` due to 2 previous errors
error: could not compile `phoenix_channels_client` due to 2 previous errors
[2023-01-23T16:05:47Z INFO  cargo_ndk::cli] If the build failed due to a missing target, you can run this command:
[2023-01-23T16:05:47Z INFO  cargo_ndk::cli] 
[2023-01-23T16:05:47Z INFO  cargo_ndk::cli]     rustup target install x86_64-linux-android
Error: error[E0425]: cannot find function `consume_budget` in module `task`
   --> src/channel.rs:519:23
    |
519 |                 task::consume_budget().await
    |                       ^^^^^^^^^^^^^^ not found in `task`

If I set CARGO_ENCODED_RUSTFLAGS instead, the quoting is wrong

╭─kronic.deth@Macintosh ~/github/liveviewnative/phoenix-channels-client ‹github-actions) ✗› 
╰─$ export CARGO_ENCODED_RUSTFLAGS='--cfg\x1Ftokio_unstable'
╭─kronic.deth@Macintosh ~/github/liveviewnative/phoenix-channels-client ‹github-actions) ✗› 
╰─$ cargo-tai tests --target x86_64-linux-android --android-api-lvl ${ANDROID_API} --android-ndk ${ANDROID_NDK_HOME}
Error: `cargo metadata` exited with an error: error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `sccache rustc - --crate-name ___ --print=file-names '--cfg\x1Ftokio_unstable' --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
  --- stderr
  error: Unrecognized option: 'cfg\x1Ftokio_unstable'

@bbqsrc
Copy link
Owner

bbqsrc commented Jan 23, 2023

If someone can create a super simple reproduction repo for this, I should be able to fix it quickly.

@MarijnS95
Copy link

MarijnS95 commented Jan 23, 2023

@bbqsrc all you need is to replicate rust-mobile/ndk#357 (or migrate to / merge with ndk-build 😉), that should be enough.

@KronicDeth
Copy link

Using the build on main gets past the issue, but I get an Error.

╭─kronic.deth@Macintosh ~/github/liveviewnative/phoenix-channels-client ‹github-actions) ✗› 
╰─$ cargo install --git https://github.com/bbqsrc/cargo-ndk
    Updating git repository `https://github.com/bbqsrc/cargo-ndk`
  Installing cargo-ndk v3.0.0-alpha.0 (https://github.com/bbqsrc/cargo-ndk#fcfe672f)
    Updating crates.io index
   Compiling proc-macro2 v1.0.50
   Compiling unicode-ident v1.0.6
   Compiling quote v1.0.23
   Compiling syn v1.0.107
   Compiling serde_derive v1.0.152
   Compiling libc v0.2.139
   Compiling serde v1.0.152
   Compiling io-lifetimes v1.0.4
   Compiling memchr v2.5.0
   Compiling rustix v0.36.7
   Compiling log v0.4.17
   Compiling thiserror v1.0.38
   Compiling camino v1.1.2
   Compiling bitflags v1.3.2
   Compiling cfg-if v1.0.0
   Compiling semver v1.0.16
   Compiling serde_json v1.0.91
   Compiling smallvec v1.10.0
   Compiling pct-str v1.1.0
   Compiling ryu v1.0.12
   Compiling itoa v1.0.5
   Compiling regex-syntax v0.6.28
   Compiling malloced v1.1.0
   Compiling fruity__bbqsrc v0.2.0
   Compiling iref v1.4.3
   Compiling termcolor v1.2.0
   Compiling os_str_bytes v2.4.0
   Compiling humantime v2.1.0
   Compiling eieio v1.0.0
   Compiling once_cell v1.17.0
   Compiling percent-encoding v2.2.0
   Compiling aho-corasick v0.7.20
   Compiling errno v0.2.8
   Compiling regex v1.7.1
   Compiling is-terminal v0.4.2
   Compiling thiserror-impl v1.0.38
   Compiling gumdrop_derive v0.8.1
   Compiling gumdrop v0.8.1
   Compiling pathos v0.3.0
   Compiling env_logger v0.10.0
   Compiling cargo-platform v0.1.2
   Compiling toml v0.5.11
   Compiling cargo_metadata v0.15.2
   Compiling cargo-ndk v3.0.0-alpha.0 (/Users/kronic.deth/.cargo/git/checkouts/cargo-ndk-5f0854eb9c1527c2/fcfe672)
    Finished release [optimized] target(s) in 37.56s
  Installing /Users/kronic.deth/.cargo/bin/cargo-ndk
   Installed package `cargo-ndk v3.0.0-alpha.0 (https://github.com/bbqsrc/cargo-ndk#fcfe672f)` (executable `cargo-ndk`)
╭─kronic.deth@Macintosh ~/github/liveviewnative/phoenix-channels-client ‹github-actions) ✗› 
╰─$ cargo-tai tests --target x86_64-linux-android --android-api-lvl ${ANDROID_API} --android-ndk ${ANDROID_NDK_HOME}
[2023-01-23T16:57:53Z INFO  cargo_ndk::cli] Using NDK at path: /usr/local/share/android-ndk (ANDROID_NDK_HOME)
[2023-01-23T16:57:53Z INFO  cargo_ndk::cli] NDK API level: 21
[2023-01-23T16:57:53Z INFO  cargo_ndk::cli] Building targets: x86_64
[2023-01-23T16:57:53Z INFO  cargo_ndk::cli] Building x86_64 (x86_64-linux-android)
   Compiling cfg-if v1.0.0
   Compiling once_cell v1.15.0
   Compiling pin-project-lite v0.2.9
   Compiling slab v0.4.7
   Compiling proc-macro2 v1.0.46
   Compiling libc v0.2.134
   Compiling quote v1.0.21
   Compiling syn v1.0.101
   Compiling memchr v2.5.0
   Compiling openssl-sys v0.9.76
   Compiling typenum v1.15.0
   Compiling generic-array v0.14.6
   Compiling log v0.4.17
   Compiling futures-core v0.3.24
   Compiling lock_api v0.4.9
   Compiling futures-task v0.3.24
   Compiling parking_lot_core v0.9.3
   Compiling futures-channel v0.3.24
   Compiling foreign-types-shared v0.1.1
   Compiling tinyvec_macros v0.1.0
   Compiling openssl v0.10.42
   Compiling foreign-types v0.3.2
   Compiling tinyvec v1.6.0
   Compiling futures-sink v0.3.24
   Compiling native-tls v0.2.10
   Compiling bytes v1.2.1
   Compiling futures-util v0.3.24
   Compiling scopeguard v1.1.0
   Compiling smallvec v1.9.0
   Compiling bitflags v1.3.2
   Compiling tracing-core v0.1.29
   Compiling tokio v1.21.2
   Compiling unicode-bidi v0.3.8
   Compiling futures-io v0.3.24
   Compiling serde_derive v1.0.145
   Compiling openssl-probe v0.1.5
   Compiling ppv-lite86 v0.2.16
   Compiling httparse v1.8.0
   Compiling pin-utils v0.1.0
   Compiling thiserror v1.0.37
   Compiling percent-encoding v2.2.0
   Compiling itoa v1.0.3
   Compiling cpufeatures v0.2.5
   Compiling byteorder v1.4.3
   Compiling serde v1.0.145
   Compiling getrandom v0.2.7
   Compiling socket2 v0.4.7
   Compiling signal-hook-registry v1.4.0
   Compiling form_urlencoded v1.1.0
   Compiling mio v0.8.4
   Compiling num_cpus v1.13.1
   Compiling fnv v1.0.7
   Compiling tracing v0.1.36
   Compiling rand_core v0.6.4
   Compiling unicode-normalization v0.1.22
   Compiling serde_json v1.0.85
   Compiling utf-8 v0.7.6
   Compiling base64 v0.13.0
   Compiling http v0.2.8
   Compiling aho-corasick v0.7.19
   Compiling parking_lot v0.12.1
   Compiling regex-syntax v0.6.27
   Compiling ryu v1.0.11
   Compiling fxhash v0.2.1
   Compiling rand_chacha v0.3.1
   Compiling atty v0.2.14
   Compiling termcolor v1.1.3
   Compiling humantime v2.1.0
   Compiling crypto-common v0.1.6
   Compiling block-buffer v0.10.3
   Compiling digest v0.10.5
   Compiling rand v0.8.5
   Compiling idna v0.3.0
   Compiling sha-1 v0.10.0
   Compiling url v2.3.1
   Compiling regex v1.6.0
   Compiling openssl-macros v0.1.0
   Compiling futures-macro v0.3.24
   Compiling thiserror-impl v1.0.37
   Compiling tokio-macros v1.8.0
   Compiling env_logger v0.9.1
   Compiling futures-executor v0.3.24
   Compiling futures v0.3.24
   Compiling tungstenite v0.17.3
   Compiling tokio-native-tls v0.3.0
   Compiling tokio-tungstenite v0.17.2
   Compiling phoenix_channels_client v0.1.0 (/Users/kronic.deth/github/liveviewnative/phoenix-channels-client)
    Finished dev [unoptimized + debuginfo] target(s) in 35.52s
Error: No such file or directory (os error 2)

Tracking that down now. (The project works for the macOS and iOS simulator build that don't use cargo-tai, so it is likely something cargo-tai, cargo-ndk, or Android-specific.

@KronicDeth
Copy link

I modified cargo-tai to add more debug statements and it's the ListDevices task that fails, so my last error is a problem in cargo-tai and the version of cargo-ndk on main fixes this bug! ❤️

Waiting for child
Child complete
units built
built units inserted into context
task ran: BuildBuiltUnits(BuildBuiltUnits)
task to run: CreateBundles(CreateBundles)
task ran: CreateBundles(CreateBundles)
task to run: ListDevices(ListDevices)
Error: No such file or directory (os error 2)

@bbqsrc
Copy link
Owner

bbqsrc commented Jan 23, 2023

Hmm, interesting.

@bbqsrc
Copy link
Owner

bbqsrc commented Jan 24, 2023

Fixed in v2.14.4, for both encoded and not encoded flags.

@bbqsrc bbqsrc closed this as completed Jan 24, 2023
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

No branches or pull requests

4 participants