ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
313 stars 43 forks source link

Conditionally generate Pyth code instead of relying on cargo feature flag #75

Closed mcintyre94 closed 1 year ago

mcintyre94 commented 1 year ago

Discussion in Discord: https://discord.com/channels/1005658120548270224/1006027519952171028/1049721077934338099

Currently our common generated code (like seahorse_util) doesn't need to know about features, it just always generates the Pyth imports behind a cargo feature flag

This simplifies the Seahorse compiler, but has some downsides:

It would probably be better for us to have all the conditional code generation in seahorse, so the dependency is only added to cargo.toml if it's used, and only imported if it's used. Not sure how complex/difficult this would be though!

The issue says Pyth code because that's the only conditional code for now, but any approach needs to scale to other conditional crates too

ameliatastic commented 1 year ago

Oh, too bad we didn't think about the playground when implementing this. Just thinking, is it safe for solpg to just always pass in the feature flag for Pyth?

FWIW I think this wouldn't be too difficult to change, so it's not a huge problem.

mcintyre94 commented 1 year ago

Just thinking, is it safe for solpg to just always pass in the feature flag for Pyth?

I think the only downside would be that it'd make the built size bigger. So for most cases that's probably fine, you might need to do another airdrop on dev before deploying. And people probably shouldn't be deploying Seahorse stuff to mainnet yet! Main issue is probably performance on the playground build server. And I guess when we add more features we'd need to keep updating the call in playground.