Skip to content

🐛 Allow passing extra_libs to CheckLibWithHeader#4676

Merged
bdbaddog merged 13 commits intoSCons:masterfrom
rdbisme:extra-libs
Feb 15, 2025
Merged

🐛 Allow passing extra_libs to CheckLibWithHeader#4676
bdbaddog merged 13 commits intoSCons:masterfrom
rdbisme:extra-libs

Conversation

@rdbisme
Copy link
Contributor

@rdbisme rdbisme commented Jan 26, 2025

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt and RELEASE.txt (and read the README.rst).
  • I have updated the appropriate documentation

@mwichmann
Copy link
Collaborator

The concept seems good... not sure why that argument was left out of the upper layer when it's present in the lower layer (Conftest.py). Could ask the same question about SConf/CheckLib.

@rdbisme
Copy link
Contributor Author

rdbisme commented Jan 26, 2025

First time I contribute to scons. Do I need to add a specific test for this?

@bdbaddog
Copy link
Contributor

First time I contribute to scons. Do I need to add a specific test for this?

Yes. That's why we have the checklist in the initial decription.
You can edit it and add an X next to each item once you've added it.

@bdbaddog
Copy link
Contributor

And add this change to the docs as well.
We'll help you through those if you need help.
Also asking on the discord server may be useful.

@rdbisme
Copy link
Contributor Author

rdbisme commented Jan 26, 2025

Yes. That's why we have the checklist in the initial decription.
You can edit it and add an X next to each item once you've added it.

I mean, my remark was more like that test wouldn't test much? CheckLib already has that argument. I'm just exposing it in the interface of CheckLibWithHeadere, but I'll give a look to the tests. :)

@rdbisme
Copy link
Contributor Author

rdbisme commented Jan 26, 2025

I should have added all things required. I'm not 100% sure about the doc (XML, really?! :)).

@mwichmann
Copy link
Collaborator

Yes, xml, really :-) (this project dates back just a few years, like 20+). We can help with docs, there's not really much to do there for this kind of change.

The configure stuff is a weird two-layer thing, SConf is the "API layer" and Conftest is the implementation layer. Except, they reach into each other and aren't as separated as they could be. Not making excuses.

if not supplied,
the default checks the ability to link against the specified
<parameter>library</parameter>.
<parameter>extra_libs</parameter> can be used to add additional libraries to link against.
Copy link
Contributor

Choose a reason for hiding this comment

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

@mwichmann - what's the blurb to indicate this is added in NEXT_RELEASE?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the xml files are not processed by Sphinx, it needs the hand-crafted version:

<para>
<emphasis>Changed in version NEXT_RELEASE:</emphasis>
Added the <parameter>extra_libs</parameter> parameter.
</para>

