Skip to content
New issue

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

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

Already on GitHub? # to your account

quickjs is not compatible with ucrt of Windows SDK 26100 #622

Closed
twinstar6980 opened this issue Oct 25, 2024 · 14 comments
Closed

quickjs is not compatible with ucrt of Windows SDK 26100 #622

twinstar6980 opened this issue Oct 25, 2024 · 14 comments

Comments

@twinstar6980
Copy link

twinstar6980 commented Oct 25, 2024

The macro definition NAN is used in quickjs.c.
https://github.com/quickjs-ng/quickjs/blob/0c8aeb1d5093869479e914980ef5588020bce64a/quickjs.c#L40297

For Windows platform, NAN is defined in ucrt/corecrt_math.h.
In Windows SDK 22621:

#define NAN ((float)(INFINITY * 0.0F))

In this case, the compiler can complete the compilation, but Microsoft has made changes in Windows SDK 26100:

#define _UCRT_NAN (__ucrt_int_to_float(0x7FC00000))
#define NAN _UCRT_NAN

When using SDK 26100, the compiler (msvc-cl 19.41 or clang-cl 19.1) will report an error: C2099 initializer is not a constant.

Is there any way to solve this problem?

@695137400
Copy link

我最初也是用终端控制台编译,会报错,后来改用了clion,直接导入cmake项目就行,不报错,完美

@twinstar6980
Copy link
Author

我最初也是用终端控制台编译,会报错,后来改用了clion,直接导入cmake项目就行,不报错,完美

你的clion用的是minggw还是msvc全家桶?能麻烦下在clion里看看NAN是怎么定义的么?

@twinstar6980
Copy link
Author

I tested the value of NAN under different conditions:
/fp:precise(default)
(-)22621: fff8000000000000
(+)22621(_UCRT_NEGATIVE_NAN): 7ff8000000000000
(-)26100(_UCRT_NOISY_NAN): fff8000000000000
(+)26100(_UCRT_NOISY_NAN,_UCRT_NEGATIVE_NAN): 7ff8000000000000
(+)26100: 7ff8000000000000
(-)26100(_UCRT_NEGATIVE_NAN): fff8000000000000

Even if defined _UCRT_NOISY_NAN, NAN is also quiet (why not noisy/signaling?). If /fp:strict is enabled, 22621 and 26100(_UCRT_NOISY_NAN) will produce positive NAN values.

I don't know if the behavior of quickjs depends on the specific value of NAN. If not, should we add _UCRT_NOISY_NAN macro definition in cmake to be compatible with sdk26100?

@saghul
Copy link
Contributor

saghul commented Oct 25, 2024

Interesting! Do you know how to use that version in a GH Action so we can add a CI?

@twinstar6980
Copy link
Author

Interesting! Do you know how to use that version in a GH Action so we can add a CI?

maybe you can use this repo: https://github.com/GuillaumeFalourd/setup-windows10-sdk-action

@saghul
Copy link
Contributor

saghul commented Oct 25, 2024

Looks like 26100 doesn't work though: (26100 returns an error)

@695137400
Copy link

2024-10-25_155809

@695137400
Copy link

2024-10-25_160422

@saghul
Copy link
Contributor

saghul commented Oct 25, 2024

Not sure what you're asking here.

@twinstar6980
Copy link
Author

Looks like 26100 doesn't work though: (26100 returns an error)

Try this: https://github.com/marketplace/actions/windows-sdk-install
I did a simple test and it was able to install sdk26100 successfully.

@twinstar6980
Copy link
Author

2024-10-25_160422

emm,我不太了解 mingw ,这个错误是因为最新版本 winsdk ucrt 更改后的 NAN 宏不再能作为编译期常量来使用。你用 mingw 工具链没触发这个问题应该是因为 mingw 内部自己实现了 NAN 的定义,而没有走 ucrt 的 NAN 定义。这与这个 issue 无关。

@bnoordhuis
Copy link
Contributor

I don't know if the behavior of quickjs depends on the specific value of NAN

Yes. From libbf.c (handles BigInts):

quickjs/libbf.c

Lines 2463 to 2464 in 89883ae

if (a->expn == BF_EXP_NAN) {
u.u = 0x7ff8000000000000; /* quiet nan */

Changing JS_NAN also changes the output of JS_WriteObject, the serializer. That's not exactly fatal but it would be annoying to have two machines produce different output for the same input.

@twinstar6980
Copy link
Author

The WinSDK version can be set in CI via:

  - name: Install windows sdk
    uses: ChristopheLav/windows-sdk-install@v1
    with:
    version-sdk: 26100
    features: 'OptionId.DesktopCPPx86,OptionId.DesktopCPPx64'

And specify -DCMAKE_SYSTEM_VERSION:STRING=10.0.26100.0 in the cmake command line.

.
Regarding specific values ​​for nan:
In winsdk 22621 and earlier, the NAN macro produces negative nan (unless /fp:strict is specified), which does not seem to be the value expected by libbf. However, quickjs-ng has always worked this way on windows before winsdk 26100.
Specifying _UCRT_NOISY_NAN will revert the behavior of nan to that before 22621. If you don't want to use it, it seems that you must refactor the relevant code to not rely on the "compile-time constant" feature.

@saghul
Copy link
Contributor

saghul commented Nov 17, 2024

I'll try to get back to this next week!

saghul added a commit that referenced this issue Nov 18, 2024
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Nov 18, 2024
NAN is reportedly no longer a compile-time expression in some versions
of MSVC. Work around that by minting a NaN from a uint64.

Fixes: quickjs-ng#622
Fixes: quickjs-ng#693
bluesky950520 pushed a commit to bluesky950520/quickjs that referenced this issue Mar 14, 2025
NAN is reportedly no longer a compile-time expression in some versions
of MSVC. Work around that by minting a NaN from a uint64.

Fixes: quickjs-ng/quickjs#622
Fixes: quickjs-ng/quickjs#693
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants