| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a4edab8 commit f9bd016
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1780,6 +1780,14 @@ def configure_node(o): | |||
| 1780 | 1780 | o['variables']['target_arch'] = target_arch | |
| 1781 | 1781 | o['variables']['node_byteorder'] = sys.byteorder | |
| 1782 | 1782 | ||
| 1783 | + # On Windows, cargo may default to the GNU target (e.g. x86_64-pc-windows-gnu) | ||
| 1784 | + # but Node.js requires MSVC-compatible libraries. Set explicit Rust target | ||
| 1785 | + # triple for the target architecture. | ||
| 1786 | + o['variables']['cargo_rust_target'] = '' | ||
| 1787 | + if flavor == 'win': | ||
| 1788 | + o['variables']['cargo_rust_target'] = \ | ||
| 1789 | + 'aarch64-pc-windows-msvc' if target_arch == 'arm64' else 'x86_64-pc-windows-msvc' | ||
| 1790 | + | ||
| 1783 | 1791 | # Allow overriding the compiler - needed by embedders. | |
| 1784 | 1792 | if options.use_clang: | |
| 1785 | 1793 | o['variables']['clang'] = 1 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,60 @@ | |||
| 1 | + #!/usr/bin/env python3 | ||
| 2 | + | ||
| 3 | + """Invoke cargo with the correct Rust target on Windows cross-compilation. | ||
| 4 | + | ||
| 5 | + Works around three issues: GYP's MSVS generator mangles executable names in | ||
| 6 | + host-toolset actions (breaking direct cargo calls), GYP cannot set different | ||
| 7 | + variable values per toolset, and cargo's output directory layout uses Rust | ||
| 8 | + target triples while MSBuild expects platform names (x64/arm64). This script | ||
| 9 | + reads MSBuild's $(Platform) to select the right Rust target and copies the | ||
| 10 | + built library to a path MSBuild can resolve per-project. | ||
| 11 | + """ | ||
| 12 | + | ||
| 13 | + import os | ||
| 14 | + import shutil | ||
| 15 | + import subprocess | ||
| 16 | + import sys | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + def main(): | ||
| 20 | + # Arguments: <platform> <output_dir> [cargo_args...] | ||
| 21 | + if len(sys.argv) < 3: | ||
| 22 | + print('Usage: cargo_build.py <platform> <output_dir> [cargo_args...]', file=sys.stderr) | ||
| 23 | + sys.exit(1) | ||
| 24 | + | ||
| 25 | + platform = sys.argv[1] # x64 or arm64 | ||
| 26 | + output_dir = sys.argv[2] # SHARED_INTERMEDIATE_DIR | ||
| 27 | + cargo_args = sys.argv[3:] | ||
| 28 | + build_profile = 'release' if '--release' in cargo_args else 'debug' | ||
| 29 | + | ||
| 30 | + cargo = os.environ.get('CARGO', 'cargo') | ||
| 31 | + if not os.path.isabs(cargo) and shutil.which(cargo) is None: | ||
| 32 | + home = os.environ.get('USERPROFILE', '') | ||
| 33 | + cargo_home = os.path.join(home, '.cargo', 'bin', 'cargo.exe') | ||
| 34 | + if os.path.isfile(cargo_home): | ||
| 35 | + cargo = cargo_home | ||
| 36 | + | ||
| 37 | + rust_target_map = { | ||
| 38 | + 'x64': 'x86_64-pc-windows-msvc', | ||
| 39 | + 'arm64': 'aarch64-pc-windows-msvc', | ||
| 40 | + } | ||
| 41 | + rust_target = rust_target_map.get(platform) | ||
| 42 | + if rust_target is None: | ||
| 43 | + print(f'Unsupported platform: {platform}', file=sys.stderr) | ||
| 44 | + sys.exit(1) | ||
| 45 | + | ||
| 46 | + cmd = [cargo, 'rustc', '--target', rust_target, '--target-dir', output_dir] + cargo_args | ||
| 47 | + ret = subprocess.call(cmd) | ||
| 48 | + if ret != 0: | ||
| 49 | + sys.exit(ret) | ||
| 50 | + | ||
| 51 | + # Copy output to the platform-specific directory that MSBuild expects. | ||
| 52 | + src = os.path.join(output_dir, rust_target, build_profile, 'node_crates.lib') | ||
| 53 | + dst_dir = os.path.join(output_dir, platform, build_profile) | ||
| 54 | + os.makedirs(dst_dir, exist_ok=True) | ||
| 55 | + dst = os.path.join(dst_dir, 'node_crates.lib') | ||
| 56 | + shutil.copy2(src, dst) | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + if __name__ == '__main__': | ||
| 60 | + main() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,24 +2,46 @@ | |||
| 2 | 2 | 'variables': { | |
| 3 | 3 | 'cargo%': 'cargo', | |
| 4 | 4 | 'cargo_vendor_dir': './vendor', | |
| 5 | + 'cargo_rust_target%': '', | ||
| 5 | 6 | }, | |
| 6 | 7 | 'conditions': [ | |
| 7 | 8 | ['build_type == "Release"', { | |
| 8 | 9 | 'variables': { | |
| 9 | 10 | 'cargo_build_flags': ['--release'], | |
| 10 | - 'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/release/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)', | ||
| 11 | 11 | }, | |
| 12 | + 'conditions': [ | ||
| 13 | + ['cargo_rust_target!=""', { | ||
| 14 | + 'variables': { | ||
| 15 | + 'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/$(Platform)/release/node_crates.lib', | ||
| 16 | + }, | ||
| 17 | + }, { | ||
| 18 | + 'variables': { | ||
| 19 | + 'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/release/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)', | ||
| 20 | + }, | ||
| 21 | + }], | ||
| 22 | + ], | ||
| 12 | 23 | }, { | |
| 13 | 24 | 'variables': { | |
| 14 | 25 | 'cargo_build_flags': [], | |
| 15 | - 'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/debug/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)', | ||
| 16 | 26 | }, | |
| 27 | + 'conditions': [ | ||
| 28 | + ['cargo_rust_target!=""', { | ||
| 29 | + 'variables': { | ||
| 30 | + 'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/$(Platform)/debug/node_crates.lib', | ||
| 31 | + }, | ||
| 32 | + }, { | ||
| 33 | + 'variables': { | ||
| 34 | + 'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/debug/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)', | ||
| 35 | + }, | ||
| 36 | + }], | ||
| 37 | + ], | ||
| 17 | 38 | }] | |
| 18 | 39 | ], | |
| 19 | 40 | 'targets': [ | |
| 20 | 41 | { | |
| 21 | 42 | 'target_name': 'node_crates', | |
| 22 | 43 | 'type': 'none', | |
| 44 | + 'toolsets': ['host', 'target'], | ||
| 23 | 45 | 'hard_dependency': 1, | |
| 24 | 46 | 'sources': [ | |
| 25 | 47 | 'Cargo.toml', | |
@@ -39,29 +61,54 @@ | |||
| 39 | 61 | }], | |
| 40 | 62 | ], | |
| 41 | 63 | }, | |
| 42 | - 'actions': [ | ||
| 43 | - { | ||
| 44 | - 'action_name': 'cargo_build', | ||
| 45 | - 'inputs': [ | ||
| 46 | - '<@(_sources)' | ||
| 47 | - ], | ||
| 48 | - 'outputs': [ | ||
| 49 | - '<(node_crates_libpath)' | ||
| 64 | + 'conditions': [ | ||
| 65 | + ['cargo_rust_target!=""', { | ||
| 66 | + 'actions': [ | ||
| 67 | + { | ||
| 68 | + 'action_name': 'cargo_build', | ||
| 69 | + 'inputs': [ | ||
| 70 | + '<@(_sources)' | ||
| 71 | + ], | ||
| 72 | + 'outputs': [ | ||
| 73 | + '<(node_crates_libpath)' | ||
| 74 | + ], | ||
| 75 | + 'action': [ | ||
| 76 | + '<(python)', | ||
| 77 | + 'cargo_build.py', | ||
| 78 | + '$(Platform)', | ||
| 79 | + '<(SHARED_INTERMEDIATE_DIR)', | ||
| 80 | + '<@(cargo_build_flags)', | ||
| 81 | + '--frozen', | ||
| 82 | + ], | ||
| 83 | + } | ||
| 50 | 84 | ], | |
| 51 | - 'action': [ | ||
| 52 | - '<(cargo)', | ||
| 53 | - 'rustc', | ||
| 54 | - '<@(cargo_build_flags)', | ||
| 55 | - '--frozen', | ||
| 56 | - '--target-dir', | ||
| 57 | - '<(SHARED_INTERMEDIATE_DIR)' | ||
| 85 | + }, { | ||
| 86 | + 'actions': [ | ||
| 87 | + { | ||
| 88 | + 'action_name': 'cargo_build', | ||
| 89 | + 'inputs': [ | ||
| 90 | + '<@(_sources)' | ||
| 91 | + ], | ||
| 92 | + 'outputs': [ | ||
| 93 | + '<(node_crates_libpath)' | ||
| 94 | + ], | ||
| 95 | + 'action': [ | ||
| 96 | + '<(cargo)', | ||
| 97 | + 'rustc', | ||
| 98 | + '<@(cargo_build_flags)', | ||
| 99 | + '--frozen', | ||
| 100 | + '--target-dir', | ||
| 101 | + '<(SHARED_INTERMEDIATE_DIR)' | ||
| 102 | + ], | ||
| 103 | + } | ||
| 58 | 104 | ], | |
| 59 | - } | ||
| 105 | + }], | ||
| 60 | 106 | ], | |
| 61 | 107 | }, | |
| 62 | 108 | { | |
| 63 | 109 | 'target_name': 'temporal_capi', | |
| 64 | 110 | 'type': 'none', | |
| 111 | + 'toolsets': ['host', 'target'], | ||
| 65 | 112 | 'sources': [], | |
| 66 | 113 | 'dependencies': [ | |
| 67 | 114 | 'node_crates', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments