Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: remove golang_al2 flag (#1624)
Browse files Browse the repository at this point in the history
* fix: remove golang_al2 flag

* fix: test
  • Loading branch information
Skn0tt authored Oct 30, 2023
1 parent af0e46c commit b7fc082
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 32 deletions.
3 changes: 0 additions & 3 deletions src/feature_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export const defaultFlags = {

// If multiple glob stars are in includedFiles, fail the build instead of warning.
zisi_esbuild_fail_double_glob: false,

// Bundle for the provided.AL2 runtime for Go functions.
zisi_golang_use_al2: false,
} as const

export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>
Expand Down
19 changes: 2 additions & 17 deletions src/runtimes/go/builder.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import { promises as fs } from 'fs'
import { basename } from 'path'

import type { FeatureFlags } from '../../feature_flags.js'
import { FunctionBundlingUserError } from '../../utils/error.js'
import { shellUtils } from '../../utils/shell.js'
import { RUNTIME } from '../runtime.js'

export const build = async ({
destPath,
mainFile,
srcDir,
featureFlags,
}: {
destPath: string
mainFile: string
srcDir: string
featureFlags: FeatureFlags
}) => {
export const build = async ({ destPath, mainFile, srcDir }: { destPath: string; mainFile: string; srcDir: string }) => {
const functionName = basename(srcDir)

try {
const args = ['build', '-o', destPath, '-ldflags', '-s -w']

if (featureFlags.zisi_golang_use_al2) {
args.push('-tags', 'lambda.norpc')
}
const args = ['build', '-o', destPath, '-ldflags', '-s -w', '-tags', 'lambda.norpc']

await shellUtils.runCommand('go', args, {
cwd: srcDir,
Expand Down
7 changes: 3 additions & 4 deletions src/runtimes/go/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const zipFunction: ZipFunction = async function ({
srcPath,
stat,
isInternal,
featureFlags,
}) {
const destPath = join(destFolder, filename)
const isSource = extname(mainFile) === '.go'
Expand All @@ -126,7 +125,7 @@ const zipFunction: ZipFunction = async function ({
// If we're building a Go function from source, we call the build method and
// update `binary` to point to the newly-created binary.
if (isSource) {
const { stat: binaryStat } = await build({ destPath, mainFile, srcDir, featureFlags })
const { stat: binaryStat } = await build({ destPath, mainFile, srcDir })

binary = {
path: destPath,
Expand All @@ -138,7 +137,7 @@ const zipFunction: ZipFunction = async function ({
config,
displayName: config?.name,
generator: config?.generator || getInternalValue(isInternal),
runtimeVersion: featureFlags.zisi_golang_use_al2 ? 'provided.al2' : undefined,
runtimeVersion: 'provided.al2',
}

// If `zipGo` is enabled, we create a zip archive with the Go binary and the
Expand All @@ -147,7 +146,7 @@ const zipFunction: ZipFunction = async function ({
const zipPath = `${destPath}.zip`
const zipOptions = {
destPath: zipPath,
filename: featureFlags.zisi_golang_use_al2 ? 'bootstrap' : basename(destPath),
filename: 'bootstrap',
runtime,
}

Expand Down
12 changes: 4 additions & 8 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1791,9 +1791,6 @@ describe('zip-it-and-ship-it', () => {
zipGo: true,
},
},
featureFlags: {
zisi_golang_use_al2: true,
},
},
})
const binaryPath = join(FIXTURES_DIR, fixtureName, 'test')
Expand Down Expand Up @@ -1838,9 +1835,6 @@ describe('zip-it-and-ship-it', () => {
zipGo: true,
},
},
featureFlags: {
zisi_golang_use_al2: true,
},
},
})
const [func] = files
Expand Down Expand Up @@ -1910,6 +1904,7 @@ describe('zip-it-and-ship-it', () => {
path: expect.anything(),
entryFilename: '',
runtime: 'go',
runtimeVersion: 'provided.al2',
},
{
config: expect.anything(),
Expand All @@ -1918,6 +1913,7 @@ describe('zip-it-and-ship-it', () => {
path: expect.anything(),
entryFilename: '',
runtime: 'go',
runtimeVersion: 'provided.al2',
},
])

Expand All @@ -1926,7 +1922,7 @@ describe('zip-it-and-ship-it', () => {
expect(shellUtils.runCommand).toHaveBeenNthCalledWith(
1,
'go',
['build', '-o', expect.stringMatching(/(\/|\\)go-func-1$/), '-ldflags', '-s -w'],
['build', '-o', expect.stringMatching(/(\/|\\)go-func-1$/), '-ldflags', '-s -w', '-tags', 'lambda.norpc'],
expect.objectContaining({
env: expect.objectContaining({ CGO_ENABLED: '0', GOOS: 'linux' }),
}),
Expand All @@ -1935,7 +1931,7 @@ describe('zip-it-and-ship-it', () => {
expect(shellUtils.runCommand).toHaveBeenNthCalledWith(
2,
'go',
['build', '-o', expect.stringMatching(/(\/|\\)go-func-2$/), '-ldflags', '-s -w'],
['build', '-o', expect.stringMatching(/(\/|\\)go-func-2$/), '-ldflags', '-s -w', '-tags', 'lambda.norpc'],
expect.objectContaining({
env: expect.objectContaining({ CGO_ENABLED: '0', GOOS: 'linux' }),
}),
Expand Down

1 comment on commit b7fc082

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⏱ Benchmark results

  • largeDepsEsbuild: 3.1s
  • largeDepsNft: 9.5s
  • largeDepsZisi: 19.4s

Please sign in to comment.