Multiple different build modes

This commit is contained in:
trickypr 2022-06-23 12:23:33 +10:00
parent 7ce1c368f6
commit a71f9797b5
4 changed files with 64 additions and 9 deletions

View file

@ -29,6 +29,12 @@ export const commands: Cmd[] = [
],
requestController: async () => (await import('./commands/build')).build,
},
{
cmd: 'config',
aliases: ['set', 'get'],
description: 'Get and set the dynamic config from this project',
requestController: async () => (await import('./commands/set')).set,
},
{
cmd: 'discard <file>',
description: 'Discard a files changes.',
@ -102,12 +108,6 @@ export const commands: Cmd[] = [
description: 'Run the browser.',
requestController: async () => (await import('./commands/run')).run,
},
{
cmd: 'config',
aliases: ['set', 'get'],
description: 'Get and set the dynamic config from this project',
requestController: async () => (await import('./commands/set')).set,
},
{
cmd: 'setup-project',
description: 'Sets up a gluon project for the first time',

View file

@ -78,7 +78,7 @@ const applyConfig = async (os: string) => {
'\n\n' +
customConfig +
'\n' +
internalMozconfg(brandingKey)
internalMozconfg(brandingKey, dynamicConfig.get('buildMode'))
writeFileSync(resolve(ENGINE_DIR, 'mozconfig'), mergedConfig)

View file

@ -1,8 +1,54 @@
export const internalMozconfg = (brand: string) => `
const otherBuildModes = `# You can change to other build modes by running:
# $ gluon set buildMode [dev|debug|release]`
const platformOptimize =
process.platform == 'darwin'
? 'ac_add_options --enable-optimize="-O3 -march=nehalem -mtune=haswell -w"'
: process.platform == 'linux'
? 'ac_add_options --enable-optimize="-O3 -march=x86-64-v2 -mtune=haswell -w"'
: process.platform == 'win32'
? 'ac_add_options --enable-optimize="-O2 -Qvec -w -clang:-ftree-vectorize -clang:-msse3 -clang:-mssse3 -clang:-msse4.1 -clang:-mtune=haswell"'
: `# Unknown platform ${process.platform}`
export const internalMozconfg = (
brand: string,
buildMode: 'dev' | 'debug' | 'release' | string
) => {
let buildOptions = `# Unknown build mode ${buildMode}`
// Get the specific build options for the current build mode
switch (buildMode) {
case 'dev':
buildOptions = `# Development build settings
${otherBuildModes}
ac_add_options --disable-debug
ac_add_options --disable-optimize`
break
case 'debug':
buildOptions = `# Debug build settings
${otherBuildModes}
ac_add_options --enable-debug
ac_add_options --disable-optimize`
break
case 'release':
buildOptions = `# Release build settings
ac_add_options --disable-debug
ac_add_options --enable-optimize
${platformOptimize} # Taken from waterfox`
break
}
return `
# =====================
# Internal gluon config
# =====================
${buildOptions}
ac_add_options --disable-geckodriver
ac_add_options --disable-profiling
ac_add_options --disable-tests
# Custom branding
ac_add_options --with-branding=browser/branding/${brand}
@ -10,3 +56,4 @@ ac_add_options --with-branding=browser/branding/${brand}
ac_add_options --disable-verify-mar
ac_add_options --enable-update-channel=${brand}
`
}

View file

@ -1,13 +1,16 @@
// Defines config that should be set dynamically on the users system. This allows
// for interfacing between these values
import { log } from '../log'
import { readItem, writeItem } from './store'
export type ValidDynamicEntries = 'brand'
export const defaultValues: {
brand: string
buildMode: 'dev' | 'debug' | 'release'
} = {
brand: 'unofficial',
buildMode: 'dev',
}
export type DefaultValuesType = typeof defaultValues
@ -23,7 +26,12 @@ type DynamicSetter<K extends keyof DefaultValuesType> = (
export const get: DynamicGetter<keyof DefaultValuesType> = (key) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readItem(`dynamicConfig.${key}`).unwrapOr(defaultValues[key]) as any
readItem(`dynamicConfig.${key}`).unwrapOrElse(() => {
log.info(
`Dynamic config '${key} not set, defaulting to '${defaultValues[key]}'`
)
return defaultValues[key]
}) as any
export const set: DynamicSetter<keyof DefaultValuesType> = (key, value) =>
writeItem(key, value)