Compile V8

目前游戏中普遍使用Lua作为脚本语言,Lua由纯粹的C实现,无任何外部依赖, 代码量较小,
无论是PC游戏还是移动游戏都能很好地适用, 其工具链也较为完善.
但仍有部分缺陷难以解决, 比如代码重构, lua文件较多时,对于函数改名等操作是非常困难的,
只能通过人工检查和运行时验证等手段, 缺少精确的方案(由于其动态性决定);另外,LuaJIT跟标准Lua差异越来越大,
在侧重性能的情况下只能选择LuaJIT, 但目前二者差异越来越大, 一些第三方代码并未同时兼容二者,
在接入LuaJIT时需要自行修改,很不方便.
故此, 有必要考虑其他的脚本语言, 在选择上首先要考虑语言的广泛性, 太小众的维护成本太大;
在性能上, 有明显的优势,或者有JIT模式. 筛选之下, 目前可行大概有Python, .Net, JavaScript这三种.
对于Python语言, 广泛性不必多言, 还有个最大的优势是UE4已经内部集成了Python插件,即开即用;
在性能上相对不足, 其JIT实现目前似乎没有一个标记标准的方案. .Net已经由Unity3D大量使用, C#性能也非常出色,
几乎是最理想的选择, GitHub也有人接入了UE4引擎; 在跨平台方面有mono方案, 不过目前mono似乎不太友好, Unity3D已有放弃趋势.
此外JavaScript需要格外关注,几年前NCSoft开源了Unreal.JS插件,
使用V8引擎, 不过当时V8在跨平台上有些缺陷(主要是IOS),因此Unreal.JS难以真正用于最终产品;
后来又有purets插件,也是基于V8引擎,实现了跨平台(最近V8更新后可以在IOS上运行, Unreal.JS也跟进提供了IOS支持),
本次先尝试将V8接入UE4.
本文先一编译V8开始.
V8的代码组织跟其他开源代码稍有区别,V8采用了专用的过程组织方式, 不是常见的cmake或makefile, 这就给编译带来了极大的不便,此处先记录下关键点.
因为要构建多个平台的链接库,因此不能直接在自己的机器上执行,目前最好的环境可能就是Github Action了,
提供windows/Linux/Mac 三种环境,当然最关键是免费.
...
先记录下在Windows上的构建脚本

# This is a basic workflow to help you get started with Actions

name: Windows_BuildV8

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: master
  pull_request:
    branches: master
  watch:
    types: started

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: windows-latest
    env:
      working-directory: ${{github.workspace}}

    if: github.event.repository.owner.id == github.event.sender.id


    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
     
      # download & unzip depot_tools
      - name: download & unzip depot_tools
        shell: cmd
        working-directory: ${{env.working-directory}}
        run: |
          curl https://storage.googleapis.com/chrome-infra/depot_tools.zip  >./depot_tools.zip
          mkdir depot_tools 
          cd depot_tools
          tar -xf ../depot_tools.zip
          gclient
          
          
     # checkut & build V8
      - name: checkut & build V8
        shell: powershell
        working-directory: ${{env.working-directory}}
        run: |
          echo on
          $ENV:vs2019_install="C:Program Files (x86)Microsoft Visual Studio2019Enterprise"
          $ENV:DEPOT_TOOLS_WIN_TOOLCHAIN="0"
          $ENV:PATH="${{env.working-directory}}depot_tools;$ENV:PATH"
          
          echo "begin fetch V8"
          fetch V8
          echo "end fetch V8"
          
          cd V8
          
          echo "begin gclient sync"
          gclient sync
          echo "end gclient sync"
          
          python tools/dev/gm.py x64.release
原文地址:https://www.cnblogs.com/rpg3d/p/14040071.html