[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [UNIKRAFT PATCH 1/2] Add support for compilation of D sources



Hi Marius-Cristian,

thanks a lot for your work! I am actually wondering if we should rather move this to a D language support library instead of maintaining it with the core Unikraft repository - especially if a language runtime library is anyway required (is this true?). It is also planned that we move the GO compile rules out of the main repository. I am concerned that at some point we have too many languages to maintain within the core Unikraft repository. What do you think? In general, a language support library, would have a file called `Makefile.rules`. It will be automatically loaded by the build system and you can take your compile rules for D sources there.

Sorry for this naive question (I am obviously not an D expert): Can the D compiler be used to compile our C sources (e.g., by using the betterC subset)? In such a case, we could provide a D compiler option with a mechanism that is currently suggested for supporting clang compiler:
https://patchwork.unikraft.org/project/unikraft/list/?series=1584&state=*

In case that this could be even completely done without needing any runtime library, then we should have enough justifaction to integrate D support into the core repository.

Let me know what you think.

Thanks,

Simon

On 21.07.20 15:37, Marius-Cristian Baciu wrote:
Use 'make D_COMPILER=gdc' for compilation of programs using full-language
capabilities and 'make D_COMPILER=dmd' for programs using the betterC subset
---
  Makefile                     | 15 +++++++++--
  Makefile.uk                  | 16 ++++++++++++
  support/build/Makefile.rules | 48 +++++++++++++++++++++++++++++++++++-
  3 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 725b012..493ac7b 100644
--- a/Makefile
+++ b/Makefile
@@ -277,6 +277,14 @@ GOCFLAGS :=
  GOCFLAGS-y :=
  GOCINCLUDES :=
  GOCINCLUDES-y :=
+DMDFLAGS :=
+DMDFLAGS-y :=
+DMDINCLUDES :=
+DMDINCLUDES-y :=
+GDCFLAGS :=
+GDCFLAGS-y :=
+GDCINCLUDES :=
+GDCINCLUDES-y :=
  DBGFLAGS :=
  DBGFLAGS-y :=
  LDFLAGS :=
@@ -502,6 +510,8 @@ CC          := $(CONFIG_CROSS_COMPILE)gcc
  CPP           := $(CC)
  CXX           := $(CPP)
  GOC           := $(CONFIG_CROSS_COMPILE)gccgo-7
+DMD            := $(CONFIG_CROSS_COMPILE)dmd
+GDC            := $(CONFIG_CROSS_COMPILE)gdc
  AS            := $(CC)
  AR            := $(CONFIG_CROSS_COMPILE)gcc-ar
  NM            := $(CONFIG_CROSS_COMPILE)gcc-nm
@@ -537,7 +547,7 @@ ASFLAGS             += -DCC_VERSION=$(CC_VERSION)
  CFLAGS                += -DCC_VERSION=$(CC_VERSION)
  CXXFLAGS      += -DCC_VERSION=$(CC_VERSION)
  GOCFLAGS      += -DCC_VERSION=$(CC_VERSION)
-
+GDCFLAGS       += -DCC_VERSION=$(CC_VERSION)
  # ensure $(BUILD_DIR)/kconfig, $(BUILD_DIR)/include and 
$(BUILD_DIR)/include/uk exists
  $(call mk_sub_build_dir,kconfig)
  $(call mk_sub_build_dir,include)
@@ -547,7 +557,8 @@ ASINCLUDES            += -I$(UK_GENERATED_INCLUDES)
  CINCLUDES             += -I$(UK_GENERATED_INCLUDES)
  CXXINCLUDES           += -I$(UK_GENERATED_INCLUDES)
  GOCINCLUDES           += -I$(UK_GENERATED_INCLUDES)
-
+DMDINCLUDES           += -I$(UK_GENERATED_INCLUDES)
+GDCINCLUDES           += -I$(UK_GENERATED_INCLUDES)
  
################################################################################
  # Build rules
  
################################################################################
diff --git a/Makefile.uk b/Makefile.uk
index 3f01a25..5356fb2 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -22,6 +22,13 @@ GOCFLAGS    += -fno-stack-protector -fno-omit-frame-pointer 
-fno-tree-sra
  GOCFLAGS    += -fno-split-stack -Wall -Wextra
  GOCINCLUDES += -nostdinc -nostdlib -I$(CONFIG_UK_BASE)/include
+DMDINCLUDES += -I$(CONFIG_UK_BASE)/include
+
+GDCFLAGS    += -U __linux__ -U __FreeBSD__ -U __sun__
+GDCFLAGS    += -fno-stack-protector -fno-omit-frame-pointer -fno-tree-sra
+GDCFLAGS    += -fno-split-stack -Wall -Wextra
+GDCINCLUDES += -nostdinc -nostdlib -nophoboslib -I$(CONFIG_UK_BASE)/include
+
  # Set the text and data sections to be readable and writable. Also,
  # do not page-align the data segment. If the output format supports
  # Unix style magic numbers, mark the output as OMAGIC.
@@ -31,22 +38,27 @@ LDFLAGS     += -nostdinc -nostdlib -Wl,--omagic 
-Wl,--build-id=none
  CFLAGS-$(CONFIG_OPTIMIZE_NONE)            += -O0 -fno-optimize-sibling-calls 
-fno-tree-vectorize
  CXXFLAGS-$(CONFIG_OPTIMIZE_NONE)          += -O0 -fno-optimize-sibling-calls 
-fno-tree-vectorize
  GOCFLAGS-$(CONFIG_OPTIMIZE_NONE)          += -O0 -fno-optimize-sibling-calls 
-fno-tree-vectorize
+GDCFLAGS-$(CONFIG_OPTIMIZE_NONE)          += -O0 -fno-optimize-sibling-calls 
-fno-tree-vectorize
  CFLAGS-$(CONFIG_OPTIMIZE_PERF)            += -O2
  CXXFLAGS-$(CONFIG_OPTIMIZE_PERF)          += -O2
  GOCFLAGS-$(CONFIG_OPTIMIZE_PERF)          += -O2
+GDCFLAGS-$(CONFIG_OPTIMIZE_PERF)          += -O2
  CFLAGS-$(CONFIG_OPTIMIZE_SIZE)            += -Os
  CXXFLAGS-$(CONFIG_OPTIMIZE_SIZE)          += -Os
  GOCFLAGS-$(CONFIG_OPTIMIZE_SIZE)          += -Os
+GDCFLAGS-$(CONFIG_OPTIMIZE_SIZE)          += -Os
CFLAGS-$(CONFIG_OPTIMIZE_DEADELIM) += -fdata-sections -ffunction-sections
  CXXFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)      += -fdata-sections 
