Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform probing can be replaced with dmd -Xi=compilerInfo -Xf=- for newer compilers #1317

Open
wilzbach opened this issue Dec 26, 2017 · 10 comments

Comments

@wilzbach
Copy link
Member

Flow:

dub/source/dub/commandline.d

Lines 1012 to 1032 in cea2f15

override int execute(Dub dub, string[] free_args, string[] app_args)
{
enforceUsage(
!(m_importPaths && m_stringImportPaths),
"--import-paths and --string-import-paths may not be used together."
);
enforceUsage(
!(m_data && (m_importPaths || m_stringImportPaths)),
"--data may not be used together with --import-paths or --string-import-paths."
);
// disable all log output to stdout and use "writeln" to output the JSON description
auto ll = getLogLevel();
setLogLevel(max(ll, LogLevel.warn));
scope (exit) setLogLevel(ll);
string package_name;
enforceUsage(free_args.length <= 1, "Expected one or zero arguments.");
if (free_args.length >= 1) package_name = free_args[0];
setupPackage(dub, package_name);

protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug")
{
if (!m_compilerName.length) m_compilerName = dub.defaultCompiler;
m_compiler = getCompiler(m_compilerName);
m_buildPlatform = m_compiler.determinePlatform(m_buildSettings, m_compilerName, m_arch);

BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override)
{
string[] arch_flags;
switch (arch_override) {
default: throw new Exception("Unsupported architecture: "~arch_override);
case "": break;
case "x86": arch_flags = ["-m32"]; break;
case "x86_64": arch_flags = ["-m64"]; break;
case "x86_mscoff": arch_flags = ["-m32mscoff"]; break;
}
settings.addDFlags(arch_flags);
return probePlatform(compiler_binary, arch_flags ~ ["-quiet", "-c", "-o-"], arch_override);

protected final BuildPlatform probePlatform(string compiler_binary, string[] args, string arch_override)
{
import std.string : format;
import dub.compilers.utils : generatePlatformProbeFile, readPlatformProbe;
auto fil = generatePlatformProbeFile();

NativePath generatePlatformProbeFile()
{
import dub.internal.vibecompat.core.file;
import dub.internal.vibecompat.data.json;
import dub.internal.utils;
auto path = getTempFile("dub_platform_probe", ".d");

Probably it could be something simple as the timestamp of the compiler binary.
How about ~/.dub/compilers/<dmd|ldc|gdc>_timestamp?

Related PRs:

@MartinNowak
Copy link
Member

It took ~5ms last time I optimized it, hardly worth caching. Of course in the mean-time it was changed to import phobos again.

@MartinNowak
Copy link
Member

#1318

@wilzbach
Copy link
Member Author

It took ~5ms last time I optimized it, hardly worth caching.

But isn't this probing done on every DUB invocation?

@FeepingCreature
Copy link
Contributor

FeepingCreature commented Mar 19, 2018

It took ~5ms last time I optimized it, hardly worth caching.


edit: Nevermind, it's dub in general, not the probe invocation. Misread the strace, carry on.

@wilzbach
Copy link
Member Author

FWIW dmd now supports dmd -Xi=compilerInfo -Xf=- since 2.079 which allows to avoid the entire probing.

@wilzbach wilzbach reopened this Mar 19, 2018
@wilzbach wilzbach changed the title Platform probing should be cached Platform probing can be replaced with dmd -Xi=compilerInfo -Xf=- for newer compilers Mar 19, 2018
@wilzbach
Copy link
Member Author

@FeepingCreature note that the officially released dub binary still isn't build with LDC. You might want to build it with LDC locally for a huge speedup for "free"

@wilzbach
Copy link
Member Author

Example: https://run.dlang.io/is/DiSyCl

@FeepingCreature
Copy link
Contributor

Good idea, thank you!

@andre2007
Copy link
Contributor

Can the probe result be stored in a cache file? On linux calling another executable is cheap but on windows with a OnAccess virus scanner this makes the single package file scenario slower.

@wilzbach
Copy link
Member Author

wilzbach commented Dec 6, 2019

Can the probe result be stored in a cache file?

I don't see any reason why it couldn't. I guess even just the timestamp and size of the compiler binary should be good enough for most (all?) probe caching purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants