FreeBSD 系统里使用ports 源代码系统编译安装VSCode

FreeBSD 14.2系统pkg升级到2.x后,很多软件都没有pkg安装包了,比如Xfce4-desktop,然后发现本机的VSCode也没有了。

于是尝试安装VSCode,发现这个也没有pkg包,pkg search vscode 找不到。

没办法,只好尝试在FreeBSD的ports里编译安装。ports系统介绍参见:第十七回 美髯公智稳插翅虎 宋公明私放晁天王-FreeBSD下的ports软件包管理系统-CSDN博客

ports源代码更新参见:使用portsnap进行ports源代码更新@FreeBSD_freebsd 14 portsnap-CSDN博客

编译安装VSCode

常规make 编译

FreeBSD系统下编译安装软件非常方便,安装好ports源代码后,使用whereis民工找到源代码的位置:
 

whereis vscode
vscode: /usr/ports/editors/vscode

然后进入源代码位置,直接make install即可。命令:

cd /usr/ports/editors/vscode
sudo make install clean

坎坷经历

刚开始碰到了极大的阻力,vscode需要electron34,electron34需要chromium-132,还需要node-20 ....总之编译好这些软件,即使顺利也需要很多时间,更何况不顺利!

幸好最后修改了pkg使用latest,electron34等软件都可以pkg安装了,先pkg安装:

pkg install electron34 krb5

一次性进程配置

由于关联软件太多,一个个config起来非常麻烦,于是用了这句:

make config-recursive

这样尽管还是需要确认,但是可以一口气全部确认完毕,而不用像以前,确认-等待下载软件,然后再进行配置-确认,再下载软件,整个过程非常耗费时间。

配置完成后,进行编译!

编译过程

运行make或者运行:

make install

到了这里会停顿一些时间,没有输出:

> code-oss-dev@1.99.2 gulp
> node --max-old-space-size=8192 ./node_modules/gulp/bin/gulp.js vscode-linux-x64-min

[21:21:35] Using gulpfile ~/vscode-1.99.2/gulpfile.js
[21:21:35] Starting 'vscode-linux-x64-min'...
[21:21:35] Starting clean-out-build ...
[21:21:35] Finished clean-out-build after 62 ms
[21:21:35] Starting build-date-file ...
[21:21:35] Finished build-date-file after 3 ms
[21:21:35] Starting compile-api-proposal-names ...
[21:21:35] Starting compilation api-proposal-names...
[21:21:37] Finished compilation api-proposal-names with 0 errors after 1314 ms
[21:21:37] Finished compile-api-proposal-names after 1406 ms
[21:21:37] Starting compile-src ...
[21:22:37] [mangler] Done collecting. Classes: 8580. Exported symbols: 10525
[21:22:41] [mangler] Done creating class replacements
[21:22:41] [mangler] Starting prepare rename edits
[21:22:44] Starting compilation...

现在获得的知识是:

使用8G内存机器编译很勉强,前面很多次都没有成功,后来多编译了几次,终于有一次编译成功了!需要把swap设为10G或以上。

16G内存机器应该是更好些。但是编译了5-6个小时后,也报错signel 9 。且每次编译3个小时,都卡在那里(没有什么输出信息),暂时放弃。

 从编译编译的时长来看,感觉Intel的5代cpu:Intel Core i5-5200U @ 2.20GHz ,编译速度竟然快快过了Intel至强E5 2643 v2 @3.5G 在VirtualBox里的8核系统。也可能是5代cpu那台系统里以前编译过好几次的原因。

最后编译生成文件:

/usr/ports/editors/vscode/work/VSCode-linux-x64 % ls -l
total 240475
drwxr-xr-x  2 root wheel         3  4月 17 18:56 bin
-rw-r--r--  1 root wheel    147793  4月 11 18:05 chrome_100_percent.pak
-rw-r--r--  1 root wheel    221300  4月 11 18:05 chrome_200_percent.pak
-r-xr-xr-x  1 root wheel  31304152  4月 11 18:05 chromedriver
-r-xr-xr-x  1 root wheel 199064664  4月 11 18:05 code-oss
drwxr-xr-x  4 root wheel         4  4月 14 10:27 gen
-rw-r--r--  1 root wheel    292056  4月 11 18:05 libEGL.so
-rw-r--r--  1 root wheel   2866480  4月 11 18:05 libffmpeg.so
-rw-r--r--  1 root wheel   7154400  4月 11 18:05 libGLESv2.so
-rw-r--r--  1 root wheel   5378656  4月 11 18:05 libvk_swiftshader.so
-rw-r--r--  1 root wheel    651272  4月 11 18:05 libvulkan.so
-rw-r--r--  1 root wheel  11102553  4月 11 18:05 LICENSES.chromium.html
drwxr-xr-x  2 root wheel        57  4月 17 18:56 locales
-r-xr-xr-x  1 root wheel  49297608  4月 11 18:05 mksnapshot
drwxr-xr-x  3 root wheel         3  4月 14 10:27 node_headers
drwxr-xr-x  4 root wheel         4  4月 14 10:27 resources
-rw-r--r--  1 root wheel   6001527  4月 11 18:05 resources.pak
-rw-r--r--  1 root wheel    320614  4月 11 18:05 snapshot_blob.bin
-r-xr-xr-x  1 root wheel 117636104  4月 11 18:05 v8_context_snapshot_generator
-rw-r--r--  1 root wheel    693457  4月 11 18:05 v8_context_snapshot.bin
-rw-r--r--  1 root wheel       107  4月 11 18:05 vk_swiftshader_icd.json

 安装

如果以前使用的是make install,则编译之后会自动安装。

如果以前使用的是make指令,则编译之后,再次执行make install 即可。

如果不需要保留编译临时文件,可以可以使用

make install clean

这样可以有效节省空间。

知识学习

Visual Studio Code (VSCode)‌ 是使用 ‌Electron‌ 框架编译和构建的。以下是关于 VSCode 编译方式的详细解释:

1. ‌Electron 框架

  • Electron‌ 是一个开源框架,允许开发者使用 Web 技术(HTML、CSS 和 JavaScript)构建跨平台的桌面应用程序。
  • VSCode 利用 Electron 将其核心功能打包成一个桌面应用,使得它可以在 Windows、macOS 和 Linux 上运行。

2. ‌核心组件

  • Monaco Editor‌:VSCode 的代码编辑器部分基于 ‌Monaco Editor‌,这是一个由微软开发的浏览器内代码编辑器,支持语法高亮、代码补全、调试等功能。
  • Node.js 集成‌:VSCode 后端使用 Node.js,提供了扩展 API 和与操作系统交互的能力。
  • TypeScript‌:VSCode 的大部分代码库是用 ‌TypeScript‌ 编写的,这是一种由微软开发的编程语言,为 JavaScript 添加了静态类型检查。

已编译好的pkg安装包

请在这里下载:

【免费】FreeBSD14.2系统下VSCode1.99pkg安装包资源-CSDN文库

使用pkg install vscode-1.99.2.pkg命令安装 安装好后,使用code-vss 启动VSCode编辑器。 

调试

报错This is not the tsc command you are looking for

npm warn exec The following package was not found and will be installed: tsc@2.0.4

                This is not the tsc command you are looking for

To get access to the TypeScript compiler, tsc, from the command line either:

- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages
npm notice
npm notice New major version of npm available! 10.9.2 -> 11.3.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.3.0
npm notice To update run: npm install -g npm@11.3.0
npm notice
*** [do-build] Error code 1

make: stopped in /usr/ports/editors/vscode
1 error

make: stopped in /usr/ports/editors/vscode

sudo nstall typescript

编译报错build/azure-pipelines/common/computeBuiltInDepsCacheKey.ts(6,16): error TS2307: Cannot find module 'fs' or its corresponding type declarations.

build/azure-pipelines/common/computeBuiltInDepsCacheKey.ts(6,16): error TS2307: Cannot find module 'fs' or its corresponding type declarations.
build/azure-pipelines/common/computeBuiltInDepsCacheKey.ts(7,18): error TS2307: Cannot find module 'path' or its corresponding type declarations.
build/azure-pipelines/common/computeBuiltInDepsCacheKey.ts(8,20): error TS2307: Cannot find module 'crypto' or its corresponding type declarations.
build/azure-pipelines/common/computeBuiltInDepsCacheKey.ts(10,58): error TS2304: Cannot find name '__dirname'.
build/azure-pipelines/common/computeBuiltInDepsCacheKey.ts(17,1): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(6,16): error TS2307: Cannot find module 'fs' or its corresponding type declarations.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(7,18): error TS2307: Cannot find module 'path' or its corresponding type declarations.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(8,20): error TS2307: Cannot find module 'crypto' or its corresponding type declarations.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(9,18): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(11,24): error TS2304: Cannot find name '__dirname'.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(38,21): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(39,16): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
build/azure-pipelines/common/computeNodeModulesCacheKey.ts(42,1): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
build/azure-pipelines/common/createBuild.ts(6,43): error TS2307: Cannot find module '@azure/identity' or its corresponding type declarations.
build/azure-pipelines/common/createBuild.ts(7,30): error TS2307: Cannot find module '@azure/cosmos' or its corresponding type declarations.
build/azure-pipelines/common/createBuild.ts(10,5): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
bui

用这条命令试试:

npm install --save-dev @types/node
npm install @azure/identity @azure/cosmos

npm install yauzl @azure/storage-blob
npm install extract-zip @electron/get ansi-colors

不行,还是很多报错,提示这样

npm install --save-dev @types/jws

npm install --save-dev @types/vinyl-fs @types/gulp-filter @types/gulp-gzip @types/mime

这个没装上:@types/gulp-merge-json 

这样也不是事啊,手动到源码目录下npm install

/usr/ports/editors/vscode/work/vscode-1.98.2 % npm install

安装的东西真不少:

npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm warn deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm warn deprecated source-map-url@0.4.0: See https://github.com/lydell/source-map-url#deprecated
npm warn deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
npm warn deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm warn deprecated sinon@12.0.1: 16.1.1
npm warn deprecated osenv@0.1.5: This package is no longer supported.
npm warn deprecated is-data-descriptor@1.0.0: Please upgrade to v1.0.1
npm warn deprecated is-accessor-descriptor@1.0.0: Please upgrade to v1.0.1
npm warn deprecated gulp-vinyl-zip@2.1.2: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm warn deprecated glob@5.0.15: Glob versions prior to v9 are no longer supported
npm warn deprecated fstream@1.0.12: This package is no longer supported.
npm warn deprecated eslint-plugin-local@6.0.0: Since the coming of ESLint flat config file, you can specify local rules without the need of this package. For running ESLint rule unit tests, use eslint-rule-tester instead
npm warn deprecated asar@3.0.3: Please use @electron/asar moving forward.  There is no API change, just a package name change
npm warn deprecated is-data-descriptor@0.1.4: Please upgrade to v0.1.5
npm warn deprecated is-accessor-descriptor@0.1.6: Please upgrade to v0.1.7
npm warn deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm warn deprecated is-data-descriptor@0.1.4: Please upgrade to v0.1.5
npm warn deprecated is-accessor-descriptor@0.1.6: Please upgrade to v0.1.7
npm warn deprecated glob@7.1.6: Glob versions prior to v9 are no longer supported
npm warn deprecated glob@7.1.7: Glob versions prior to v9 are no longer supported
npm warn deprecated is-data-descriptor@0.1.4: Please upgrade to v0.1.5
npm warn deprecated is-accessor-descriptor@0.1.6: Please upgrade to v0.1.7
npm warn deprecated glob@8.1.0: Glob versions prior to v9 are no longer supported
npm warn deprecated glob@7.1.7: Glob versions prior to v9 are no longer supported
npm warn deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm warn deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm warn deprecated glob@7.1.6: Glob versions prior to v9 are no longer supported
npm warn deprecated is-data-descriptor@0.1.4: Please upgrade to v0.1.5
npm warn deprecated is-accessor-descriptor@0.1.6: Please upgrade to v0.1.7
npm warn deprecated is-data-descriptor@0.1.4: Please upgrade to v0.1.5
npm warn deprecated is-accessor-descriptor@0.1.6: Please upgrade to v0.1.7
npm warn deprecated glob@7.1.6: Glob versions prior to v9 are no longer supported
npm warn cleanup Failed to remove some directories [
npm warn cleanup   [
npm warn cleanup     '/usr/ports/editors/vscode/work/vscode-1.98.2/node_modules/native-is-elevated',
npm warn cleanup     [Error: ENOTEMPTY: directory not empty, rmdir '/usr/ports/editors/vscode/work/vscode-1.98.2/node_modules/native-is-elevated'] {
npm warn cleanup       errno: -66,
npm warn cleanup       code: 'ENOTEMPTY',
npm warn cleanup       syscall: 'rmdir',
npm warn cleanup       path: '/usr/ports/editors/vscode/work/vscode-1.98.2/node_modules/native-is-elevated'
npm warn cleanup     }
npm warn cleanup   ],
npm warn cleanup   [
npm warn cleanup     '/usr/ports/editors/vscode/work/vscode-1.98.2/node_modules/native-keymap',
npm warn cleanup     [Error: 

直接在项目根目录npm install

/usr/ports/editors/vscode % sudo nstall
密码:

up to date, audited 140 packages in 2s

29 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

还是有问题。删除work目录,重新make

make 报错gyp ERR! System FreeBSD 14.2-RELEASE-p1

This program built for amd64-portbld-freebsd14.0
Report bugs to <bug-make@gnu.org>
gyp ERR! build error
gyp ERR! stack Error: `gmake` failed with exit code: 2
gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:216:23)
gyp ERR! System FreeBSD 14.2-RELEASE-p1
gyp ERR! command "/usr/local/bin/node" "/usr/local/bin/node-gyp" "--userconfig=/usr/ports/editors/vscode/work/vscode-1.98.2/.npmrc" "rebuild"
gyp ERR! cwd /usr/ports/editors/vscode/work/vscode-1.98.2/node_modules/kerberos
gyp ERR! node -v v20.19.0
gyp ERR! node-gyp -v v11.0.0
gyp ERR! not ok
*** [pre-build] Error code 1

make: stopped in /usr/ports/editors/vscode
1 error

make: stopped in /usr/ports/editors/vscode

难道系统不兼容,14.0可以用,14.2不可以用?

后来经过ports源代码更新,安装好了VSCode1.99版本。可能就是新版本修正了编译不过去的bug。

编译VSCode的时候出现siginal 9 信号并退出编译

大约主要是内存不够的问题,建议使用16G以上的系统进行编译。如果是8G内存的系统,建议把swap设置为大约8G,比如10G,亲测可以编译过去,但是需要都尝试几次。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值