hello_swift added
required: swift 6 (embedded module)
This commit is contained in:
parent
d37b326cb1
commit
7c4590b818
@ -77,27 +77,30 @@ CXXOBJS = $(CXXSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
RUSTOBJS = $(RUSTSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
ZIGOBJS = $(ZIGSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
DOBJS = $(DSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
SWIFTOBJS = $(SWIFTSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
|
||||
MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
|
||||
MAINCSRCS = $(filter %.c,$(MAINSRC))
|
||||
MAINRUSTSRCS = $(filter %$(RUSTEXT),$(MAINSRC))
|
||||
MAINZIGSRCS = $(filter %$(ZIGEXT),$(MAINSRC))
|
||||
MAINDSRCS = $(filter %$(DEXT),$(MAINSRC))
|
||||
MAINSWIFTSRCS = $(filter %$(SWIFTEXT),$(MAINSRC))
|
||||
MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
MAINRUSTOBJ = $(MAINRUSTSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
MAINZIGOBJ = $(MAINZIGSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
MAINDOBJ = $(MAINDSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
MAINSWIFTOBJ = $(MAINSWIFTSRCS:=$(SUFFIX)$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
|
||||
OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS) $(DOBJS) $(EXTOBJS)
|
||||
OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS) $(DOBJS) $(SWIFTOBJS) $(EXTOBJS)
|
||||
|
||||
ifneq ($(BUILD_MODULE),y)
|
||||
OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ)
|
||||
OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ)
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(PROGNAME)),)
|
||||
PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ)
|
||||
PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ)
|
||||
PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGNAME))
|
||||
REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME)))
|
||||
|
||||
@ -135,6 +138,7 @@ endif
|
||||
ZIGELFFLAGS ?= $(ZIGFLAGS)
|
||||
RUSTELFFLAGS ?= $(RUSTFLAGS)
|
||||
DELFFLAGS ?= $(DFLAGS)
|
||||
SWIFTELFFLAGS ?= $(SWIFTFLAGS)
|
||||
|
||||
DEPPATH += --dep-path .
|
||||
DEPPATH += --obj-path .
|
||||
@ -185,6 +189,12 @@ define ELFCOMPILED
|
||||
$(ECHO_END)
|
||||
endef
|
||||
|
||||
define ELFCOMPILESWIFT
|
||||
$(ECHO_BEGIN)"SWIFTC: $1 "
|
||||
$(Q) $(SWIFTC) -c $(SWIFTELFFLAGS) $($(strip $1)_SWIFTELFFLAGS) $1 -o $2
|
||||
$(ECHO_END)
|
||||
endef
|
||||
|
||||
define ELFLD
|
||||
$(ECHO_BEGIN)"LD: $2 "
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDSTARTGROUP) $(LDLIBS) $(LDENDGROUP) -o $2
|
||||
@ -226,6 +236,10 @@ $(DOBJS): %$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
|
||||
$(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
|
||||
|
||||
$(SWIFTOBJS): %$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
|
||||
$(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@))
|
||||
|
||||
AROBJS :=
|
||||
ifneq ($(OBJS),)
|
||||
SORTOBJS := $(sort $(OBJS))
|
||||
@ -264,7 +278,11 @@ $(MAINDOBJ): %$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
|
||||
|
||||
$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ)
|
||||
$(MAINSWIFTOBJ): %$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@))
|
||||
|
||||
$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ)
|
||||
$(Q) mkdir -p $(BINDIR)
|
||||
$(call ELFLD, $(PROGOBJ_$@), $(call CONVERT_PATH,$@))
|
||||
$(Q) chmod +x $@
|
||||
@ -303,6 +321,10 @@ $(MAINDOBJ): %$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
|
||||
|
||||
$(MAINSWIFTOBJ): %$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT)
|
||||
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
|
||||
$(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@))
|
||||
|
||||
install::
|
||||
@:
|
||||
|
||||
|
@ -55,6 +55,7 @@ CXXEXT ?= .cxx
|
||||
RUSTEXT ?= .rs
|
||||
ZIGEXT ?= .zig
|
||||
DEXT ?= .d
|
||||
SWIFTEXT ?= .swift
|
||||
|
||||
# Library path
|
||||
|
||||
|
28
examples/hello_swift/BridgingHeader.h
Normal file
28
examples/hello_swift/BridgingHeader.h
Normal file
@ -0,0 +1,28 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/hello_swift/BridgingHeader.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
#ifndef BridgingHeader_h
|
||||
#define BridgingHeader_h
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#endif // BridgingHeader_h
|
29
examples/hello_swift/Kconfig
Normal file
29
examples/hello_swift/Kconfig
Normal file
@ -0,0 +1,29 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_HELLO_SWIFT
|
||||
tristate "\"Hello, Swift!\" Swift embedded example"
|
||||
default n
|
||||
---help---
|
||||
Enable the \"Hello, Swift!\" Swift embedded example
|
||||
|
||||
if EXAMPLES_HELLO_SWIFT
|
||||
|
||||
config EXAMPLES_HELLO_SWIFT_PROGNAME
|
||||
string "Program name"
|
||||
default "hello_swift"
|
||||
---help---
|
||||
This is the name of the program that will be used when the
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_HELLO_SWIFT_PRIORITY
|
||||
int "Hello Swift task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_HELLO_SWIFT_STACKSIZE
|
||||
int "Hello Swift stack size"
|
||||
default DEFAULT_TASK_STACKSIZE
|
||||
|
||||
endif
|
23
examples/hello_swift/Make.defs
Normal file
23
examples/hello_swift/Make.defs
Normal file
@ -0,0 +1,23 @@
|
||||
############################################################################
|
||||
# apps/examples/hello_swift/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_HELLO_SWIFT),)
|
||||
CONFIGURED_APPS += $(APPDIR)/examples/hello_swift
|
||||
endif
|
37
examples/hello_swift/Makefile
Normal file
37
examples/hello_swift/Makefile
Normal file
@ -0,0 +1,37 @@
|
||||
############################################################################
|
||||
# apps/examples/hello_swift/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# Hello, World! Swift Embedded Example
|
||||
|
||||
MAINSRC = hello_swift_main.swift
|
||||
|
||||
# hello_swift built-in application info
|
||||
|
||||
SWIFTFLAGS += -import-bridging-header BridgingHeader.h -I$(TOPDIR)/include
|
||||
SWIFTFLAGS += -Xfrontend -function-sections -Xfrontend -disable-stack-protector
|
||||
SWIFTFLAGS += -Xfrontend -enable-single-module-llvm-emission
|
||||
PROGNAME = $(CONFIG_EXAMPLES_HELLO_SWIFT_PROGNAME)
|
||||
PRIORITY = $(CONFIG_EXAMPLES_HELLO_SWIFT_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_HELLO_SWIFT_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_HELLO_SWIFT)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
33
examples/hello_swift/hello_swift_main.swift
Normal file
33
examples/hello_swift/hello_swift_main.swift
Normal file
@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/hello_swift/hello_swift_main.swift
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hello_swift_main
|
||||
****************************************************************************/
|
||||
func swiftMain() {
|
||||
print("Hello from Swift embedded!")
|
||||
}
|
||||
|
||||
// Create a C-compatible entry point
|
||||
@_cdecl("hello_swift_main")
|
||||
public func cMain(_ argc: Int32, _ argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> Int32 {
|
||||
swiftMain()
|
||||
return 0
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user