summaryrefslogtreecommitdiff
path: root/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/Makefile.am10
-rwxr-xr-xtutorial/cl/Makefile.am66
-rw-r--r--tutorial/cl/load-locally.lisp22
-rw-r--r--tutorial/cl/make-tutorial-client.lisp54
-rw-r--r--tutorial/cl/make-tutorial-server.lisp32
-rw-r--r--tutorial/cl/shared-implementation.lisp25
-rw-r--r--tutorial/cl/thrift-tutorial.asd17
-rw-r--r--tutorial/cl/tutorial-implementation.lisp41
-rw-r--r--tutorial/dart/client/pubspec.yaml2
-rw-r--r--tutorial/dart/console_client/pubspec.yaml2
-rw-r--r--tutorial/dart/server/pubspec.yaml2
-rw-r--r--tutorial/delphi/DelphiClient/DelphiClient.dproj4
-rw-r--r--tutorial/delphi/DelphiServer/DelphiServer.dproj4
-rw-r--r--tutorial/haxe/cpp.hxml6
-rw-r--r--tutorial/haxe/csharp.hxml6
-rw-r--r--tutorial/haxe/flash.hxml6
-rw-r--r--tutorial/haxe/java.hxml6
-rw-r--r--tutorial/haxe/javascript.hxml6
-rw-r--r--tutorial/haxe/neko.hxml6
-rw-r--r--tutorial/haxe/php-web-server.hxml3
-rw-r--r--tutorial/haxe/php.hxml6
-rw-r--r--tutorial/haxe/python.hxml6
-rw-r--r--tutorial/netstd/Client/Client.csproj2
-rw-r--r--tutorial/netstd/Interfaces/Interfaces.csproj2
-rw-r--r--tutorial/netstd/Server/Server.csproj2
-rw-r--r--tutorial/ocaml/_oasis2
-rw-r--r--tutorial/rs/Cargo.toml2
-rw-r--r--tutorial/shared.thrift1
-rw-r--r--tutorial/swift/Makefile.am33
-rw-r--r--tutorial/swift/Package.swift53
-rw-r--r--tutorial/swift/README.md11
-rw-r--r--tutorial/swift/Sources/TutorialClient/main.swift45
-rw-r--r--tutorial/swift/Sources/TutorialRunner/main.swift36
-rw-r--r--tutorial/swift/Sources/TutorialServer/CalculatorService.swift73
-rw-r--r--tutorial/swift/Sources/TutorialServer/main.swift28
l---------tutorial/swift/swift-dep1
-rw-r--r--tutorial/tutorial.thrift1
37 files changed, 584 insertions, 40 deletions
diff --git a/tutorial/Makefile.am b/tutorial/Makefile.am
index 77e8593ea..24969d13b 100644
--- a/tutorial/Makefile.am
+++ b/tutorial/Makefile.am
@@ -74,6 +74,10 @@ if WITH_RS
SUBDIRS += rs
endif
+if WITH_CL
+SUBDIRS += cl
+endif
+
if WITH_PERL
SUBDIRS += perl
endif
@@ -82,8 +86,12 @@ if WITH_PHP
SUBDIRS += php
endif
+if WITH_SWIFT
+SUBDIRS += swift
+endif
+
#
-# generate html for ThriftTest.thrift
+# generate html for tutorial.thrift
#
all-local:
$(top_builddir)/compiler/cpp/thrift --gen html -r $(top_srcdir)/tutorial/tutorial.thrift
diff --git a/tutorial/cl/Makefile.am b/tutorial/cl/Makefile.am
new file mode 100755
index 000000000..70c5e0730
--- /dev/null
+++ b/tutorial/cl/Makefile.am
@@ -0,0 +1,66 @@
+#
+# 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.
+
+setup-local-lisp-env: ../../lib/cl/ensure-externals.sh
+ bash ../../lib/cl/ensure-externals.sh
+
+gen-cl: $(top_srcdir)/tutorial/tutorial.thrift
+ $(THRIFT) --gen cl -r $<
+
+ALL_FILE_PREREQS = \
+ load-locally.lisp \
+ make-tutorial-server.lisp \
+ make-tutorial-client.lisp \
+ shared-implementation.lisp \
+ thrift-tutorial.asd \
+ tutorial-implementation.lisp
+
+# NOTE: the server and client cannot be built in parallel
+# because on loading the make-tutorial-* scripts SBCL will
+# attempt to compile their dependencies. Unfortunately,
+# because their dependencies are shared, parallel jobs can
+# end up overwriting or corrupting the compiled files
+all-local: gen-cl setup-local-lisp-env $(ALL_FILE_PREREQS)
+ $(SBCL) --script make-tutorial-server.lisp
+ $(SBCL) --script make-tutorial-client.lisp
+
+tutorialserver: all
+ ./TutorialServer
+
+tutorialclient: all
+ ./TutorialClient
+
+clean-local:
+ -$(RM) -r gen-*
+ -$(RM) -r externals
+ -$(RM) -r quicklisp
+ -$(RM) -r lib
+ -$(RM) quicklisp.lisp
+ -$(RM) backport-update.zip
+ -$(RM) shared-implementation.fasl
+ -$(RM) tutorial-implementation.fasl
+ -$(RM) TutorialServer
+ -$(RM) TutorialClient
+
+EXTRA_DIST = \
+ tutorial-implementation.lisp \
+ shared-implementation.lisp \
+ thrift-tutorial.asd \
+ make-tutorial-server.lisp \
+ make-tutorial-client.lisp \
+ load-locally.lisp
diff --git a/tutorial/cl/load-locally.lisp b/tutorial/cl/load-locally.lisp
new file mode 100644
index 000000000..b52a0a269
--- /dev/null
+++ b/tutorial/cl/load-locally.lisp
@@ -0,0 +1,22 @@
+(in-package #:cl-user)
+
+;;;; Licensed 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.
+
+;;;; Just a script for loading the library itself, using bundled dependencies.
+;;;; This is an identical copy of the file in lib/cl.
+
+(require "asdf")
+
+(load (merge-pathnames "externals/bundle.lisp" *load-truename*))
+(asdf:load-asd (merge-pathnames "lib/de.setf.thrift-backport-update/thrift.asd" *load-truename*))
+(asdf:load-system :thrift)
diff --git a/tutorial/cl/make-tutorial-client.lisp b/tutorial/cl/make-tutorial-client.lisp
new file mode 100644
index 000000000..5b8183e20
--- /dev/null
+++ b/tutorial/cl/make-tutorial-client.lisp
@@ -0,0 +1,54 @@
+(in-package #:cl-user)
+
+;;;; Licensed 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.
+
+(require "asdf")
+(load (merge-pathnames "load-locally.lisp" *load-truename*))
+(require "sb-grovel") ;; necessary for :net.didierverna.clon.termio
+(asdf:load-asd (first (directory (merge-pathnames "../../lib/cl/externals/software/clon-*/termio/net.didierverna.clon.termio.asd"
+ *load-truename*))))
+(asdf:load-system :net.didierverna.clon)
+(asdf:load-asd (merge-pathnames "gen-cl/shared/thrift-gen-shared.asd" *load-truename*))
+(asdf:load-asd (merge-pathnames "gen-cl/tutorial/thrift-gen-tutorial.asd" *load-truename*))
+(asdf:load-asd (merge-pathnames "thrift-tutorial.asd" *load-truename*))
+(asdf:load-system :thrift-tutorial)
+
+(net.didierverna.clon:nickname-package)
+
+(defun main ()
+ "Entry point for the binary."
+ (thrift:with-client (prot #u"thrift://127.0.0.1:9090")
+ (tutorial.calculator:ping prot)
+ (format t "ping()~%")
+ (format t "1 + 1 = ~a~%" (tutorial.calculator:add prot 1 1))
+ (let ((work-instance (tutorial:make-work :num1 5
+ :num2 0
+ :op tutorial:operation.divide
+ :comment "Booya!")))
+ (handler-case (format t
+ "5 / 0 = ~a - Oh, really? An exception should have been thrown here.~%"
+ (tutorial.calculator:calculate prot 1 work-instance))
+ (tutorial:invalidoperation (e)
+ (format t "---~%(Expected) Invalid Operation caught: ~%~a~%---~%" e))))
+ (let ((work-instance (tutorial:make-work :num1 15
+ :num2 10
+ :op tutorial:operation.subtract
+ :comment "Playing nice this time.")))
+ (handler-case (format t
+ "15 - 10 = ~a~%"
+ (tutorial.calculator:calculate prot 1 work-instance))
+ (tutorial:invalidoperation (e)
+ (format t "---~%(Unexpected) Invalid Operation caught: ~%~a~%---~%" e))))
+ (format t "Check log: ~a~%" (shared.shared-service:get-struct prot 1))))
+
+(clon:dump "TutorialClient" main)
diff --git a/tutorial/cl/make-tutorial-server.lisp b/tutorial/cl/make-tutorial-server.lisp
new file mode 100644
index 000000000..9f47be82b
--- /dev/null
+++ b/tutorial/cl/make-tutorial-server.lisp
@@ -0,0 +1,32 @@
+(in-package #:cl-user)
+
+;;;; Licensed 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.
+
+(require "asdf")
+(load (merge-pathnames "load-locally.lisp" *load-truename*))
+(require "sb-grovel") ;; necessary for :net.didierverna.clon.termio
+(asdf:load-asd (first (directory (merge-pathnames "../../lib/cl/externals/software/clon-*/termio/net.didierverna.clon.termio.asd"
+ *load-truename*))))
+(asdf:load-system :net.didierverna.clon)
+(asdf:load-asd (merge-pathnames "gen-cl/shared/thrift-gen-shared.asd" *load-truename*))
+(asdf:load-asd (merge-pathnames "gen-cl/tutorial/thrift-gen-tutorial.asd" *load-truename*))
+(asdf:load-asd (merge-pathnames "thrift-tutorial.asd" *load-truename*))
+(asdf:load-system :thrift-tutorial)
+
+(net.didierverna.clon:nickname-package)
+
+(defun main ()
+ "Entry point for the binary."
+ (thrift:serve #u"thrift://127.0.0.1:9090" tutorial:calculator))
+
+(clon:dump "TutorialServer" main)
diff --git a/tutorial/cl/shared-implementation.lisp b/tutorial/cl/shared-implementation.lisp
new file mode 100644
index 000000000..c197626a5
--- /dev/null
+++ b/tutorial/cl/shared-implementation.lisp
@@ -0,0 +1,25 @@
+(in-package #:shared-implementation)
+
+;;;; Licensed 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.
+
+(defvar *structs* (make-hash-table))
+
+(defun shared.shared-service-implementation:get-struct (key)
+ (format t "getStruct(~a)~%" key)
+ (gethash key *structs*))
+
+(defun add-log (key value)
+ (setf (gethash key *structs*)
+ (make-instance 'shared:sharedstruct
+ :key key
+ :value (write-to-string value))))
diff --git a/tutorial/cl/thrift-tutorial.asd b/tutorial/cl/thrift-tutorial.asd
new file mode 100644
index 000000000..8a0353763
--- /dev/null
+++ b/tutorial/cl/thrift-tutorial.asd
@@ -0,0 +1,17 @@
+;;;; Licensed 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.
+
+(asdf:defsystem #:thrift-tutorial
+ :depends-on (#:thrift-gen-tutorial)
+ :serial t
+ :components ((:file "shared-implementation")
+ (:file "tutorial-implementation")))
diff --git a/tutorial/cl/tutorial-implementation.lisp b/tutorial/cl/tutorial-implementation.lisp
new file mode 100644
index 000000000..5c92fe405
--- /dev/null
+++ b/tutorial/cl/tutorial-implementation.lisp
@@ -0,0 +1,41 @@
+(in-package #:tutorial-implementation)
+
+;;;; Licensed 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.
+
+(defun tutorial.calculator-implementation:ping ()
+ (format t "ping()~%"))
+
+(defun tutorial.calculator-implementation:add (num1 num2)
+ (format t "add(~a, ~a)~%" num1 num2)
+ (+ num1 num2))
+
+(defun tutorial.calculator-implementation:calculate (logid work)
+ (format t "calculate(~a, ~a)~%" logid work)
+ (handler-case
+ (let* ((num1 (tutorial:work-num1 work))
+ (num2 (tutorial:work-num2 work))
+ (op (tutorial:work-op work))
+ (result
+ (cond
+ ((= op tutorial:operation.add) (+ num1 num2))
+ ((= op tutorial:operation.subtract) (- num1 num2))
+ ((= op tutorial:operation.multiply) (* num1 num2))
+ ((= op tutorial:operation.divide) (/ num1 num2)))))
+ (shared-implementation::add-log logid result)
+ result)
+ (division-by-zero () (error 'tutorial:invalidoperation
+ :why "Division by zero."
+ :what-op (tutorial:work-op work)))))
+
+(defun tutorial.calculator-implementation:zip ()
+ (format t "zip()~%"))
diff --git a/tutorial/dart/client/pubspec.yaml b/tutorial/dart/client/pubspec.yaml
index 028f0033f..dda5ff0eb 100644
--- a/tutorial/dart/client/pubspec.yaml
+++ b/tutorial/dart/client/pubspec.yaml
@@ -16,7 +16,7 @@
# under the License.
name: tutorial_client
-version: 0.17.0
+version: 0.18.0
description: A Dart client implementation of the Apache Thrift tutorial
author: Apache Thrift Developers <dev@thrift.apache.org>
homepage: http://thrift.apache.org
diff --git a/tutorial/dart/console_client/pubspec.yaml b/tutorial/dart/console_client/pubspec.yaml
index 435177f3c..7aeea57e7 100644
--- a/tutorial/dart/console_client/pubspec.yaml
+++ b/tutorial/dart/console_client/pubspec.yaml
@@ -16,7 +16,7 @@
# under the License.
name: tutorial_console_client
-version: 0.17.0
+version: 0.18.0
description: >
A Dart console client to implementation of the Apache Thrift tutorial
author: Apache Thrift Developers <dev@thrift.apache.org>
diff --git a/tutorial/dart/server/pubspec.yaml b/tutorial/dart/server/pubspec.yaml
index 05900946d..0ac202a2b 100644
--- a/tutorial/dart/server/pubspec.yaml
+++ b/tutorial/dart/server/pubspec.yaml
@@ -16,7 +16,7 @@
# under the License.
name: tutorial_server
-version: 0.17.0
+version: 0.18.0
description: A Dart server to support the Apache Thrift tutorial
author: Apache Thrift Developers <dev@thrift.apache.org>
homepage: http://thrift.apache.org
diff --git a/tutorial/delphi/DelphiClient/DelphiClient.dproj b/tutorial/delphi/DelphiClient/DelphiClient.dproj
index ec487e909..45daec2d3 100644
--- a/tutorial/delphi/DelphiClient/DelphiClient.dproj
+++ b/tutorial/delphi/DelphiClient/DelphiClient.dproj
@@ -124,13 +124,13 @@ popd]]></PreBuildEvent>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription">Thrift Tutorial</VersionInfoKeys>
- <VersionInfoKeys Name="FileVersion">0.17.0.0</VersionInfoKeys>
+ <VersionInfoKeys Name="FileVersion">0.18.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName">DelphiClient</VersionInfoKeys>
<VersionInfoKeys Name="LegalCopyright">Copyright © 2012 The Apache Software Foundation</VersionInfoKeys>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename">DelphiClient.exe</VersionInfoKeys>
<VersionInfoKeys Name="ProductName">Thrift</VersionInfoKeys>
- <VersionInfoKeys Name="ProductVersion">0.17.0.0</VersionInfoKeys>
+ <VersionInfoKeys Name="ProductVersion">0.18.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
</VersionInfoKeys>
<Source>
diff --git a/tutorial/delphi/DelphiServer/DelphiServer.dproj b/tutorial/delphi/DelphiServer/DelphiServer.dproj
index 31e8fd85c..91cf7bb91 100644
--- a/tutorial/delphi/DelphiServer/DelphiServer.dproj
+++ b/tutorial/delphi/DelphiServer/DelphiServer.dproj
@@ -121,13 +121,13 @@ popd]]></PreBuildEvent>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription">Thrift Tutorial</VersionInfoKeys>
- <VersionInfoKeys Name="FileVersion">0.17.0.0</VersionInfoKeys>
+ <VersionInfoKeys Name="FileVersion">0.18.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName">DelphiServer</VersionInfoKeys>
<VersionInfoKeys Name="LegalCopyright">Copyright © 2012 The Apache Software Foundation</VersionInfoKeys>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename">DelphiServer.exe</VersionInfoKeys>
<VersionInfoKeys Name="ProductName">Thrift</VersionInfoKeys>
- <VersionInfoKeys Name="ProductVersion">0.17.0.0</VersionInfoKeys>
+ <VersionInfoKeys Name="ProductVersion">0.18.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
</VersionInfoKeys>
<Source>
diff --git a/tutorial/haxe/cpp.hxml b/tutorial/haxe/cpp.hxml
index 6adb52d7e..1b581a924 100644
--- a/tutorial/haxe/cpp.hxml
+++ b/tutorial/haxe/cpp.hxml
@@ -31,11 +31,11 @@
#To produce 64 bit binaries the file should define the HXCPP_M64 compile variable:
#-D HXCPP_M64
+# libs
+-lib uuid
+
#Add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/haxe/csharp.hxml b/tutorial/haxe/csharp.hxml
index 295c017e7..41d20adcc 100644
--- a/tutorial/haxe/csharp.hxml
+++ b/tutorial/haxe/csharp.hxml
@@ -28,11 +28,11 @@
#CSHARP target
-cs bin/Tutorial.exe
+# libs
+-lib uuid
+
#Add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/haxe/flash.hxml b/tutorial/haxe/flash.hxml
index a1f0568ad..50c4a6046 100644
--- a/tutorial/haxe/flash.hxml
+++ b/tutorial/haxe/flash.hxml
@@ -28,6 +28,9 @@
#Flash target
-swf bin/Tutorial.swf
+# libs
+-lib uuid
+
#Add debug information
-debug
@@ -35,7 +38,4 @@
# --macro allowPackage("sys")
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/haxe/java.hxml b/tutorial/haxe/java.hxml
index c615565a9..1f810c7aa 100644
--- a/tutorial/haxe/java.hxml
+++ b/tutorial/haxe/java.hxml
@@ -28,11 +28,11 @@
#Java target
-java bin/Tutorial.jar
+# libs
+-lib uuid
+
#Add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/haxe/javascript.hxml b/tutorial/haxe/javascript.hxml
index b2b3876cf..b9a39bbb0 100644
--- a/tutorial/haxe/javascript.hxml
+++ b/tutorial/haxe/javascript.hxml
@@ -34,11 +34,11 @@
#you modify your .hx files.
-D source-map-content
+# libs
+-lib uuid
+
#Generate source map and add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/haxe/neko.hxml b/tutorial/haxe/neko.hxml
index 6161f6977..00b055637 100644
--- a/tutorial/haxe/neko.hxml
+++ b/tutorial/haxe/neko.hxml
@@ -28,11 +28,11 @@
#neko target
-neko bin/Tutorial.n
+# libs
+-lib uuid
+
#Add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/haxe/php-web-server.hxml b/tutorial/haxe/php-web-server.hxml
index c6e9432a3..4961cfa58 100644
--- a/tutorial/haxe/php-web-server.hxml
+++ b/tutorial/haxe/php-web-server.hxml
@@ -39,7 +39,4 @@
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full
diff --git a/tutorial/haxe/php.hxml b/tutorial/haxe/php.hxml
index 42bbf7424..847da3bd2 100644
--- a/tutorial/haxe/php.hxml
+++ b/tutorial/haxe/php.hxml
@@ -29,11 +29,11 @@
-php bin/php/
-D php-front=Main-debug.php
+# libs
+-lib uuid
+
#Add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full
diff --git a/tutorial/haxe/python.hxml b/tutorial/haxe/python.hxml
index f2c19fa93..e5910428f 100644
--- a/tutorial/haxe/python.hxml
+++ b/tutorial/haxe/python.hxml
@@ -28,11 +28,11 @@
#Python target
-python bin/Tutorial.py
+# libs
+-lib uuid
+
#Add debug information
-debug
#dead code elimination : remove unused code
-#"-dce no" : do not remove unused code
-#"-dce std" : remove unused code in the std lib (default)
-#"-dce full" : remove all unused code
-dce full \ No newline at end of file
diff --git a/tutorial/netstd/Client/Client.csproj b/tutorial/netstd/Client/Client.csproj
index 158e59243..c07f9cdd6 100644
--- a/tutorial/netstd/Client/Client.csproj
+++ b/tutorial/netstd/Client/Client.csproj
@@ -24,7 +24,7 @@
<AssemblyName>Client</AssemblyName>
<PackageId>Client</PackageId>
<OutputType>Exe</OutputType>
- <Version>0.17.0.0</Version>
+ <Version>0.18.0.0</Version>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
diff --git a/tutorial/netstd/Interfaces/Interfaces.csproj b/tutorial/netstd/Interfaces/Interfaces.csproj
index d04b243f3..544c532f1 100644
--- a/tutorial/netstd/Interfaces/Interfaces.csproj
+++ b/tutorial/netstd/Interfaces/Interfaces.csproj
@@ -22,7 +22,7 @@
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>Interfaces</AssemblyName>
<PackageId>Interfaces</PackageId>
- <Version>0.17.0.0</Version>
+ <Version>0.18.0.0</Version>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
diff --git a/tutorial/netstd/Server/Server.csproj b/tutorial/netstd/Server/Server.csproj
index cf11a7501..b55b00877 100644
--- a/tutorial/netstd/Server/Server.csproj
+++ b/tutorial/netstd/Server/Server.csproj
@@ -24,7 +24,7 @@
<AssemblyName>Server</AssemblyName>
<PackageId>Server</PackageId>
<OutputType>Exe</OutputType>
- <Version>0.17.0.0</Version>
+ <Version>0.18.0.0</Version>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
diff --git a/tutorial/ocaml/_oasis b/tutorial/ocaml/_oasis
index 9e211fc43..0eaa5687e 100644
--- a/tutorial/ocaml/_oasis
+++ b/tutorial/ocaml/_oasis
@@ -1,5 +1,5 @@
Name: tutorial
-Version: 0.17.0
+Version: 0.18.0
OASISFormat: 0.3
Synopsis: OCaml Tutorial example
Authors: Apache Thrift Developers <dev@thrift.apache.org>
diff --git a/tutorial/rs/Cargo.toml b/tutorial/rs/Cargo.toml
index e6e1d7cac..696798432 100644
--- a/tutorial/rs/Cargo.toml
+++ b/tutorial/rs/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "thrift-tutorial"
version = "0.1.0"
-edition = "2018"
+edition = "2021"
license = "Apache-2.0"
authors = ["Apache Thrift Developers <dev@thrift.apache.org>"]
exclude = ["Makefile*", "shared.rs", "tutorial.rs"]
diff --git a/tutorial/shared.thrift b/tutorial/shared.thrift
index 795e9cb93..3c6a69db8 100644
--- a/tutorial/shared.thrift
+++ b/tutorial/shared.thrift
@@ -22,6 +22,7 @@
* these definitions.
*/
+namespace cl shared
namespace cpp shared
namespace d share // "shared" would collide with the eponymous D keyword.
namespace dart shared
diff --git a/tutorial/swift/Makefile.am b/tutorial/swift/Makefile.am
new file mode 100644
index 000000000..f48456054
--- /dev/null
+++ b/tutorial/swift/Makefile.am
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+#
+# Common thrift code generation rules
+#
+gen_swift:
+ $(THRIFT) --gen swift -r -o Sources/Common $(top_srcdir)/tutorial/tutorial.thrift
+
+tutorial: gen_swift
+ swift run TutorialRunner
+
+tutorialserver: gen_swift
+ swift run TutorialServer
+
+tutorialclient: gen_swift
+ swift run TutorialClient
diff --git a/tutorial/swift/Package.swift b/tutorial/swift/Package.swift
new file mode 100644
index 000000000..ae3f53099
--- /dev/null
+++ b/tutorial/swift/Package.swift
@@ -0,0 +1,53 @@
+// swift-tools-version:5.1
+/*
+ * 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.
+ */
+
+import PackageDescription
+
+let thriftDependency: Target.Dependency = .product(name: "Thrift", package: "swift-dep")
+let package = Package(
+ name: "swift-tutorial",
+ platforms: [
+ .macOS(.v10_13)
+ ],
+ products: [
+ // Products define the executables and libraries a package produces, and make them visible to other packages.
+ .executable(name: "TutorialServer", targets: ["TutorialServer"]),
+ .executable(name: "TutorialClient", targets: ["TutorialClient"]),
+ .executable(name: "TutorialRunner", targets: ["TutorialRunner"])
+ ],
+ dependencies: [
+ // Dependencies declare other packages that this package depends on.
+ .package(path: "./swift-dep"),
+ ],
+ targets: [
+ // Targets are the basic building blocks of a package. A target can define a module or a test suite.
+ // Targets can depend on other targets in this package, and on products in packages this package depends on.
+ .target(
+ name: "Common",
+ dependencies: [thriftDependency]),
+ .target(
+ name: "TutorialServer",
+ dependencies: [thriftDependency, "Common"]),
+ .target(
+ name: "TutorialClient",
+ dependencies: [thriftDependency, "Common"]),
+ .target(name: "TutorialRunner")
+ ]
+)
diff --git a/tutorial/swift/README.md b/tutorial/swift/README.md
new file mode 100644
index 000000000..18a1e7b6d
--- /dev/null
+++ b/tutorial/swift/README.md
@@ -0,0 +1,11 @@
+# Thrift Swift Tutorial
+==================================================
+
+## Run the tutorial code (client + server):
+`make tutorial`
+
+## Run the server only
+`make tutorialserver`
+
+## Run the client only
+`make tutorialclient`
diff --git a/tutorial/swift/Sources/TutorialClient/main.swift b/tutorial/swift/Sources/TutorialClient/main.swift
new file mode 100644
index 000000000..ea8720f34
--- /dev/null
+++ b/tutorial/swift/Sources/TutorialClient/main.swift
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+import Foundation
+import Thrift
+import Common
+
+let transport = try TSocketTransport(hostname: "localhost", port: 9090)
+let inOutProto = TBinaryProtocol(on: transport)
+let client = CalculatorClient(inoutProtocol: inOutProto)
+
+try client.ping()
+print("1+1= \(try client.add(num1: 1, num2: 1))")
+
+let work = Work(num1: 1, num2: 0, op: .divide)
+do {
+ _ = try client.calculate(logid: 1, w: work)
+ assertionFailure("Hm... shouldn't be able to divide by zero")
+} catch let error as InvalidOperation {
+ print("Invalid operation: \(error.why)")
+}
+
+work.op = .subtract
+work.num1 = 15
+work.num2 = 10
+
+print("15-10= \(try client.calculate(logid: 1, w: work))")
+
+print("Done!")
diff --git a/tutorial/swift/Sources/TutorialRunner/main.swift b/tutorial/swift/Sources/TutorialRunner/main.swift
new file mode 100644
index 000000000..7d2439127
--- /dev/null
+++ b/tutorial/swift/Sources/TutorialRunner/main.swift
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+import Foundation
+
+let swiftUrl = URL(fileURLWithPath: "/usr/bin/swift")
+let server = Process()
+server.executableURL = swiftUrl
+server.arguments = ["run", "TutorialServer"]
+try server.run()
+
+Thread.sleep(forTimeInterval: 2)
+
+let client = Process()
+client.executableURL = swiftUrl
+client.arguments = ["run", "TutorialClient"]
+try client.run()
+client.waitUntilExit()
+
+server.terminate()
diff --git a/tutorial/swift/Sources/TutorialServer/CalculatorService.swift b/tutorial/swift/Sources/TutorialServer/CalculatorService.swift
new file mode 100644
index 000000000..2021cfc81
--- /dev/null
+++ b/tutorial/swift/Sources/TutorialServer/CalculatorService.swift
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+import Foundation
+import Common
+
+struct CalculatorError: Error {
+
+}
+class CalculatorService: Calculator {
+ var resultMap = [Int32:SharedStruct]()
+
+ func ping() throws {
+ print("ping()")
+ }
+
+ func add(num1: Int32, num2: Int32) throws -> Int32 {
+ print("add(\(num1), \(num2))")
+ return num1 + num2
+ }
+
+ func calculate(logid: Int32, w: Work) throws -> Int32 {
+ print("calculate(\(logid), \(w))")
+ let result: Int32 = try {
+ switch w.op {
+ case .add:
+ return w.num1 + w.num2
+ case .subtract:
+ return w.num1 - w.num2
+ case .multiply:
+ return w.num1 * w.num2
+ case .divide:
+ guard w.num2 != 0 else {
+ throw InvalidOperation(whatOp: w.op.rawValue, why: "Cannot divide by 0")
+ }
+ return w.num1 / w.num2
+ }
+ }()
+
+ let resultEntry = SharedStruct(key: logid, value: "\(result)")
+ resultMap[logid] = resultEntry
+
+ return result
+ }
+
+ func zip() throws {
+ print("zip()")
+ }
+
+ func getStruct(key: Int32) throws -> SharedStruct {
+ print("getStruct(\(key))")
+ guard let entry = resultMap[key] else {
+ throw CalculatorError()
+ }
+ return entry
+ }
+}
diff --git a/tutorial/swift/Sources/TutorialServer/main.swift b/tutorial/swift/Sources/TutorialServer/main.swift
new file mode 100644
index 000000000..517a8b1f0
--- /dev/null
+++ b/tutorial/swift/Sources/TutorialServer/main.swift
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+import Foundation
+import Common
+import Thrift
+
+let service = CalculatorService()
+let processor = CalculatorProcessor(service: service)
+let server = try TSocketServer(port: 9090, inProtocol: TBinaryProtocol.self, outProtocol: TBinaryProtocol.self, processor: processor)
+
+RunLoop.main.run()
diff --git a/tutorial/swift/swift-dep b/tutorial/swift/swift-dep
new file mode 120000
index 000000000..c757a77c2
--- /dev/null
+++ b/tutorial/swift/swift-dep
@@ -0,0 +1 @@
+../../lib/swift \ No newline at end of file
diff --git a/tutorial/tutorial.thrift b/tutorial/tutorial.thrift
index 6e3313058..f1e291297 100644
--- a/tutorial/tutorial.thrift
+++ b/tutorial/tutorial.thrift
@@ -63,6 +63,7 @@ include "shared.thrift"
* target languages.
*/
+namespace cl tutorial
namespace cpp tutorial
namespace d tutorial
namespace dart tutorial