浏览代码

Migration to dune (#8801)

use dune
Simon Krajewski 6 年之前
父节点
当前提交
594d3646a3

+ 3 - 0
.gitignore

@@ -129,3 +129,6 @@ tests/display/.unittest/
 tests/unit/.unittest/
 tests/threads/export/
 tests/server/test.js.map
+*.merlin
+lib.sexp
+src/compiler/version.ml

+ 0 - 14
.merlin

@@ -1,14 +0,0 @@
-S src/**
-B _build/src/**
-S libs/**
-B libs/**
-B +threads
-PKG ptmap
-PKG sedlex
-PKG extlib
-PKG camlzip
-PKG xml-light
-PKG sha
-FLG -safe-string
-FLG -w -3
-FLG -w -40

+ 1 - 1
.vscode/tasks.json

@@ -1,5 +1,5 @@
 {
-    "version": "2.0.0",
+	"version": "2.0.0",
 	"tasks": [
 		{
 			"label": "make: haxe",

+ 16 - 126
Makefile

@@ -21,6 +21,7 @@ PACKAGE_SRC_EXTENSION=.tar.gz
 MAKEFILENAME?=Makefile
 PLATFORM?=unix
 
+DUNE_COMMAND=dune
 HAXE_OUTPUT=haxe
 HAXELIB_OUTPUT=haxelib
 PREBUILD_OUTPUT=prebuild
@@ -30,48 +31,6 @@ STATICLINK?=0
 
 # Configuration
 
-# Modules in these directories should only depend on modules that are in directories to the left
-HAXE_DIRECTORIES=core core/ds core/json core/display syntax context context/display codegen codegen/gencommon generators generators/jvm optimization filters macro macro/eval macro/eval/bytes typing compiler
-EXTLIB_LIBS=extlib-leftovers extc neko javalib swflib ttflib ilib objsize pcre ziplib
-OCAML_LIBS=unix str threads dynlink
-OPAM_LIBS=sedlex.ppx xml-light extlib ptmap sha
-
-FINDLIB_LIBS=$(OCAML_LIBS)
-FINDLIB_LIBS+=$(OPAM_LIBS)
-
-# Includes, packages and compiler
-
-HAXE_INCLUDES=$(HAXE_DIRECTORIES:%=-I _build/src/%)
-EXTLIB_INCLUDES=$(EXTLIB_LIBS:%=-I libs/%)
-ALL_INCLUDES=$(EXTLIB_INCLUDES) $(HAXE_INCLUDES)
-FINDLIB_PACKAGES=$(FINDLIB_LIBS:%=-package %)
-CFLAGS=
-ALL_CFLAGS=-bin-annot -safe-string -thread -g -w -3 -w -40 $(CFLAGS) $(ALL_INCLUDES) $(FINDLIB_PACKAGES)
-
-MESSAGE_FILTER=sed -e 's/_build\/src\//src\//' tmp.tmp
-
-ifeq ($(BYTECODE),1)
-	TARGET_FLAG = bytecode
-	COMPILER = ocamlfind ocamlc
-	LIB_EXT = cma
-	MODULE_EXT = cmo
-	NATIVE_LIB_FLAG = -custom
-else
-	TARGET_FLAG = native
-	COMPILER = ocamlfind ocamlopt
-	LIB_EXT = cmxa
-	MODULE_EXT = cmx
-	OCAMLDEP_FLAGS = -native
-endif
-
-CC_CMD = ($(COMPILER) $(ALL_CFLAGS) -c $< 2>tmp.tmp && $(MESSAGE_FILTER)) || ($(MESSAGE_FILTER) && exit 1)
-
-# Meta information
-
-BUILD_DIRECTORIES := $(HAXE_DIRECTORIES:%=_build/src/%)
-HAXE_SRC := $(wildcard $(HAXE_DIRECTORIES:%=src/%/*.ml))
-BUILD_SRC := $(HAXE_SRC:%=_build/%)
-
 ADD_REVISION?=0
 
 BRANCH=$(shell echo $$APPVEYOR_REPO_NAME | grep -q /haxe && echo $$APPVEYOR_REPO_BRANCH || echo $$TRAVIS_REPO_SLUG | grep -q /haxe && echo $$TRAVIS_BRANCH || git rev-parse --abbrev-ref HEAD)
@@ -87,94 +46,26 @@ PACKAGE_FILE_NAME=haxe_$(COMMIT_DATE)_$(COMMIT_SHA)
 HAXE_VERSION=$(shell $(CURDIR)/$(HAXE_OUTPUT) -version 2>&1 | awk '{print $$1;}')
 HAXE_VERSION_SHORT=$(shell echo "$(HAXE_VERSION)" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+")
 
-# using $(CURDIR) on Windows will not work since it might be a Cygwin path
-ifdef SYSTEMROOT
-	EXTENSION=.exe
-else
-	export HAXE_STD_PATH=$(CURDIR)/std
-endif
-
-# Native libraries
-
 ifneq ($(STATICLINK),0)
 	LIB_PARAMS= -cclib '-Wl,-Bstatic -lpcre -lz -Wl,-Bdynamic '
 else
 	LIB_PARAMS?= -cclib -lpcre -cclib -lz
 endif
 
-NATIVE_LIBS=-thread -cclib libs/extc/extc_stubs.o -cclib libs/extc/process_stubs.o -cclib libs/objsize/c_objsize.o -cclib libs/pcre/pcre_stubs.o -ccopt -L/usr/local/lib $(LIB_PARAMS)
-
-# Modules
-
--include Makefile.modules
-
-# Rules
-
-all: libs haxe tools
-
-libs:
-	$(foreach lib,$(EXTLIB_LIBS),$(MAKE) -C libs/$(lib) $(TARGET_FLAG) &&) true
-
-_build/%:%
-	mkdir -p $(dir $@)
-	cp $< $@
-
-build_dirs:
-	@mkdir -p $(BUILD_DIRECTORIES)
-
-_build/src/syntax/grammar.ml:src/syntax/grammar.mly
-	camlp5o -impl $< -o $@
-
-_build/src/compiler/version.ml: FORCE
-ifneq ($(ADD_REVISION),0)
-	$(MAKE) -f Makefile.version_extra -s --no-print-directory ADD_REVISION=$(ADD_REVISION) BRANCH=$(BRANCH) COMMIT_SHA=$(COMMIT_SHA) COMMIT_DATE=$(COMMIT_DATE) > _build/src/compiler/version.ml
-else
-	echo let version_extra = None > _build/src/compiler/version.ml
-endif
-
-_build/src/core/defineList.ml: src-json/define.json prebuild
-	./$(PREBUILD_OUTPUT) define $< > $@
-
-_build/src/core/metaList.ml: src-json/meta.json prebuild
-	./$(PREBUILD_OUTPUT) meta $< > $@
-
-build_src: | $(BUILD_SRC) _build/src/syntax/grammar.ml _build/src/compiler/version.ml _build/src/core/defineList.ml _build/src/core/metaList.ml
-
-prebuild: _build/src/core/json/json.ml _build/src/prebuild/main.ml
-	$(COMPILER) -safe-string -linkpkg -g -o $(PREBUILD_OUTPUT) -package sedlex.ppx -package extlib -I _build/src/core/json _build/src/core/json/json.ml _build/src/prebuild/main.ml
+all: haxe tools
 
-haxe: build_src
-	$(MAKE) -f $(MAKEFILENAME) build_pass_1
-	$(MAKE) -f $(MAKEFILENAME) build_pass_2
-	$(MAKE) -f $(MAKEFILENAME) build_pass_3
-	$(MAKE) -f $(MAKEFILENAME) build_pass_4
-
-build_pass_1:
-	printf MODULES= > Makefile.modules
-	ls -1 $(HAXE_DIRECTORIES:%=_build/src/%/*.ml) | tr '\n' ' ' >> Makefile.modules
-
-build_pass_2:
-	printf MODULES= > Makefile.modules
-	ocamlfind ocamldep -sort -slash $(HAXE_INCLUDES) $(MODULES) | sed -e "s/\.ml//g" >> Makefile.modules
-
-build_pass_3:
-	ocamlfind ocamldep -slash $(OCAMLDEP_FLAGS) $(HAXE_INCLUDES) $(MODULES:%=%.ml) > Makefile.dependencies
-
-build_pass_4: $(MODULES:%=%.$(MODULE_EXT))
-	$(COMPILER) -safe-string -linkpkg -g -o $(HAXE_OUTPUT) $(NATIVE_LIBS) $(NATIVE_LIB_FLAG) $(LFLAGS) $(FINDLIB_PACKAGES) $(EXTLIB_INCLUDES) $(EXTLIB_LIBS:=.$(LIB_EXT)) $(MODULES:%=%.$(MODULE_EXT))
+haxe:
+	$(DUNE_COMMAND) build --workspace dune-workspace.dev src-prebuild/prebuild.exe
+	_build/default/src-prebuild/prebuild.exe libparams $(LIB_PARAMS) > lib.sexp
+	_build/default/src-prebuild/prebuild.exe version $(ADD_REVISION) $(BRANCH) $(COMMIT_SHA) > src/compiler/version.ml
+	$(DUNE_COMMAND) build --workspace dune-workspace.dev src/haxe.exe
+	cp -f _build/default/src/haxe.exe ./${HAXE_OUTPUT}
 
 kill_exe_win:
 ifdef SYSTEMROOT
 	-@taskkill /F /IM haxe.exe 2>/dev/null
 endif
 
-plugin:
-ifeq ($(BYTECODE),1)
-	$(CC_CMD) $(PLUGIN).ml
-else
-	$(COMPILER) $(ALL_CFLAGS) -shared -o $(PLUGIN).cmxs $(PLUGIN).ml
-endif
-
 # Only use if you have only changed gencpp.ml
 quickcpp: build_src build_pass_4 copy_haxetoolkit
 
@@ -211,14 +102,16 @@ uninstall:
 	rm -rf $(DESTDIR)$(INSTALL_STD_DIR)
 
 opam_install:
-	opam install $(OPAM_LIBS) camlp5 ocamlfind --yes
-
-# Dependencies
+	opam install camlp5 ocamlfind dune --yes
 
--include Makefile.dependencies
+haxe_deps:
+	opam pin add haxe . --no-action
+	opam install haxe --deps-only --yes
 
 # Package
 
+package_env: opam_install haxe_deps
+
 package_src:
 	mkdir -p $(PACKAGE_OUT_DIR)
 	# use git-archive-all since we have submodules
@@ -300,10 +193,7 @@ package_installer_mac: $(INSTALLER_TMP_DIR)/neko-osx64.tar.gz package_unix
 
 # Clean
 
-clean: clean_libs clean_haxe clean_tools clean_package
-
-clean_libs:
-	$(foreach lib,$(EXTLIB_LIBS),$(MAKE) -C libs/$(lib) clean &&) true
+clean: clean_haxe clean_tools clean_package
 
 clean_haxe:
 	rm -f -r _build $(HAXE_OUTPUT) $(PREBUILD_OUTPUT)
@@ -324,4 +214,4 @@ FORCE:
 .ml.cmo:
 	$(CC_CMD)
 
-.PHONY: haxe libs haxelib
+.PHONY: haxe haxelib

+ 0 - 11
Makefile.version_extra

@@ -1,11 +0,0 @@
-# A hack to print the content of version.ml consistently across Windows (cygwin / command prompt) and Unix.
-# The hack: http://stackoverflow.com/a/7284135/267998
-# The issue: https://github.com/HaxeFoundation/haxe/commit/4f8f6a99ddf810ea045492cdd6d40c55abc03e15#commitcomment-10660400
-
-all: ;
-
-ifneq ($(ADD_REVISION),0)
-	$(info let version_extra = Some ("git build $(BRANCH)","$(COMMIT_SHA)"))
-else
-	$(info let version_extra = None)
-endif

+ 1 - 0
Makefile.win

@@ -7,6 +7,7 @@ PREBUILD_OUTPUT=prebuild.exe
 EXTENSION=.exe
 PACKAGE_SRC_EXTENSION=.zip
 ARCH?=32
+DUNE_COMMAND=dune.exe
 
 ifeq ($(ARCH),64)
 NEKO_ARCH_STR=64

+ 1 - 0
dune

@@ -0,0 +1 @@
+(data_only_dirs extra lib std tests)

+ 10 - 0
dune-project

@@ -0,0 +1,10 @@
+(lang dune 1.11)
+(name haxe)
+
+(package
+	(name haxe)
+)
+
+(package
+	(name haxe_prebuild)
+)

+ 2 - 0
dune-workspace.dev

@@ -0,0 +1,2 @@
+(lang dune 1.11)
+(profile release)

+ 0 - 2
extra/azure-pipelines/build-linux.yml

@@ -32,8 +32,6 @@ jobs:
         displayName: Install OCaml libraries
       - script: |
           set -ex
-          opam config exec -- make -s STATICLINK=1 libs
-          opam config exec -- make -s STATICLINK=1 prebuild
           opam config exec -- make -s -j`nproc` STATICLINK=1 haxe
           opam config exec -- make -s haxelib
           make -s package_bin

+ 0 - 2
extra/azure-pipelines/build-mac.yml

@@ -31,8 +31,6 @@ jobs:
         displayName: Install OCaml libraries
       - script: |
           set -ex
-          opam config exec -- make -s STATICLINK=1 "LIB_PARAMS=/usr/local/opt/zlib/lib/libz.a /usr/local/lib/libpcre.a" libs
-          opam config exec -- make -s STATICLINK=1 "LIB_PARAMS=/usr/local/opt/zlib/lib/libz.a /usr/local/lib/libpcre.a" prebuild
           opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/opt/zlib/lib/libz.a /usr/local/lib/libpcre.a" haxe
           opam config exec -- make -s haxelib
           make -s package_bin package_installer_mac

+ 0 - 1
extra/azure-pipelines/build-windows.yml

@@ -54,7 +54,6 @@ jobs:
         displayName: Expose mingw dll files
       - powershell: |
           Set-PSDebug -Trace 1
-          & "$(CYG_ROOT)/bin/bash.exe" @('-lc', 'cd "$OLDPWD" && opam config exec -- make -s -f Makefile.win libs prebuild 2>&1')
           & "$(CYG_ROOT)/bin/bash.exe" @('-lc', 'cd "$OLDPWD" && opam config exec -- make -s -f Makefile.win -j`nproc` haxe 2>&1')
           & "$(CYG_ROOT)/bin/bash.exe" @('-lc', 'cd "$OLDPWD" && opam config exec -- make -s -f Makefile.win haxelib 2>&1')
           & "$(CYG_ROOT)/bin/bash.exe" @('-lc', 'cd "$OLDPWD" && opam config exec -- make -f Makefile.win echo_package_files package_bin package_installer_win package_choco 2>&1')

+ 16 - 0
libs/extc/dune

@@ -0,0 +1,16 @@
+(include_subdirs no)
+
+(library
+	(name extc)
+	(libraries extlib)
+	(c_names extc_stubs)
+	(modules extc)
+	(wrapped false)
+)
+
+(library
+	(name extproc)
+	(c_names process_stubs)
+	(modules process)
+	(wrapped false)
+)

+ 7 - 0
libs/extlib-leftovers/dune

@@ -0,0 +1,7 @@
+(include_subdirs no)
+
+(library
+	(name extlib_leftovers)
+	(libraries extlib)
+	(wrapped false)
+)

+ 8 - 0
libs/ilib/dune

@@ -0,0 +1,8 @@
+(include_subdirs no)
+
+(library
+	(name ilib)
+	(modules_without_implementation ilData ilMeta)
+	(libraries extlib)
+	(wrapped false)
+)

+ 4 - 4
libs/ilib/ilMetaWriter.ml

@@ -68,11 +68,11 @@ let int_of_type_def_string = function
 
 let int_of_type_def_flags f =
 	int_of_type_def_vis f.tdf_vis
-		logor
+		lor
 	int_of_type_def_layout f.tdf_layout
-		logor
+		lor
 	int_of_type_def_semantics f.tdf_semantics
-		logor
+		lor
 	int_of_type_def_impl f.tdf_impl
-		logor
+		lor
 	int_of_type_def_string f.tdf_string

+ 7 - 0
libs/javalib/dune

@@ -0,0 +1,7 @@
+(include_subdirs no)
+
+(library
+	(name javalib)
+	(libraries extlib)
+	(wrapped false)
+)

+ 6 - 0
libs/json/dune

@@ -0,0 +1,6 @@
+(include_subdirs no)
+
+(library
+	(name json)
+	(preprocess (pps sedlex.ppx))
+)

+ 0 - 0
src/core/json/json.ml → libs/json/json.ml


+ 7 - 0
libs/neko/dune

@@ -0,0 +1,7 @@
+(include_subdirs no)
+
+(library
+	(name neko)
+	(libraries extlib)
+	(wrapped false)
+)

+ 9 - 0
libs/objsize/dune

@@ -0,0 +1,9 @@
+(include_subdirs no)
+
+(library
+	(name objsize)
+	(c_names c_objsize)
+	(c_flags (-I../../../../libs/objsize)) ; TODO: This is stupid
+	(wrapped false)
+	(modules objsize)
+)

+ 7 - 0
libs/pcre/dune

@@ -0,0 +1,7 @@
+(include_subdirs no)
+
+(library
+	(name pcre)
+	(c_names pcre_stubs)
+	(wrapped false)
+)

+ 8 - 0
libs/swflib/dune

@@ -0,0 +1,8 @@
+(include_subdirs no)
+
+(library
+	(name swflib)
+	(libraries extc extlib extlib_leftovers)
+	(modules_without_implementation as3 as3hl)
+	(wrapped false)
+)

+ 7 - 0
libs/ttflib/dune

@@ -0,0 +1,7 @@
+(include_subdirs no)
+
+(library
+	(name ttflib)
+	(libraries extlib extlib_leftovers swflib)
+	(wrapped false)
+)

+ 2 - 0
libs/ttflib/main.ml

@@ -65,6 +65,8 @@ let process args =
  				let config = {
  					ttfc_range_str = range_str;
  					ttfc_font_name = None;
+					ttfc_font_weight = TFWRegular;
+					ttfc_font_posture = TFPNormal;
  				} in
 				let f2 = TTFSwfWriter.to_swf ttf config in
 				let ch = IO.output_channel (open_out_bin (dir ^ "/" ^ ttf.ttf_font_name ^ ".dat")) in

+ 7 - 0
libs/ziplib/dune

@@ -0,0 +1,7 @@
+(include_subdirs no)
+
+(library
+	(name ziplib)
+	(libraries extc unix)
+	(wrapped false)
+)

+ 8 - 0
src-prebuild/dune

@@ -0,0 +1,8 @@
+(include_subdirs no)
+
+(executable
+	(name prebuild)
+	(public_name haxe_prebuild)
+	(package haxe_prebuild)
+	(libraries extlib json)
+)

+ 14 - 4
src/prebuild/main.ml → src-prebuild/prebuild.ml

@@ -196,8 +196,8 @@ type meta_parameter =
 
 ;;
 
-match Sys.argv with
-	| [|_; "define"; define_path|] ->
+match Array.to_list (Sys.argv) with
+	| [_; "define"; define_path]->
 		let defines = parse_file_array define_path parse_define in
 		Printf.printf "%s" define_header;
 		Printf.printf "type strict_defined =\n";
@@ -206,7 +206,7 @@ match Sys.argv with
 		Printf.printf "let infos = function\n";
 		Printf.printf "%s" (gen_define_info defines);
 		Printf.printf "\n\t| Last -> assert false\n"
-	| [|_; "meta"; meta_path|] ->
+	| [_; "meta"; meta_path]->
 		let metas = parse_file_array meta_path parse_meta in
 		Printf.printf "%s" meta_header;
 		Printf.printf "type strict_meta =\n";
@@ -215,4 +215,14 @@ match Sys.argv with
 		Printf.printf "let get_info = function\n";
 		Printf.printf "%s" (gen_meta_info metas);
 		Printf.printf "\n\t| Last -> assert false\n\t| Dollar s -> \"$\" ^ s,(\"\",[])\n\t| Custom s -> s,(\"\",[])\n"
-	| _ -> ()
+	| _ :: "libparams" :: params ->
+		Printf.printf "(%s)" (String.concat " " (List.map (fun s -> Printf.sprintf "\"%s\"" s) params))
+	| [_ ;"version";add_revision;branch;sha] ->
+		begin match add_revision with
+		| "0" | "" ->
+			print_endline "let version_extra = None"
+		| _ ->
+			Printf.printf "let version_extra = Some (\"git build %s\",\"%s\")" branch sha
+		end
+	| args ->
+		print_endline (String.concat ", " args)

+ 0 - 0
src/compiler/main.ml → src/compiler/haxe.ml


+ 11 - 0
src/core/dune

@@ -0,0 +1,11 @@
+(rule
+	(targets metaList.ml)
+	(deps ../../src-json/meta.json)
+	(action (with-stdout-to metaList.ml (run %{bin:haxe_prebuild} meta ../../src-json/meta.json)))
+)
+
+(rule
+	(targets defineList.ml)
+	(deps ../../src-json/define.json)
+	(action (with-stdout-to defineList.ml (run %{bin:haxe_prebuild} define ../../src-json/define.json)))
+)

+ 23 - 0
src/dune

@@ -0,0 +1,23 @@
+(include_subdirs unqualified)
+
+(env
+	(_
+		(flags (:standard -w -3 -thread))
+	)
+)
+
+(executable
+	(name haxe)
+	(public_name haxe)
+	(package haxe)
+	(libraries
+		extc extproc extlib_leftovers ilib javalib neko objsize pcre swflib ttflib ziplib
+		json
+		unix str threads dynlink
+		xml-light extlib ptmap sha
+	)
+	(preprocess (per_module
+		((pps sedlex.ppx) json lexer)
+	))
+	(link_flags (:include ../lib.sexp))
+)

+ 5 - 0
src/syntax/dune

@@ -0,0 +1,5 @@
+(rule
+	(targets grammar.ml)
+	(deps grammar.mly)
+	(action (run %{bin:camlp5o} -impl grammar.mly -o %{targets}))
+)