-ffunction-sections
  GOCFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)      += -fdata-sections 
-ffunction-sections
+GDCFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)      += -fdata-sections 
-ffunction-sections
  LDFLAGS-$(CONFIG_OPTIMIZE_DEADELIM)       += -Wl,--gc-sections
# LTO requires the compiler flags to be handed over also for linking
  CFLAGS-$(CONFIG_OPTIMIZE_LTO)             += -flto
  CXXFLAGS-$(CONFIG_OPTIMIZE_LTO)           += -flto
  GOCFLAGS-$(CONFIG_OPTIMIZE_LTO)           += -flto
+GDCFLAGS-$(CONFIG_OPTIMIZE_LTO)           += -flto
  LIBLDFLAGS-$(CONFIG_OPTIMIZE_LTO)         += $(CFLAGS) $(CFLAGS-y)
  LDFLAGS-$(CONFIG_OPTIMIZE_LTO)            += $(CFLAGS) $(CFLAGS-y)
@@ -67,6 +79,9 @@ CXXFLAGS += -DUK_FULLVERSION=$(UK_FULLVERSION)
  GOCFLAGS += -D __Unikraft__ -DUK_CODENAME="$(UK_CODENAME)"
  GOCFLAGS += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
  GOCFLAGS += -DUK_FULLVERSION=$(UK_FULLVERSION)
