diff --git a/changelog/add_lowmem.dd b/changelog/add_lowmem.dd new file mode 100644 index 0000000..84d7faa --- /dev/null +++ b/changelog/add_lowmem.dd @@ -0,0 +1,9 @@ +Added support for low memory compilation option to the $(LINK2 https://dub.pm/settings, dub settings file). + +To enable, set `defaultLowMemory` to `true`. For dmd and ldc, the `-lowmem` command-line option is added when compiling. + +``` +{ + "defaultLowMemory": true +} +``` diff --git a/source/dub/commandline.d b/source/dub/commandline.d index bebdd43..7a799d2 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -998,6 +998,7 @@ { if (!m_compilerName.length) m_compilerName = dub.defaultCompiler; if (!m_arch.length) m_arch = dub.defaultArchitecture; + if (dub.defaultLowMemory) m_buildSettings.options |= BuildOption.lowmem; m_compiler = getCompiler(m_compilerName); m_buildPlatform = m_compiler.determinePlatform(m_buildSettings, m_compilerName, m_arch); m_buildSettings.addDebugVersions(m_debugVersions); @@ -1592,6 +1593,7 @@ settings.buildType = m_buildType; settings.compiler = m_compiler; settings.filterVersions = m_filterVersions; + settings.buildSettings.options |= m_buildSettings.options & BuildOption.lowmem; if (m_importPaths) { m_data = ["import-paths"]; m_dataList = true; } else if (m_stringImportPaths) { m_data = ["string-import-paths"]; m_dataList = true; } diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index f5bb45f..49965e7 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -325,10 +325,11 @@ profileGC = 1<<21, /// Profile runtime allocations pic = 1<<22, /// Generate position independent code betterC = 1<<23, /// Compile in betterC mode (-betterC) + lowmem = 1<<24, /// Compile in lowmem mode (-lowmem) // for internal usage - _docs = 1<<24, // Write ddoc to docs - _ddox = 1<<25 // Compile docs.json + _docs = 1<<25, // Write ddoc to docs + _ddox = 1<<26 // Compile docs.json } struct BuildOptions { diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 1782831..add0308 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -63,6 +63,7 @@ tuple(BuildOption.property, ["-property"]), tuple(BuildOption.profileGC, ["-profile=gc"]), tuple(BuildOption.betterC, ["-betterC"]), + tuple(BuildOption.lowmem, ["-lowmem"]), tuple(BuildOption._docs, ["-Dddocs"]), tuple(BuildOption._ddox, ["-Xfdocs.json", "-Df__dummy.html"]), diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index c4ba3ec..080fa52 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -45,6 +45,7 @@ tuple(BuildOption.property, ["-property"]), //tuple(BuildOption.profileGC, ["-?"]), tuple(BuildOption.betterC, ["-betterC"]), + tuple(BuildOption.lowmem, ["-lowmem"]), tuple(BuildOption._docs, ["-Dd=docs"]), tuple(BuildOption._ddox, ["-Xf=docs.json", "-Dd=__dummy_docs"]), diff --git a/source/dub/dub.d b/source/dub/dub.d index c11737b..1a8433d 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -132,6 +132,7 @@ NativePath m_overrideSearchPath; string m_defaultCompiler; string m_defaultArchitecture; + bool m_defaultLowMemory; } /** The default placement location of fetched packages. @@ -288,6 +289,7 @@ determineDefaultCompiler(); m_defaultArchitecture = m_config.defaultArchitecture; + m_defaultLowMemory = m_config.defaultLowMemory; } @property void dryRun(bool v) { m_dryRun = v; } @@ -332,6 +334,13 @@ */ @property string defaultArchitecture() const { return m_defaultArchitecture; } + /** Returns the default low memory option to use for building D code. + + If set, the "defaultLowMemory" field of the DUB user or system + configuration file will be used. Otherwise false will be returned. + */ + @property bool defaultLowMemory() const { return m_defaultLowMemory; } + /** Loads the package that resides within the configured `rootPath`. */ void loadPackage() @@ -765,6 +774,7 @@ settings.compiler = getCompiler(compiler_binary); settings.platform = settings.compiler.determinePlatform(settings.buildSettings, compiler_binary, m_defaultArchitecture); settings.buildType = "debug"; + if (m_defaultLowMemory) settings.buildSettings.options |= BuildOption.lowmem; settings.run = true; foreach (dependencyPackage; m_project.dependencies) @@ -1261,6 +1271,7 @@ settings.buildType = "debug"; settings.run = true; settings.runArgs = runArgs; + if (m_defaultLowMemory) settings.buildSettings.options |= BuildOption.lowmem; initSubPackage.recipe.buildSettings.workingDirectory = path.toNativeString(); template_dub.generateProject("build", settings); } @@ -1331,6 +1342,7 @@ settings.compiler = getCompiler(compiler_binary); // TODO: not using --compiler ??? settings.platform = settings.compiler.determinePlatform(settings.buildSettings, compiler_binary, m_defaultArchitecture); settings.buildType = "debug"; + if (m_defaultLowMemory) settings.buildSettings.options |= BuildOption.lowmem; settings.run = true; auto filterargs = m_project.rootPackage.recipe.ddoxFilterArgs.dup; @@ -1833,4 +1845,12 @@ if (m_parentConfig) return m_parentConfig.defaultArchitecture; return null; } + + @property bool defaultLowMemory() + const { + if(auto pv = "defaultLowMemory" in m_data) + return (*pv).get!bool; + if (m_parentConfig) return m_parentConfig.defaultLowMemory; + return false; + } } diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 2852c3d..db21e51 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -96,6 +96,7 @@ BuildSettings buildSettings; auto config = configs[pack.name]; buildSettings.processVars(m_project, pack, pack.getBuildSettings(settings.platform, config), settings, true); + if (settings.buildSettings.options & BuildOption.lowmem) buildSettings.options |= BuildOption.lowmem; prepareGeneration(pack, m_project, settings, buildSettings); diff --git a/test/issue1867-lowmem.sh b/test/issue1867-lowmem.sh new file mode 100755 index 0000000..6a39653 --- /dev/null +++ b/test/issue1867-lowmem.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh +DIR=$(dirname "${BASH_SOURCE[0]}") + +if ! { ${DUB} build --root ${DIR}/issue1867-lowmem -v -f 2>&1 || true; } | grep -cF " -lowmem " > /dev/null; then + die $LINENO 'DUB build with lowmem did not find -lowmem option.' +fi + +if ! { ${DUB} test --root ${DIR}/issue1867-lowmem -v -f 2>&1 || true; } | grep -cF " -lowmem " > /dev/null; then + die $LINENO 'DUB test with lowmem did not find -lowmem option.' +fi + +if ! { ${DUB} run --root ${DIR}/issue1867-lowmem -v -f 2>&1 || true; } | grep -cF " -lowmem " > /dev/null; then + die $LINENO 'DUB test with lowmem did not find -lowmem option.' +fi + +if ! { ${DUB} describe --root ${DIR}/issue1867-lowmem --data=options --data-list --verror 2>&1 || true; } | grep -cF "lowmem" > /dev/null; then + die $LINENO 'DUB describe --data=options --data-list with lowmem did not find lowmem option.' +fi diff --git a/test/issue1867-lowmem/.gitignore b/test/issue1867-lowmem/.gitignore new file mode 100644 index 0000000..3b21cd5 --- /dev/null +++ b/test/issue1867-lowmem/.gitignore @@ -0,0 +1,15 @@ +.dub +docs.json +__dummy.html +docs/ +/issue1867-lowmem +issue1867-lowmem.so +issue1867-lowmem.dylib +issue1867-lowmem.dll +issue1867-lowmem.a +issue1867-lowmem.lib +issue1867-lowmem-test-* +*.exe +*.o +*.obj +*.lst diff --git a/test/issue1867-lowmem/.no_build b/test/issue1867-lowmem/.no_build new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1867-lowmem/.no_build diff --git a/test/issue1867-lowmem/.no_run b/test/issue1867-lowmem/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1867-lowmem/.no_run diff --git a/test/issue1867-lowmem/.no_test b/test/issue1867-lowmem/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1867-lowmem/.no_test diff --git a/test/issue1867-lowmem/dub.sdl b/test/issue1867-lowmem/dub.sdl new file mode 100644 index 0000000..2cf20c8 --- /dev/null +++ b/test/issue1867-lowmem/dub.sdl @@ -0,0 +1 @@ +name "issue1867-lowmem" diff --git a/test/issue1867-lowmem/dub.settings.json b/test/issue1867-lowmem/dub.settings.json new file mode 100644 index 0000000..6944fb1 --- /dev/null +++ b/test/issue1867-lowmem/dub.settings.json @@ -0,0 +1,3 @@ +{ + "defaultLowMemory": true +} diff --git a/test/issue1867-lowmem/source/app.d b/test/issue1867-lowmem/source/app.d new file mode 100644 index 0000000..c3eec7f --- /dev/null +++ b/test/issue1867-lowmem/source/app.d @@ -0,0 +1,6 @@ +import std.stdio; + +void main() +{ + writeln("Edit source/app.d to start your project."); +}