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

Support for library with different name than crate name #1100

Merged
merged 9 commits into from
Apr 24, 2023
Merged

Support for library with different name than crate name #1100

merged 9 commits into from
Apr 24, 2023

Conversation

azam
Copy link
Contributor

@azam azam commented Apr 10, 2023

This resolves #1099

Copy link
Contributor

@eeeebbbbrrrr eeeebbbbrrrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good.

I feel like we ought to document this somewhere, but pgx' "documentation" is kinda disorganized. We'll get this documented somewhere later.

@eeeebbbbrrrr
Copy link
Contributor

Oh, one change, @azam: could you also update the .github/workflows/tests.yml file to include the new example? Unfortunately we hardcode those...

@eeeebbbbrrrr
Copy link
Contributor

Also, looks like it needs a cargo fmt too. Thanks! That's the test current test failure.

@azam
Copy link
Contributor Author

azam commented Apr 11, 2023

@eeeebbbbrrrr
Sure! Pushed the changes. Found the doc on lib.name, so I also added a comment on changed line referencing the doc.

@azam
Copy link
Contributor Author

azam commented Apr 12, 2023

Got to put a hold on this, I am stuck at getting the lib name here. Should we read the cargo manifest to get it, since there is no env var set for lib name (there is for binaries though CARGO_BIN_NAME)?

@eeeebbbbrrrr
Copy link
Contributor

Got to put a hold on this, I am stuck at getting the lib name here. Should we read the cargo manifest to get it, since there is no env var set for lib name (there is for binaries though CARGO_BIN_NAME)?

That's a sneaky line of code!

Yeah, so I think now it makes sense to centralize the manifest handling, and use it here. I think what might be okay is to add a PgxManifest type (or whatever) to the pgx-pg-config crate, which both cargo-pgx and pgx-tests already have a dependency for.

I'd go for the absolutely minimal implementation of this new PgxManifest type -- basically just a constructor that can parse the file and a public function to get the crate name we'd want everyone to use.

What do you think?

@eeeebbbbrrrr
Copy link
Contributor

edit: and I suppose this means moving some of cargo-pgx/src/manifest.rs over too. So yeah, there'll be a little bit of design work here now.

@azam
Copy link
Contributor Author

azam commented Apr 12, 2023

I could do that, thinking on the line of exporting these functions:

  • get_crate_name(cargo_toml_path)
  • get_crate__version(cargo_toml_path)
  • get_extension_name(cargo_toml_path)

Should I do this?

@eeeebbbbrrrr
Copy link
Contributor

Yeah, that seems fine. Thanks!

@azam
Copy link
Contributor Author

azam commented Apr 12, 2023

@eeeebbbbrrrr
Pushed my changes. Hope nothing breaks.

@eeeebbbbrrrr
Copy link
Contributor

Since we just renamed to pgrx, this PR needs to be rebased against the develop branch. Would you mind doing that?

And if there's any references to "pgx" in your changeset they'll now need to be "pgrx". Sorry for the trouble! Growing pains!

@azam
Copy link
Contributor Author

azam commented Apr 19, 2023

@eeeebbbbrrrr
Rebased my repo!

@eeeebbbbrrrr
Copy link
Contributor

This looks good. I'm letting CI run it now. Thanks @azam!

@eeeebbbbrrrr
Copy link
Contributor

I'm not sure if you're allowed to see the test runner output? https://github.com/tcdi/pgrx/actions/runs/4738921279/jobs/8425118139

But basically the tests are failing with:

Error: 
   0: Could not get shared object file from Cargo output.

Location:
   cargo-pgrx/src/command/install.rs:380

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   0: cargo_pgrx::command::install::find_library_file
      at cargo-pgrx/src/command/install.rs:351
   1: cargo_pgrx::command::install::install_extension with pg_version=13.10 profile=Dev test=true features=["pg13", "pg_test", "cshim"]
      at cargo-pgrx/src/command/install.rs:94
   2: cargo_pgrx::command::install::execute
      at cargo-pgrx/src/command/install.rs:51

Oh, and this is for the pgrx-tests crate. Any ideas? Have you tried running cargo test --all --features pg13 --no-default-features locally?


let mut library_file = None;
for message in build_command_messages {
match message {
cargo_metadata::Message::CompilerArtifact(artifact) => {
if artifact.target.name != *crate_name {
if artifact.target.name != *target_name {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artifact.target.name is filled with crate name as-is (ie pgrx-tests) or lib name, depending on whether lib name has a name override or not, but cargo_manifest::Manifest auto fills lib name with crate name with hyphen replaced with underscore (ie pgrx_tests). Added target_name on PgrxManifestExt to return a value matching what cargo_metadata expects

@azam
Copy link
Contributor Author

azam commented Apr 20, 2023

@eeeebbbbrrrr
Apologize for the failure; borked my cargo-pgrx after the rebase, it kept the old version.
Fixed the error, re-ran the test locally and passed.
test_out.log

@eeeebbbbrrrr
Copy link
Contributor

No need to apologize! It's a complex system and that's why we have CI. We appreciate your efforts on this PR!

@eeeebbbbrrrr eeeebbbbrrrr merged commit abf0b4b into pgcentralfoundation:develop Apr 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

Successfully merging this pull request may close these issues.

2 participants