It's a little unclear whether an existing method getting a new parameter is considered "added" or "changed". I'm tending to follow what CPython does, which is to consider that "changed" (though I admit that's not been consistent).

The corresponding markup in source code (aka the docstring) is:

.. versionchanged:: NEXT_RELEASE
    Added the  *extra_libs* parameter.

@mwichmann
Copy link
Collaborator

Still think this should be added to SCons.SConf.CheckLib as well.

@mwichmann mwichmann added the Configure any issues related to Configure contexts label Jan 27, 2025
@mwichmann
Copy link
Collaborator

If I can figure out how to do it, I'm going to push an update to this that

  • also enables extra_libs for the CheckLib API,
  • adds the version-added rst to the docstrings
  • adds the version-added xml and the `extra_libs addition to the manpage, plus tweaks a little bit (trying to resist doing more this time!)

@mwichmann
Copy link
Collaborator

Hmmm, I just spotted that this isn't passing on the Windows CI:

 213/1250 (17.04%) C:\hostedtoolcache\windows\Python\3.12.8\x64\python.exe test\Configure\CheckLibWithHeader_extra_libs.py
D:\a\scons\scons\scripts\scons.py returned 2
STDOUT =========================================================================
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /FolibB.obj /c libB.c /nologo /IC:\Users\RUNNER~1\AppData\Local\Temp\scons\testcmd.5912.50_ghoo6\libA
libB.c
link /nologo /dll /out:libB.dll /implib:libB.lib /LIBPATH:C:\Users\RUNNER~1\AppData\Local\Temp\scons\testcmd.5912.50_ghoo6\libA A.lib libB.obj
LINK : fatal error LNK1181: cannot open input file 'A.lib'
scons: building terminated because of errors.

STDERR =========================================================================
scons: *** [libB.dll] Error 1181

Will investigate soon if someone doesn't get there first...

@mwichmann
Copy link
Collaborator

Need some guidance here... on Windows you have to link against the .lib version, which doesn't even build... not sure how this is supposed to work.

Manpage entries and docstrings updated with version-added specifiers.

Signed-off-by: Mats Wichmann <mats@linux.com>
Add boilderplate header/footer, fix one place where the wrong
(non-portable) name for a library was used.  Still does not
build on Windows, due to mismatch between .dll/.lib construction.

Signed-off-by: Mats Wichmann <mats@linux.com>
"Muscle memory" had me add calls to skip tools for DefaultEnvironment,
but the two library builds use it, so that was just plain wrong.
Restored prior state.

Signed-off-by: Mats Wichmann <mats@linux.com>
@jcbrill
Copy link
Contributor

jcbrill commented Feb 9, 2025

@mwichmann My guess is that A.dll does not export any symbols; therefore, an import library is not generated.

@mwichmann
Copy link
Collaborator

@mwichmann My guess is that A.dll does not export any symbols; therefore, an import library is not generated.

That's certainly true for the test file in the PR. I've added those in a worktree here, and it still doesn't, so I think I must be doing something wrong with that.

@jcbrill
Copy link
Contributor

jcbrill commented Feb 9, 2025

The following builds libA with MSVC from the command-line outside of the test. It correctly produces the A.lib file. I haven't checked to see if it breaks gnu/gcc yet. It shouldn't but one never knows.

libA/libA.h:

#ifdef _MSC_VER
  #ifdef BUILDINGSHAREDLIB
    #define MYAPI __declspec(dllexport)
  #else
    #define MYAPI __declspec(dllimport)
  #endif
#else
  #define MYAPI
#endif

MYAPI void libA();

libA/libA.c:

#include <stdio.h>
#include "libA.h"

MYAPI void libA() {
    printf("libA\\n");
}

libA/SConstruct:

SharedLibrary('A', source=['libA.c'], CPPDEFINES="BUILDINGSHAREDLIB")

I updated the test and it failed though.

P.S.: pretty sure the extra backslash in the print statement is erroneous.

@mwichmann
Copy link
Collaborator

@mwichmann My guess is that A.dll does not export any symbols; therefore, an import library is not generated.

That's certainly true for the test file in the PR. I've added those in a worktree here, and it still doesn't, so I think I must be doing something wrong with that.

I have an alternate independently developed example which does work, so later I'll reconcile the two and hopefully find what errors I made adjusting the original.

@mwichmann
Copy link
Collaborator

The following builds libA with MSVC from the command-line outside of the test. It correctly produces the A.lib file. I haven't checked to see if it breaks gnu/gcc yet. It shouldn't but one never knows.

libA/libA.h:

#ifdef _MSC_VER
  #ifdef BUILDINGSHAREDLIB
    #define MYAPI __declspec(dllexport)
  #else
    #define MYAPI __declspec(dllimport)
  #endif
#else
  #define MYAPI
#endif

MYAPI void libA();

libA/libA.c:

#include <stdio.h>
#include "libA.h"

MYAPI void libA() {
    printf("libA\\n");
}

libA/SConstruct:

SharedLibrary('A', source=['libA.c'], CPPDEFINES="BUILDINGSHAREDLIB")

I updated the test and it failed though.

P.S.: pretty sure the extra backslash in the print statement is erroneous.

yes, that looks like what it should want. And the backslash is left over from when it was a string-print in the testcase, once listed as raw-string, then not, then I think put back. Anyway, this should be enough to wrap it up.

@jcbrill
Copy link
Contributor

jcbrill commented Feb 9, 2025

Attached is a version of test/Configure/CheckLibWithHeader_extra_libs.py which appears to pass on Windows using msvc and WSL using gcc.

CheckLibWithHeader_extra_libs.zip

In hindsight, the double backslash may be necessary in the test since it is not inside a raw string (e.g., r""").

@mwichmann
Copy link
Collaborator

Attached is a version of test/Configure/CheckLibWithHeader_extra_libs.py which appears to pass on Windows using msvc and WSL using gcc.

CheckLibWithHeader_extra_libs.zip

In hindsight, the double backslash may be necessary in the test since it is not inside a raw string (e.g., r""").

thanks. I have one working here, but will look over.

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann
Copy link
Collaborator

Okay, this should be working now. Thanks to @jcbrill for confirming that what I was figuring out was on a workable path.

@rdbisme
Copy link
Contributor Author

rdbisme commented Feb 13, 2025

Thanks for bringing this forward :)

Signed-off-by: Mats Wichmann <mats@linux.com>
SharedLibrary(target='A', source=['libA.c'], CPPDEFINES='BUILDINGSHAREDLIB')
""",
)
test.dir_fixture(['fixture', 'checklib_extra', 'libA'], 'libA')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should just be able to do this once as
test.dir_fixture(['fixture', 'checklib_extra'])

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose. If you think it's worth doing yet another iteration...

@bdbaddog bdbaddog merged commit 2a85d9e into SCons:master Feb 15, 2025
6 of 8 checks passed
@mwichmann mwichmann added this to the 4.9 milestone Feb 15, 2025
Yakkhini added a commit to OpenXiangShan/GEM5 that referenced this pull request Jan 21, 2026
For better compatibility with Scons version 4.9.0 and after.

See also:

* GEM5 upstream repository PR: gem5/gem5#2080
* SCons break change: SCons/scons#4676

Change-Id: I0082f1b12d6afc25e0791673cd8f7d4c400d8644
Yakkhini added a commit to OpenXiangShan/GEM5 that referenced this pull request Jan 22, 2026
For better compatibility with Scons version 4.9.0 and after.

See also:

* GEM5 upstream repository PR: gem5/gem5#2080
* SCons break change: SCons/scons#4676

Change-Id: I0082f1b12d6afc25e0791673cd8f7d4c400d8644
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Configure any issues related to Configure contexts

Projects

No open projects
Status: Complete

Development

Successfully merging this pull request may close these issues.

4 participants