Skip to content

Windows builds fail to link C++ static library #107162

Description

@jdm

Code

Building the mozjs crate for any Windows target stopped working after #97485. mozjs has a build script that compiles the C++ library SpiderMonkey into js_static.a, which is then linked. Before #97485, these builds worked successfully. Since that PR was merged, CI using nightly and beta toolsets targeting MSVC x86_64 and UWP x86_64 now fail to build with the following error:

error: failed to add native library D:\a\mozjs\mozjs\target\debug\build\mozjs_sys-4062d5cd7cbc7110\out\build/js/src/build\js_static.lib: Unsupported archive identifier

This was first reported in servo/mozjs#327 and servo/mozjs#334.

Version it worked on

2022-12-03 nightly
Rust 1.66 beta

Version with regression

2022-12-04 nightly
Rust 1.67 beta

If you know when this regression occurred, please add a line like below, replacing {channel} with one of stable, beta, or nightly.

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Jan 21, 2023
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Jan 21, 2023
  3. jyn514 commented on Jan 22, 2023

    @jyn514
    Member
  4. bjorn3 commented on Jan 22, 2023

    @bjorn3
    Member

    As workaround adding windows to

    if sess.target.arch == "wasm32" || sess.target.arch == "wasm64" {
    should revert back to the old archive writer. Luckily it was preserved for wasm.

    Could you post a hex dump of the first 16 or so bytes of the js_static.lib archive to see the magic bytes of this file.

  5. sagudev commented on Jan 22, 2023

    @sagudev
    Contributor

    Here is hexdump:

    0000000 3c21 6874 6e69 0a3e 202f 2020 2020 2020
    0000010 2020 2020 2020 2020 2030 2020 2020 2020
    

    Here is GitHub action of working one: https://github.com/sagudev/mozjs/actions/runs/3974783209 and here is GitHub action of defect one: https://github.com/sagudev/mozjs/actions/runs/3974683394. Artifact contains .lib file, that is produced in windows job.

  6. bjorn3 commented on Jan 22, 2023

    @bjorn3
    Member

    Yeah, that is indeed very much not a valid archive.

    ┌────────┬─────────────────────────┬────────┐
    │00000000│ 3c 21 68 74 6e 69 0a 3e │<!htni_>│
    │00000008│ 20 2f 20 20 20 20 20 20 │ /      │
    │00000010│ 20 20 20 20 20 20 20 20 │        │
    │00000018│ 20 30 20 20 20 20 20 20 │ 0      │
    └────────┴─────────────────────────┴────────┘
    

    It does look like !<thin>\n (which is a valid header for thin archives) except with every pair of bytes swapped. Rustc also shouldn't be producing thin archives.

  7. sagudev commented on Jan 22, 2023

    @sagudev
    Contributor

    Well hex-editor in vscode shows it right (but hexdump is showing reversed bits on same file):
    slika

  8. mati865 commented on Jan 22, 2023

    @mati865
    Member

    Do you know if this affects all Windows targets or just MSVC based?
    I couldn't get it to build at all with windows-gnu:

    $ LANG=C.utf8 cargo t
       Compiling mozjs_sys v0.68.2 (D:\tmp\mozjs\mozjs)
    error: failed to run custom build command for `mozjs_sys v0.68.2 (D:\tmp\mozjs\mozjs)`
    
    Caused by:
      process didn't exit successfully: `D:\tmp\mozjs\target\debug\build\mozjs_sys-352d87b28c39ffac\build-script-build` (exit code: 101)
      --- stdout
      cargo:outdir=D:\tmp\mozjs\target\debug\build\mozjs_sys-27c0928751302e7b\out\build
    
      --- stderr
      make: invalid --jobserver-auth string '__rust_jobserver_semaphore_2019855554'
      make: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
      D:\tmp\mozjs\mozjs\makefile.cargo:175: *** recipe commences before first target.  Stop.
      thread 'main' panicked at 'assertion failed: result.success()', mozjs\build.rs:178:5
      note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    
  9. sagudev commented on Jan 22, 2023

    @sagudev
    Contributor

    Ideally we would want to find another case for regression, because mozjs is complicated.
    @mati865 Do you have MozillaBuild 3.4 installed as error is in makefile.cargo:175 and MozBuild comes packaged with python? I suggest looking at GitHub Workflows to correctly setup for compiling.

  10. mati865 commented on Jan 24, 2023

    @mati865
    Member

    @mati865 Do you have MozillaBuild 3.4 installed as error is in makefile.cargo:175 and MozBuild comes packaged with python?

    No, I had checked first step in the readme but the link is dead:

    Follow the directions at https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Windows_Prerequisites

  11. sagudev commented on Jan 24, 2023

    @sagudev
    Contributor

    Well, those instruction would not be relevant anymore as we are still few SM versions behind if they would be available. Following GitHub Workflows is currently the best way.

  12. 27 remaining items

  13. added and removed on Feb 16, 2023
  14. wesleywiser commented on Feb 16, 2023

    @wesleywiser
    Member

    Downgrading to P-medium as we've shipped a point release with this fix. Leaving open as we would love a regression test to be added.

  15. Mark-Simulacrum commented on Mar 3, 2023

    @Mark-Simulacrum
    Member

    Untagging as a regression, since this has been fixed on beta + stable + nightly at this point as far as I can tell.

  16. added 3 commits that reference this issue on Aug 12, 2024
  17. added 3 commits that reference this issue on Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.O-windows-msvcToolchain: MSVC, Operating system: WindowsP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions