Browse Source

Patch Solana dependencies when needed

Loris Leiva 1 year ago
parent
commit
20dc4c87f5
4 changed files with 37 additions and 4 deletions
  1. 1 2
      .github/workflows/main.yml
  2. 9 2
      index.ts
  3. 7 0
      scripts/snapshot.mjs
  4. 20 0
      utils/solanaCli.ts

+ 1 - 2
.github/workflows/main.yml

@@ -30,8 +30,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        solana: ["1.18.4"]
-        # solana: ["1.17.24", "1.18.4"]
+        solana: ["1.17.24", "1.18.4"]
 
     steps:
       - name: Git checkout

+ 9 - 2
index.ts

@@ -8,7 +8,11 @@ import { getLanguage } from './utils/getLanguage';
 import { logBanner, logDone, logStep } from './utils/getLogs';
 import { RenderContext, getRenderContext } from './utils/getRenderContext';
 import { renderTemplate } from './utils/renderTemplates';
-import { detectSolanaVersion, generateKeypair } from './utils/solanaCli';
+import {
+  detectSolanaVersion,
+  generateKeypair,
+  patchSolanaDependencies,
+} from './utils/solanaCli';
 
 (async function init() {
   logBanner();
@@ -57,7 +61,10 @@ import { detectSolanaVersion, generateKeypair } from './utils/solanaCli';
       '$targetDirectory',
       inputs.targetDirectoryName
     ),
-    () => renderTemplates(ctx)
+    async () => {
+      renderTemplates(ctx);
+      await patchSolanaDependencies(ctx.targetDirectory, ctx.solanaVersion);
+    }
   );
 
   // Done.

+ 7 - 0
scripts/snapshot.mjs

@@ -60,6 +60,13 @@ for (const projectName of projects) {
     });
   }
 
+  // Build programs.
+  if ('programs:build' in pkg.scripts) {
+    await executeStep('build programs', async () => {
+      await $`pnpm programs:build`;
+    });
+  }
+
   if (runTests) {
     // Test programs.
     if ('programs:test' in pkg.scripts) {

+ 20 - 0
utils/solanaCli.ts

@@ -24,6 +24,26 @@ export async function detectSolanaVersion(language: Language): Promise<string> {
   return version!;
 }
 
+export async function patchSolanaDependencies(
+  targetDirectory: string,
+  solanaVersion: string
+): Promise<void> {
+  const patchMap: Record<string, string[]> = {
+    '1.17': ['-p ahash@0.8.11 --precise 0.8.6'],
+  };
+
+  const patches = patchMap[solanaVersion] ?? [];
+  await Promise.all(
+    patches.map((patch) =>
+      waitForCommand(
+        spawnCommand('cargo', ['update', ...patch.split(' ')], {
+          cwd: targetDirectory,
+        })
+      )
+    )
+  );
+}
+
 export function toMinorSolanaVersion(
   language: Language,
   version: string