Closed ifiokjr closed 5 months ago
We can remove the panicking behavior but then the error would be silenced even when it's necessary.
As a temporary fix I've hardcoded the env variable
ANCHOR_IDL_BUILD_PROGRAM_PATH
to point to the program path but that will stop working with multiple programs in the workspace.
Why would it stop working when there are multiple programs? It should continue to work as long as the env variable ANCHOR_IDL_BUILD_PROGRAM_PATH
is only overridden in Rust Analyzer.
Thanks for the report!
Yes I am also facing the same issue, what could be necessary fix for it? how and where to disable cargo.features = "all"
??
@tarunjais28 provided you're using VS Code, you can add this to your .vscode/settings.json
file:
{
"rust-analyzer.cargo.allFeatures": false
}
@robertohuertasm I tried that but that is also not working, as issue #3045 is merged so how can it reflect on build as I am getting same error
How to resolve this issue? @tarunjais28 @ifiokjr @acheroncrypto
If you get this error when building, you resolve it by upgrading anchor-cli
to 0.30.1
. Otherwise this issue is specifically for Rust Analyzer, it means you have idl-build
feature enabled there, and you can resolve it by removing "rust-analyzer.cargo.features": "all"
entry.
Alternatively, you can disable this lint in Anchor.toml
:
[features]
skip-lint = true
Hi @acheroncrypto I tried above solutions suggested by you, still getting the same error.
Its very critical I am not able to build any of my solana projects
@tarunjais28 add this line to your Anchor.toml
[features] skip-lint = true
hi @Abhishek7Tech that is also there
Strange that the issue is closed, we have the same issue. Why did you closed it? Same problem, added env variable, added lint skip in Anchor config. With workspace that has multiple programs, all those solutions does not work. Using Anchor 0.30.1 and Solana 1.18.18
Strange that the issue is closed, we have the same issue. Why did you closed it? Same problem, added env variable, added lint skip in Anchor config. With workspace that has multiple programs, all those solutions does not work. Using Anchor 0.30.1 and Solana 1.18.18
Add "rust-analyzer.cargo.features": []
in .vscode/settings.json
.
This is also causing CI to fail when running cargo clippy --all-features
. Not running clippy is not an option so this needs a fix
This issue persists regardless of anchor version (0.30.1) or setting skip-lint=true in Anchor.toml. I also do not have VS Code installed so there is no settings.json to modify, but the error is still here.. Any other suggestions?
I have ran into this issue and cannot find a workaround to get my program building anymore.
Cargo.toml
[package]
name = "****"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
name = "****"
[features]
default = []
cpi = ["no-entrypoint"]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]
[dependencies]
anchor-lang = { version = "0.30.1", features = ["init-if-needed"] }
anchor-spl = { version = "0.30.1", features = ["idl-build", "metadata"] }
mpl-token-metadata = { version = "4.1.2" }
solana-program = "1.18.0"
Anchor.toml
[toolchain]
[features]
resolution = true
skip-lint = true
[programs.localnet]
launch = "****"
[registry]
url = "https://api.apr.dev"
[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"
[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
Any other suggestions?
^+1 also having this issue. I'm able to compile the program fine using declare_program!()
but I cannot seem to build an IDL when using declare_program!()
^+1 also having this issue. I'm able to compile the program fine using
declare_program!()
but I cannot seem to build an IDL when usingdeclare_program!()
This issue is unrelated to declare_program!
. Make sure you're using anchor-cli 0.30.1
(any older version won't work).
Here's a repro: https://github.com/ngundotra/spl-account-compression-idl-issue/tree/declare-program-fix
In this example, even with anchor-cli v0.30.1
I still can't get the IDL to build. When I run anchor build
I get the following output:
error: custom attribute panicked
--> programs/spl-account-compression-idl-issue/src/lib.rs:18:1
|
18 | #[program]
| ^^^^^^^^^^
|
= help: message: Safety checks failed: Failed to get program path
Found the issue. Was creating program id via Pubkey::from_str(...).unwrap()
that was throwing inside the cargo test __anchor_private_print_idl --features idl-build
step, which hides errors (rightfully).
I wonder if it's worth exposing a --verbose
flag that allows idl-build errors to be surfaced in the cargo test __anchor_private_print_idl
stage
I wonder if it's worth exposing a
--verbose
flag that allows idl-build errors to be surfaced in thecargo test __anchor_private_print_idl
stage
This is not documented but you can do
ANCHOR_LOG=true anchor build
I have ran into this issue and cannot find a workaround to get my program building anymore.
Cargo.toml
[package] .... [dependencies] anchor-lang = { version = "0.30.1", features = ["init-if-needed"] } anchor-spl = { version = "0.30.1", features = ["idl-build", "metadata"] } mpl-token-metadata = { version = "4.1.2" } solana-program = "1.18.0"
Any other suggestions?
found my issue. I needed to remove "idl-build" from anchor-spl
dependency.
@ngundotra @statikdev FYI, enabling the idl-build
feature by default should always be avoided (see https://github.com/jito-foundation/stakenet/pull/48#discussion_r1659971579).
There will be warnings and errors that guide the user to the correct usage of IDL build in the next version (e.g. https://github.com/coral-xyz/anchor/pull/3061, https://github.com/coral-xyz/anchor/pull/3133).
@acheroncrypto running ANCHOR_LOG=true anchor build
did not actually show me logs of why building the IDL failed. I just see this:
Error: Building IDL failed
side note: I love declare_program!()
it is fricking awesome.
@ngundotra Ah, it was returning early (before logging could happen) when the underlying build command failed. Fixed it and improved the build error message in https://github.com/coral-xyz/anchor/pull/3284.
I ran into the same issue with RustRover 2024.2.3. Ran a trace and found the macro expansion failed with the "Failed to get program path" error, resulting in all code completion failing.
What worked for me is explicitly setting ANCHOR_IDL_BUILD_PROGRAM_PATH
to where the Anchor program is.
Until the patch from @acheroncrypto (thanks!) gets released, just updating the ANCHOR_IDL_BUILD_PROGRAM_PATH
environment variable to the Anchor program being worked on should keep us going.
I've just upgraded to the latest version of anchor 0.30.1. Everything is fine and
anchor build
runs well. However, there's a small issue when rust-analyzer runs withcargo.features = "all"
. This means thatidl-build
feature is switched on in the LSP.As a result I'm seeing this error on the
#[program]
macro.The error originates from this variable declaration: https://github.com/coral-xyz/anchor/blob/e6d7dafe12da661a36ad1b4f3b5970e8986e5321/lang/syn/src/idl/external.rs#L20-L21
As a temporary fix I've hardcoded the env variable
ANCHOR_IDL_BUILD_PROGRAM_PATH
to point to the program path but that will stop working with multiple programs in the workspace.