Skip to content

Commit

Permalink
Makefile: New 'reusevm' target & bootstrap-skipping method
Browse files Browse the repository at this point in the history
This is a "less magic" and "more helpful" way to handle bootstrapping
vs not bootstrapping the VM.

The default behavior of "make" is reverted to its original behavior.
i.e. it generates code for the VM using DynASM (requiring LuaJIT.)

If LuaJIT is not available then this error message is printed:

    Error: Missing dependency (luajit) for bootstrapping the VM.

    Here are your options to build RaptorJIT:
      make reusevm     # copy reference VM from reusevm/
      (install luajit) # satisfy the dependency
      nix-build        # use nix to satisfy the dependencies

    Warning:
      Only reusevm when running a pristine copy of RaptorJIT from
      a repository that keeps the reference VM up-to-date.
      (Otherwise you might mix some stale code into your build.)

So then the user can choose between installing LuaJIT or running 'make
reusevm' to use the in-tree generated code at their own risk.

In practice it should be safe to 'reusevm' when building a pristine
master branch because CI is ensuring that the code is always
up-to-date. However, other branches or working copies may have stale
code in reusevm/ that is not safe to use.
  • Loading branch information
lukego committed Jul 9, 2017
1 parent 9fe3967 commit c297923
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 29 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,25 @@ The [AnandTech review of the Haswell microarchitecture](http://www.anandtech.com

### Compilation for users

Building a standard RaptorJIT from source is easy:
Simple build:

```shell
$ make # requires LuaJIT (2.0 or 2.1) to run DynASM
```
$ make
$ ls -l src/raptorjit{,.a,.o} src/libraptorjit.so
-rwxr-xr-x 1 luke users 553592 Jul 7 08:22 src/raptorjit
-rw-r--r-- 1 luke users 843116 Jul 7 08:21 src/raptorjit.a
-rw-r--r-- 1 luke users 18072 Jul 7 08:22 src/raptorjit.o
-rwxr-xr-x 1 luke users 566288 Jul 7 08:22 src/libraptorjit.so

Alternative if you don't have LuaJIT available and you are building a
pristine copy from the master branch:

```shell
$ make reusevm # Reuse reference copy of the generated VM code
$ make # Does not require LuaJIT now
```

### Compilation for VM hackers

If you are hacking the virtual machine definition then you need a few
additional software dependencies for the build. For example, you need
LuaJIT to run DynASM in order to regenerate the virtual machine sources.

You can install these dependencies yourself or you can use the
reference [Nix](http://nixos.org/nix/) build environment provided with
RaptorJIT.
RaptorJIT uses [Nix](http://nixos.org/nix/) to provide a reference
build environment. You can use Nix to build/test/benchmark RaptorJIT
with suitable versions of all dependencies provided.

Note: Building with nix will be slow the first time because it
downloads the exact reference versions of the toolchain (clang, etc)
Expand Down
3 changes: 0 additions & 3 deletions raptorjit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ mkDerivation rec {
name = "raptorjit-${version}";
inherit version;
src = source;
preBuild = ''
make bootstrapclean
'';
buildInputs = [ luajit ]; # LuaJIT to bootstrap DynASM
installPhase = ''
mkdir -p $out/bin
Expand Down
35 changes: 23 additions & 12 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)

LIB_VMDEF= jit/vmdef.lua
LIB_VMDEFP= $(LIB_VMDEF)

LUAJIT_O= raptorjit.o
LUAJIT_A= raptorjit.a
LUAJIT_SO= libraptorjit.so
Expand All @@ -253,7 +250,7 @@ LUAJIT_T= raptorjit
ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
host/buildvm_arch.h
ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
ALL_GEN= $(LJVM_S) $(ALL_HDRGEN)
WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
ALL_RM= $(ALL_T) *.o host/*.o $(WIN_RM)

Expand All @@ -263,7 +260,7 @@ ALL_RM= $(ALL_T) *.o host/*.o $(WIN_RM)

TARGET_O= $(LUAJIT_A)
TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
TARGET_DEP= $(LUAJIT_SO)

Q= @
E= @echo
Expand All @@ -278,10 +275,13 @@ default all: $(TARGET_T)

clean:
$(HOST_RM) $(ALL_RM)

bootstrapclean: clean
$(HOST_RM) $(ALL_GEN)

reusevm:
cd reusevm; \
cp -r * ../
@echo "Copied reference VM. Ready to build."

libbc:
./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
$(MAKE) all
Expand All @@ -300,13 +300,28 @@ depend:
test -s $$file || $(HOST_RM) $$file; \
done

.PHONY: default all clean libbc depend
.PHONY: default all clean libbc depend reusevm

##############################################################################
# Rules for generated files.
##############################################################################

host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) $(DASM_DIR)/*.lua
@command -v $(DASM) 2>/dev/null || { \
echo "Error: Missing dependency (luajit) for bootstrapping the VM."; \
echo ""; \
echo "Here are your options to build RaptorJIT:"; \
echo " make reusevm # copy reference VM from reusevm/"; \
echo " (install luajit) # satisfy the dependency"; \
echo " nix-build # use nix to satisfy the dependencies"; \
echo ""; \
echo "Warning:"; \
echo " Only reusevm when running a pristine copy of RaptorJIT from";\
echo " a repository that keeps the reference VM up-to-date."; \
echo " (Otherwise you might mix some stale code into your build.)"; \
echo; \
exit 1; \
}
$(E) "DYNASM $@"
$(Q)$(DASM) -o $@ $(DASM_DASC)

Expand Down Expand Up @@ -336,10 +351,6 @@ lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
$(E) "BUILDVM $@"
$(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)

$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
$(E) "BUILDVM $@"
$(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)

lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
$(E) "BUILDVM $@"
$(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c297923

Please sign in to comment.