+GDCFLAGS += -D __Unikraft__ -DUK_CODENAME="$(UK_CODENAME)"
+GDCFLAGS += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
+GDCFLAGS += -DUK_FULLVERSION=$(UK_FULLVERSION)
  M4FLAGS  += -D __Unikraft__ -DUK_CODENAME="$(UK_CODENAME)"
  M4FLAGS  += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
@@ -77,5 +92,6 @@ ASFLAGS-$(call gcc_version_ge,6,1) += -no-pie
  CFLAGS-$(call gcc_version_ge,6,1)     += -no-pie
  CXXFLAGS-$(call gcc_version_ge,6,1)   += -no-pie
  GOFLAGS-$(call gcc_version_ge,6,1)    += -no-pie
+GDCFLAGS-$(call gcc_version_ge,6,1)    += -no-pie
  LIBLDFLAGS-$(call gcc_version_ge,6,1) += -no-pie
  LDFLAGS-$(call gcc_version_ge,6,1)    += -no-pie
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index a13180a..65cc155 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -464,6 +464,51 @@ $(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
  $(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call 
out2dep,$(3)))
  endef
+define buildrule_dmd =
+$(3): $(2) | prepare
+       $(call build_cmd,DMD,$(1),$(3),\
+               $(DMD) -betterC $(DMDINCLUDES) $(DMDINCLUDES-y) \
+                       $($(call vprefix_lib,$(1),DMDINCLUDES)) $($(call 
vprefix_lib,$(1),DMDINCLUDES-y)) \
+                   $(DMDFLAGS) $(DMDFLAGS-y) $($(call 
vprefix_lib,$(1),DMDFLAGS)) \
+            $($(call vprefix_lib,$(1),DMDFLAGS-y)) \
+            $(2) -c -od=$(dir $(3))
+       )
+
+UK_SRCS-y += $(2)
+UK_DEPS-y += $(call out2dep,$(3))
+UK_OBJS-y += $(3)
+$(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
+$(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call 
out2dep,$(3)))
+endef
+
+define buildrule_gdc =
+$(3): $(2) | prepare
+       $(call build_cmd,GDC,$(1),$(3),\
+               $(GDC) $(GDCINCLUDES) $(GDCINCLUDES-y) \
+                       $($(call vprefix_lib,$(1),GDCINCLUDES)) $($(call 
vprefix_lib,$(1),GDCINCLUDES-y)) \
+                       $(GDCFLAGS) $(GDCFLAGS-y) $(DBGFLAGS) $(DBGFLAGS-y) \
+                       $($(call vprefix_lib,$(1),GDCFLAGS)) $($(call 
vprefix_lib,$(1),GDCFLAGS-y)) \
+                       $(4) -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) \
+                       -c $(2) -o $(3) $(depflags)
+       )
+
+UK_SRCS-y += $(2)
+UK_DEPS-y += $(call out2dep,$(3))
+UK_OBJS-y += $(3)
+$(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
+$(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call 
out2dep,$(3)))
+endef
+
+ifeq ($(D_COMPILER),dmd)
+    define buildrule_d =
+        $(buildrule_dmd)
+    endef
+else
+    define buildrule_d =
+        $(buildrule_gdc)
+    endef
+endif
+
  define add_lds_to_plat =
  $(eval $(call uc,$(2))_LD_SCRIPT-y += $(1))
  endef
@@ -544,8 +589,9 @@ $(if $(filter %.CPP,  $(2)),$(call buildrule_cc 
,$(1),$(2),$(3),$(4)),\
  $(if $(filter %.c++,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
  $(if $(filter %.C,    $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
  $(if $(filter %.go,   $(2)),$(call buildrule_go ,$(1),$(2),$(3),$(4)),\
+$(if $(filter %.d,   $(2)),$(call buildrule_d ,$(1),$(2),$(3),$(4)),\
  $(error $(3): missing build rule for source type $(suffix $(2))) \
-)))))))))))))))
+))))))))))))))))
  endef



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.