Browse Source

idl: Fix generation with recursive external types (#2946)

guibescos 1 year ago
parent
commit
128e937f4b
3 changed files with 5 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 0
      idl/src/build.rs
  3. 3 2
      lang/syn/src/idl/external.rs

+ 1 - 0
CHANGELOG.md

@@ -23,6 +23,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - ts: Fix incorrect `maxSupportedTransactionVersion` in `AnchorProvider.send*()` methods ([#2922](https://github.com/coral-xyz/anchor/pull/2922)).
 - cli: Use npm's configured default license for new projects made with `anchor init` ([#2929](https://github.com/coral-xyz/anchor/pull/2929)).
 - cli: add filename to 'Unable to read keypair file' errors ([#2932](https://github.com/coral-xyz/anchor/pull/2932)).
+- idl: Fix path resolution of the `Cargo.lock` of the project when generating idls for external types ([#2946](https://github.com/coral-xyz/anchor/pull/2946)).
 
 ### Breaking
 

+ 1 - 0
idl/src/build.rs

@@ -95,6 +95,7 @@ fn build(program_path: &Path, resolution: bool, no_docs: bool) -> Result<Idl> {
             "ANCHOR_IDL_BUILD_RESOLUTION",
             if resolution { "TRUE" } else { "FALSE" },
         )
+        .env("ANCHOR_IDL_BUILD_PROGRAM_PATH", program_path)
         .env("RUSTFLAGS", "--cfg procmacro2_semver_exempt")
         .current_dir(program_path)
         .stderr(Stdio::inherit())

+ 3 - 2
lang/syn/src/idl/external.rs

@@ -17,8 +17,9 @@ pub fn get_external_type(name: &str, path: impl AsRef<Path>) -> Result<Option<sy
         .ok_or_else(|| anyhow!("`{name}` not found in use statements"))?;
 
     // Get crate name and version from lock file
-    let lib_path = find_path("lib.rs", path)?;
-    let lock_path = find_path("Cargo.lock", lib_path)?;
+    let program_path =
+        std::env::var("ANCHOR_IDL_BUILD_PROGRAM_PATH").expect("Failed to get program path");
+    let lock_path = find_path("Cargo.lock", program_path)?;
     let lock_file = parse_lock_file(lock_path)?;
     let registry_path = get_registry_path()?;