Skip to content

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Dec 26, 2017

DUB creates a special platform probe file on every invocation, (more details).

(determinePlatform is called by setupPackage in execute)

While DUB should cache this invocation, I think there should be a "standard" format for feature detection instead of using this hack to generate a D file with version identifiers.
This PR generates the same output as the generated DUB probing file, e.g.:

{

    "compiler": "dmd",
    "frontendVersion": 2078,
    "compilerFrontend": "v2.078.0-beta.1-113-g057aa4442",
    "config": null,
    "binary": "/home/seb/dlang/dmd/generated/linux/release/64/dmd",
    "platform": [
        "posix",
        "linux"
    ],
    "architecture": [
        "x86_64"
    ],
    "predefinedVersions": [
        "DigitalMars",
        "Posix",
        "linux",
        "ELFv1",
        "LittleEndian",
        "D_Version2",
        "all",
        "D_SIMD",
        "D_InlineAsm_X86_64",
        "X86_64",
        "CRuntime_Glibc",
        "D_LP64",
        "D_PIC",
        "assert",
        "D_HardFloat"
    ]
}

(I didn't add this flag to the documentation, s.t. it can stay an experiment)

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@wilzbach
Copy link
Contributor Author

(CC @s-ludwig who is using this in DUB)


private void determinePlatform(void delegate(string) print)
{
version(Windows) print("windows");
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. Don't you want to print target information, not host?


private void determineArchitecture(void delegate(string) print)
{
version(X86) print("x86");
Copy link
Member

Choose a reason for hiding this comment

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

Likewise here.

* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/mars.d, _mars.d)
* Documentation: https://dlang.org/phobos/dmd_mars.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/mars.d
Copy link
Contributor

Choose a reason for hiding this comment

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

This documentation header seems to be cut and pasted from mars.d, but needs to be updated for this file.

else version(GNU) return "gdc";
else version(LDC) return "ldc";
else version(SDC) return "sdc";
else return null;
Copy link
Contributor

@mathias-lang-sociomantic mathias-lang-sociomantic Dec 29, 2017

Choose a reason for hiding this comment

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

That also looks wrong, since it gives the name of the compiler used to compile this file.

version(SH64) print("sh64");
version(Alpha) print("alpha");
version(Alpha_SoftFP) print("alpha_softfp");
version(Alpha_HardFP) print("alpha_hardfp");
Copy link
Contributor

Choose a reason for hiding this comment

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

Then leave it out ? No point in faking support, especially given those targets are more likely to be subject to cross compilation.

@s-ludwig
Copy link
Member

Wouldn't slightly a more generic functionailty make more sense, where simply all predefined versions are dumped to stdout?

@ibuclaw
Copy link
Member

ibuclaw commented Dec 29, 2017

Wouldn't slightly a more generic functionailty make more sense, where simply all predefined versions are dumped to stdout?

They are with -v.

dmd/src/dmd/mars.d

Lines 1428 to 1437 in a6515d1

private void printPredefinedVersions()
{
if (global.params.verbose && global.params.versionids)
{
fprintf(global.stdmsg, "predefs ");
foreach (const s; *global.params.versionids)
fprintf(global.stdmsg, " %s", s);
fprintf(global.stdmsg, "\n");
}
}

@wilzbach wilzbach force-pushed the probing branch 3 times, most recently from aa118b4 to 0900e80 Compare December 29, 2017 15:16
@wilzbach
Copy link
Contributor Author

They are with -v.

It doesn't do this anymore: #7549

Wouldn't slightly a more generic functionailty make more sense, where simply all predefined versions are dumped to stdout?

Good idea (done), but I think you will still need things like frontendVersion for DUB too, right?

@s-ludwig
Copy link
Member

s-ludwig commented Jan 4, 2018

Good idea (done), but I think you will still need things like frontendVersion for DUB too, right?

True, would be good to avoid another process invocation for that (--version), at least on Windows...

@wilzbach
Copy link
Contributor Author

wilzbach commented Jan 8, 2018

@s-ludwig so -probe would work for you? Anything else that's missing/blocking?

@timotheecour
Copy link
Contributor

timotheecour commented Jan 20, 2018

how about a more flexible way to output exactly what we want:

  • -probe=version,import,default_version,deps,file=out.txt (etc, easily extensible without breaking client clode)
  • it would output in json (easier to parse) (or maybe allow -probe=...,format=txt)
  • if file is not specified, goes to stdout
  • advantage: if some probes are large or slow down compilation, could be wasteful to add them unless they're explicitly asked for.

NOTE: -v can't change too much unfortunately for backward compatibility reasons, but -probe could be well designed since we're starting from scratch and future proof.

NOTE: precedent for this:
dub describe --data="lflags, libs, linker-files" (similar syntax)

FYI @marler8997 @wilzbach @s-ludwig

@marler8997
Copy link
Contributor

graphql for dmd :)

@timotheecour
Copy link
Contributor

could -Xf (json output) used instead of introducing another -probe flag? (cf #7757)

@wilzbach
Copy link
Contributor Author

wilzbach commented Jan 22, 2018

how about a more flexible way to output exactly what we want:

I like the idea, but isn't this an overkill? The JSON file is really tiny at the moment (see the first comment) and it's unlikely that it will get bigger

NOTE: -v can't change too much unfortunately for backward compatibility reasons, but -probe could be well designed since we're starting from scratch and future proof.

I don't see why - if this advanced selection was ever needed - it couldn't be added to -probe. After all, -probe currently takes no argument and detecting the special case when a user gives it an argument isn't too hard.

could -Xf (json output) used instead of introducing another -probe flag?

Problems I see

  • -probe doesn't require a file input and won't do any serious work. Thus it's very cheap to call. It's like -version
  • -probe uses stdout by default
  • you proposed to allow alternative formats for -probe - how would that work with -Xf?

We could rename -probe to e.g. -version=json if you don't like to have a new flag.

@CyberShadow
Copy link
Member

I like Timothee's idea from here, where dmd -Xf without input files produces the same information as -probe would. It would mean one less switch and one less format, and would let programs that need to compile something and get compiler information to do so with one compiler invocation.

@timotheecour
Copy link
Contributor

the link u gave is wrong, I think you meant dlang/tools#292 (comment) :)

@marler8997
Copy link
Contributor

Alternative to -probe submitted here: #7838

@wilzbach
Copy link
Contributor Author

Superseded by #7894

@wilzbach wilzbach closed this Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants