Chez Scheme 编译与环境搭建 Windows10

15 篇文章 0 订阅

Chez Scheme 编译与环境搭建 Windows10

引言

现在是2020年2月,防疫期间,下载各类工具很不方便。怀着对 Chez Scheme 的好奇,花了两天时间完成了 Windows10 上的编译,可以使用这个充满传奇色彩的解释器学习 SICP 了!

为什么要手动编译

据说官方网站上可以下载编译好的 Windows 可执行文件,无奈不能出门。CSDN 上有这资源,就是 chez scheme 可执行文件,但这不是最新版本,我想要最新版本。

源码获得

Github 路途遥远,来去不便。幸运的是,有一个国内网站提供 chez scheme 项目镜像(向提供镜像的 gitee 平台表示由衷的感谢)!

四散的组件

一个叫 configure 的文件里有这样一段:

if [ -d '.git' ] && command -v git >/dev/null 2>&1 ; then
  git submodule init && git submodule update || exit 1
else
  if [ ! -f 'nanopass/nanopass.ss' ] ; then
    rmdir nanopass > /dev/null 2>&1
    (curl  -L -o v1.9.tar.gz https://github.com/nanopass/nanopass-framework-scheme/archive/v1.9.tar.gz && tar -zxf v1.9.tar.gz && mv nanopass-framework-scheme-1.9 nanopass && rm v1.9.tar.gz) || exit 1
  fi

  if [ "${zlibDep}" != "" ] ; then
    if [ ! -f 'zlib/configure' ] ; then
      rmdir zlib > /dev/null 2>&1
      (curl -L -o v1.2.11.tar.gz https://github.com/madler/zlib/archive/v1.2.11.tar.gz && tar -xzf v1.2.11.tar.gz && mv zlib-1.2.11 zlib && rm v1.2.11.tar.gz) || exit 1
    fi
  fi
  
  if [ "${LZ4Dep}" != "" ] ; then
    if [ ! -f 'lz4/lib/Makefile' ] ; then
      rmdir lz4 > /dev/null 2>&1
      (curl -L -o v1.8.3.tar.gz https://github.com/lz4/lz4/archive/v1.8.3.tar.gz && tar -xzf v1.8.3.tar.gz && mv lz4-1.8.3 lz4 && rm v1.8.3.tar.gz) || exit 1
    fi
  fi

  if [ ! -f 'stex/Mf-stex' ] ; then
    rmdir stex > /dev/null 2>&1
    (curl -L -o v1.2.1.tar.gz https://github.com/dybvig/stex/archive/v1.2.1.tar.gz && tar -zxf v1.2.1.tar.gz && mv stex-1.2.1 stex && rm v1.2.1.tar.gz) || exit 1
  fi
fi

这段 bash 脚本会检查项目根目录下有没有 nanopass, zlib, lz4, stex 这四个文件夹,没有的话就用 curl 命令去 GitHub 上下载。

实话说,我不太理解项目作者为什么让人以这种方式获取这些依赖,而不是直接把处理好的文件添加进来。总之,网络状况不好的时候,就只能手动添加这些依赖了。注意,我们要假装自己是 bash 解释器,把下载好的文件解压、重命名、放到和 configure 同级目录下。

编译器以及 GNU 工具链

下载 msys2

下面的内容参考了Windows下编译最新版ChezScheme

近些年,Windows 对 Linux 的兼容性越来越好了。比如 msys2 是一个在 Windows 上运行的 Linux shell (不知道这样说是否准确,我不太清楚它和 Linux shell 到底什么关系),在清华镜像站可以下载到 msys2 安装包。注意64位系统选 x86_64 版。

如果清华镜像站不能用了,可以给 MSYS2 添加中科大的源

为什么需要 msys2

我也不清楚。

嗯……在 Linux 上,chez scheme (以及大多数 GNU 软件)的编译过程流畅自然,所以使用 msys2 这个 Linux shell 大概是为了简化编译过程吧。

另外,msys2 的包管理工具pacman可以一键安装许多依赖。

Pacman

项目文件 BUILDING 中有这样一段:

Prerequisites:

  • Bash/WSL, MinGW/MSYS, or Cygwin with bash, git, grep, make, sed, etc.
  • Microsoft Visual Studio 2019, 2017, or 2015
  • WiX Toolset (for making an install)

意思是,编译需要的工具有

  • 一个能用的 Bash,和其上的 git, grep, make 等等工具
  • Visual Studio
  • 打包工具集

其中,能在 bash 上运行的各种 GNU 工具要用 Pacman 安装(在 msys2 中),命令是:

同步?
pacman -Sy

搞不清具体作用,在配置镜像站之后执行一下吧。

安装

下面的命令安装 git

pacman -S git

软件被安装到哪里了?就像很多的 Linux 软件一样,安装位置真是弄不清楚!如果你知道规律,一定教教我。

言归正传,用这个安装命令把需要的工具都装上。一共需要哪些工具?我装了好多,也不知道是哪些用上了……

Visual Studio

BUILDING 中有:

If you’re using Visual Studio 2019, install “Desktop development with C++”
on the “Workloads” tabs and the “C++ 2019 Redistributable MSMs” on the
“Individual components” tab under the “Compilers, build tools, and runtimes”
section.

所以需要安装的组件是:

  • C++ 桌面开发环境
  • C++ 2019 Redistributable MSM (在单个组件选项卡里)

前面安装了一堆 GNU 工具,到头来还是需要 Visual Studio。

安装上述组件的 Visual Studio 有 5GB 左右。

WIX Toolsets

这似乎是打包用的,可能不是必须安装。文档中有:

WiX is a set of tools that allows you to create Windows Installer-based deployment packages for your application. The WiX toolset is based on a declarative XML authoring model. You can use WiX on the command line by using the WiX tools or MSBuild. In addition, there is also a WiX Visual Studio plug-in that supports VS2005, VS2008, and VS2010. The WiX toolset supports building the following types of Windows Installer files:
Installer (.msi)
Patches (.msp)
Merge Modules (.msm)
Transforms (.mst)

大意就是,WIX 是制作安装包的工具。

如果我没记错的话,至此,所有的工具集齐了。

编译

编译过程主要参考项目目录下的 BUILDING 文件和前面提到过的博客。

过程

启动 msys2,进入 wininstall 目录。msys2 的目录要用 Linux 格式,例如,Windows 格式的cd语句

cd D:\home\Downloads\Compressed\chez-scheme\wininstall

要写成:

cd /d/home/Downloads/Compressed/chez-scheme/wininstall

然后依次执行:

make workareas
make

顺利的话,过程结束后,你会在一个文件夹里找到新鲜出炉的可执行文件。

下面是一些可能出现的错误。

找不到 Visual Studio

Visual Studio 2017 or 2015 must be installed.

这条错误信息极具误导性,让人误以为只能用 VS 2017 或 VS 2015。要不是文件 BUILDING 中明确提到 VS 2019,我肯定会上当。

下面是这条错误信息的来源,vs.bat

@echo off
set Applications=%ProgramFiles(x86)%
if not "%Applications%" == "" goto win64
set Applications=%ProgramFiles%
:win64

:: Set up Visual Studio command line environment variables given a
:: machine type, e.g., amd64 or x86.

:: Visual Studio 2019 Enterprise
set BATDIR=D:\Program Files (x86)\Microsoft Visual Studio\2019\VC\Auxiliary\Build    # 我修改了这里
if exist "%BATDIR%\vcvarsall.bat" goto found

:: Visual Studio 2019 Professional
set BATDIR=%Applications%\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build
if exist "%BATDIR%\vcvarsall.bat" goto found

……

:: Visual Studio 2017 BuildTools
set BATDIR=%Applications%\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build
if exist "%BATDIR%\vcvarsall.bat" goto found

:: Visual Studio 2015
set BATDIR=%VS140COMNTOOLS%..\..\VC
if exist "%BATDIR%\vcvarsall.bat" goto found

echo Visual Studio 2017 or 2015 must be installed.
exit 1

这段脚本可不怎么高明:看上去考虑的情况蛮多的,然而,我的 VS 目录结构和脚本作者预想的不一样啊!

补救方法自然是填入正确的路径。不过还没完,编译过程中,脚本会根据你的计算机体系结构,创建一个新的文件夹,把这个 vs.bat 复制进去。也就是说,会出现两个 vs.bat,统统改掉吧!

无限循环

不知道是不是因为上一步的魔改,我的编译过程会无限循环。我花了一些时间才注意到提示信息在不断重复……于是在又一次循环刚开始的时候(出现 Visual Studio 2019 字样)关掉了窗口(msys2),似乎不影响下一步执行make

提取可执行文件

BUILDING 中有:

The resulting executable in \bin<machine> relies on
bootfiles in …\boot<machine> relative to the executable.

也就是说,可执行文件位于<machine>\bin\<machine>,而且其执行依赖于..\boot\<machine>(boot 是 bin 的兄弟文件夹)。

拿我的计算机举例,可执行文件的位置是:

./a6nt/bin/a6nt/scheme.exe

boot 文件

./a6nt/boot/a6nt/scheme.boot

scheme.bootscheme.exe放在一起之后,它们所在的文件夹无论位于何处,scheme.exe都可以运行。

编辑器

VS code

插件:

  • code runner
  • chez-scheme

参考:

在Windows 10下部署Scheme开发环境(20190602图文攻略版)

解决VS Code 配置Code Runner运行Scheme时报错

DrRacket

对 scheme 来说,vs code 实在不是一款好用的编辑器。我知道 vs code 可以配置得很深入,但这些配置是通过编辑一系列配置文件(可能还包括其他手段)实现的,对于轻度用户来说负担太重。

DrRacket 就很不错:有漂亮的界面,舒心的包管理器,完备的文档。唯一的遗憾是,它不是 chez scheme。而就在最近,这个遗憾不存在了!chez 开源后,racket 推出了以 chez 为后端的版本,兼具 chez 的速度和 DrRacket 的界面。

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值