numbat icon indicating copy to clipboard operation
numbat copied to clipboard

Fix compilation for android (plotly.rs)

Open frroossst opened this issue 5 months ago • 8 comments

I prefer having cli programs on my android device as well. So when I tried to install numbat-cli with termux on Android it failed.

How to replicate

git clone https://github.com/sharkdp/numbat.git
cd numbat
cargo build

The error we get is

error[E0599]: no function or associated item named `show_with_default_app` found for struct `Plot` in the current scope
   --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotly-0.12.1/src/plot.rs:273:15
    |
178 | pub struct Plot {
    | --------------- function or associated item `show_with_default_app` not found for this struct
...
273 |         Plot::show_with_default_app(temp_path);
    |               ^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `Plot`
    |
note: if you're trying to build a new `Plot`, consider using `Plot::new` which returns `Plot`
   --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotly-0.12.1/src/plot.rs:190:5
    |
190 |     pub fn new() -> Plot {
    |     ^^^^^^^^^^^^^^^^^^^^

error[E0599]: no function or associated item named `show_with_default_app` found for struct `Plot` in the current scope
   --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotly-0.12.1/src/plot.rs:286:15
    |
178 | pub struct Plot {
    | --------------- function or associated item `show_with_default_app` not found for this struct
...
286 |         Plot::show_with_default_app(path);
    |               ^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `Plot`
    |
note: if you're trying to build a new `Plot`, consider using `Plot::new` which returns `Plot`
   --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotly-0.12.1/src/plot.rs:190:5
    |
190 |     pub fn new() -> Plot {
    |     ^^^^^^^^^^^^^^^^^^^^

error[E0599]: no function or associated item named `show_with_default_app` found for struct `Plot` in the current scope
   --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotly-0.12.1/src/plot.rs:315:15
    |
178 | pub struct Plot {
    | --------------- function or associated item `show_with_default_app` not found for this struct
...
315 |         Plot::show_with_default_app(temp_path);
    |               ^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `Plot`
    |
note: if you're trying to build a new `Plot`, consider using `Plot::new` which returns `Plot`
   --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/plotly-0.12.1/src/plot.rs:190:5
    |
190 |     pub fn new() -> Plot {
    |     ^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0599`.
error: could not compile `plotly` (lib) due to 3 previous errors

Solution

Looking around I found this particular issue on the plotly github.

https://github.com/plotly/plotly.rs/issues/282

There does not seem to be an update out at this point for plotly that fixes compilation on android. (Last release was 6 months ago)

So, the simple update would be to change numbat/Cargo.toml

# plotly = { version = "0.12.0", optional = true }
plotly = { git = "https://github.com/plotly/plotly.rs", branch = "main" , optional = true }

This will fail with

error[E0599]: no method named `show` found for struct `Plot` in the current scope                                  
  --> numbat/src/ffi/plot.rs:93:10
   |
93 |     plot.show();
   |          ^^^^ method not found in `Plot`

For more information about this error, try `rustc --explain E0599`.                                                
error: could not compile `numbat` (lib) due to 1 previous error

Currently, I just have a simple fix to add the plot.show() stub for android.

In numbat/src/ffi/plot.rs

fn show_plot(plot: Plot) -> CompactString {
    #[cfg(target_os = "android")]
    {
        let _ = plot;
        unimplemented!("cannot show_plot on android")
    }

    #[cfg(not(target_os = "android"))]
    {
        plot.show();

        CompactString::const_new("Plot will be opened in the browser")
    }
}

If the author(s)/ maintainer(s) feel like this might be a useful thing to add, I can open a pull request against master.

Thank you for creating and working on numbat!

frroossst avatar Jul 03 '25 16:07 frroossst

Feel free to checkout the code that is ready to be merged at https://github.com/frroossst/numbat/tree/36e8d059683f05a0bcf32bbb0d14447f19011563

I have run cargo test and all tests seem to pass.

frroossst avatar Jul 03 '25 17:07 frroossst

Can this not be solved by compiling Numbat without the plotting feature? I'm not too familiar with rust compilation yet, but I think that would be the preferable solution if possible.

Goju-Ryu avatar Jul 03 '25 17:07 Goju-Ryu

shouldn't plotting be an additional feature that could be turned on, but should be disabled on default installs?

cargo install numbat-cli --features plotting

frroossst avatar Jul 03 '25 18:07 frroossst

Whether it should or not I'm not sure, but currently it is part of the default feature set. To get a default installation except excluding plotting I think you can run:

cargo install numbat-cli --no-default-features --features fetch-exchangerates

Goju-Ryu avatar Jul 03 '25 18:07 Goju-Ryu

Although I might be forgetting features from the cli now that I think about it.

Goju-Ryu avatar Jul 03 '25 18:07 Goju-Ryu

https://doc.rust-lang.org/cargo/reference/features.html?highlight=additive#feature-unification

I was just going off of this which says cargo features must be additive

frroossst avatar Jul 03 '25 18:07 frroossst

I am not super well versed in rust compilation, but I think it is allowed since we use the resolver version 2 as described in this section. I may be wrong though.

Goju-Ryu avatar Jul 03 '25 18:07 Goju-Ryu

So, should I close this as won't fix?

frroossst avatar Nov 07 '25 14:11 frroossst