Skip to content

Commit 544a5d2

Browse files
committed
Update ffigen_codelab
1 parent bbe6500 commit 544a5d2

File tree

33 files changed

+9305
-9125
lines changed

33 files changed

+9305
-9125
lines changed

ffigen_codelab/codelab_rebuild.yaml

Lines changed: 110 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ steps:
3434
}
3535
]
3636
}
37+
- name: Patch example/android/app/build.gradle.kts
38+
path: ffigen_app/example/android/app/build.gradle.kts
39+
patch-u: |
40+
--- a/ffigen_codelab/step_03/example/android/app/build.gradle.kts
41+
+++ b/ffigen_codelab/step_03/example/android/app/build.gradle.kts
42+
@@ -8,7 +8,7 @@ plugins {
43+
android {
44+
namespace = "com.example.ffigen_app_example"
45+
compileSdk = flutter.compileSdkVersion
46+
- ndkVersion = flutter.ndkVersion
47+
+ ndkVersion = "27.0.12077973"
48+
49+
compileOptions {
50+
sourceCompatibility = JavaVersion.VERSION_11
3751
- name: dart format
3852
dart: format ffigen_app
3953
- name: dart fix ffigen_app
@@ -53,24 +67,24 @@ steps:
5367
flutter: pub upgrade --major-versions
5468
- name: Build iOS simulator bundle
5569
path: ffigen_app/example
56-
platforms: [ macos ]
70+
platforms: [macos]
5771
flutter: build ios --simulator
5872
- name: Build macOS app
5973
path: ffigen_app/example
60-
platforms: [ macos ]
74+
platforms: [macos]
6175
flutter: build macos --debug
6276
- name: Build Android app
6377
path: ffigen_app/example
64-
platforms: [ macos ]
65-
flutter: build apk --debug
78+
platforms: [macos]
79+
flutter: build apk --debug
6680
- name: Build Windows app
6781
path: ffigen_app/example
68-
platforms: [ windows ]
69-
flutter: build windows --debug
82+
platforms: [windows]
83+
flutter: build windows --debug
7084
- name: Build Linux app
7185
path: ffigen_app/example
72-
platforms: [ linux ]
73-
flutter: build linux --debug
86+
platforms: [linux]
87+
flutter: build linux --debug
7488
- name: Flutter clean
7589
path: ffigen_app/example
7690
flutter: clean
@@ -89,22 +103,22 @@ steps:
89103
path: ffigen_app/src/duktape.tar.xz
90104
retrieve-url: https://duktape.org/duktape-2.7.0.tar.xz
91105
- name: Unarchive duktape.tar.xz with tar
92-
platforms: [ linux, macos ]
106+
platforms: [linux, macos]
93107
path: ffigen_app/src
94108
tar: xf duktape.tar.xz
95109
- name: Unarchive duktape.tar.xz with 7z
96-
platforms: [ windows ]
110+
platforms: [windows]
97111
path: ffigen_app/src
98112
7z: x duktape.tar.xz
99113
- name: Unarchive duktape.tar with 7z
100-
platforms: [ windows ]
114+
platforms: [windows]
101115
path: ffigen_app/src
102116
7z: x duktape.tar
103117
- name: Remove duktape.tar.xz
104118
path: ffigen_app/src
105119
rm: duktape.tar.xz
106120
- name: Remove duktape.tar
107-
platforms: [ windows ]
121+
platforms: [windows]
108122
path: ffigen_app/src
109123
rm: duktape.tar
110124
- name: Copy duktape-2.7.0/src/duktape.c
@@ -137,7 +151,7 @@ steps:
137151
description: |
138152
- Bindings for `src/ffigen_app.h`.
139153
+ Bindings for `src/duktape.h`.
140-
154+
141155
Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
142156
-output: 'lib/ffigen_app_bindings_generated.dart'
143157
+output: 'lib/duktape_bindings_generated.dart'
@@ -311,19 +325,19 @@ steps:
311325
+++ a/ffigen_codelab/step_05/src/CMakeLists.txt
312326
@@ -6,12 +6,19 @@ cmake_minimum_required(VERSION 3.10)
313327
project(ffigen_app_library VERSION 0.0.1 LANGUAGES C)
314-
328+
315329
add_library(ffigen_app SHARED
316330
- "ffigen_app.c"
317331
+ duktape.c
318332
)
319-
333+
320334
set_target_properties(ffigen_app PROPERTIES
321335
- PUBLIC_HEADER ffigen_app.h
322336
+ PUBLIC_HEADER duktape.h
323337
+ PRIVATE_HEADER duk_config.h
324338
OUTPUT_NAME "ffigen_app"
325339
)
326-
340+
327341
+if (WIN32)
328342
+set_target_properties(ffigen_app PROPERTIES
329343
+ WINDOWS_EXPORT_ALL_SYMBOLS ON
@@ -363,12 +377,12 @@ steps:
363377
dart: analyze --fatal-infos
364378
- name: Build Windows app
365379
path: ffigen_app/example
366-
platforms: [ windows ]
367-
flutter: build windows --debug
380+
platforms: [windows]
381+
flutter: build windows --debug
368382
- name: Build Linux app
369383
path: ffigen_app/example
370-
platforms: [ linux ]
371-
flutter: build linux --debug
384+
platforms: [linux]
385+
flutter: build linux --debug
372386
- name: Flutter clean
373387
path: ffigen_app/example
374388
flutter: clean
@@ -408,24 +422,24 @@ steps:
408422
dart: analyze --fatal-infos
409423
- name: Build iOS simulator bundle
410424
path: ffigen_app/example
411-
platforms: [ macos ]
425+
platforms: [macos]
412426
flutter: build ios --simulator
413427
- name: Build macOS app
414428
path: ffigen_app/example
415-
platforms: [ macos ]
429+
platforms: [macos]
416430
flutter: build macos --debug
417431
- name: Build Android app
418432
path: ffigen_app/example
419-
platforms: [ macos ]
420-
flutter: build apk --debug
433+
platforms: [macos]
434+
flutter: build apk --debug
421435
- name: Build Windows app
422436
path: ffigen_app/example
423-
platforms: [ windows ]
424-
flutter: build windows --debug
437+
platforms: [windows]
438+
flutter: build windows --debug
425439
- name: Build Linux app
426440
path: ffigen_app/example
427-
platforms: [ linux ]
428-
flutter: build linux --debug
441+
platforms: [linux]
442+
flutter: build linux --debug
429443
- name: Flutter clean
430444
path: ffigen_app/example
431445
flutter: clean
@@ -447,9 +461,9 @@ steps:
447461
import 'dart:io' show Platform;
448462
import 'package:ffi/ffi.dart' as ffi;
449463
+import 'package:path/path.dart' as p;
450-
464+
451465
import 'duktape_bindings_generated.dart';
452-
466+
453467
@@ -13,12 +14,37 @@ const String _libName = 'ffigen_app';
454468
/// The dynamic library in which the symbols for [DuktapeBindings] can be found.
455469
final DynamicLibrary _dylib = () {
@@ -491,13 +505,13 @@ steps:
491505
@@ -38,13 +64,13 @@ class Duktape {
492506
);
493507
}
494-
508+
495509
- void evalString(String jsCode) {
496510
+ String evalString(String jsCode) {
497511
// From duktape.h:
498512
// #define duk_peval_string(ctx,src) \
499513
// (duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
500-
514+
501515
var nativeUtf8 = jsCode.toNativeUtf8();
502516
- _bindings.duk_eval_raw(
503517
+ final evalResult = _bindings.duk_eval_raw(
@@ -515,7 +529,7 @@ steps:
515529
+
516530
+ return _retrieveTopOfStackAsString();
517531
}
518-
532+
519533
- int getInt(int index) {
520534
- return _bindings.duk_get_int(ctx, index);
521535
+ String _retrieveTopOfStackAsString() {
@@ -527,7 +541,7 @@ steps:
527541
+ ffi.calloc.free(outLengthPtr);
528542
+ return returnVal;
529543
}
530-
544+
531545
void dispose() {
532546
- name: Create example/lib/duktape_message.dart
533547
path: ffigen_app/example/lib/duktape_message.dart
@@ -536,9 +550,9 @@ steps:
536550
// Use of this source code is governed by a BSD-style license that can be
537551
// found in the LICENSE file.
538552
import 'package:freezed_annotation/freezed_annotation.dart';
539-
553+
540554
part 'duktape_message.freezed.dart';
541-
555+
542556
@freezed
543557
class DuktapeMessage with _$DuktapeMessage {
544558
factory DuktapeMessage.evaluate(String code) = DuktapeMessageCode;
@@ -636,45 +650,51 @@ steps:
636650
child: ListView.builder(
637651
padding: const EdgeInsets.all(8.0),
638652
reverse: true,
639-
itemBuilder:
640-
(context, idx) => messages[idx].when(
641-
evaluate:
642-
(str) => Padding(
643-
padding: const EdgeInsets.symmetric(vertical: 2),
644-
child: Text(
645-
'> $str',
646-
style: GoogleFonts.firaCode(
647-
textStyle:
648-
Theme.of(context).textTheme.titleMedium,
649-
),
650-
),
651-
),
652-
response:
653-
(str) => Padding(
654-
padding: const EdgeInsets.symmetric(vertical: 2),
655-
child: Text(
656-
'= $str',
657-
style: GoogleFonts.firaCode(
658-
textStyle:
659-
Theme.of(context).textTheme.titleMedium,
660-
color: Colors.blue[800],
661-
),
662-
),
663-
),
664-
error:
665-
(str) => Padding(
666-
padding: const EdgeInsets.symmetric(vertical: 2),
667-
child: Text(
668-
str,
669-
style: GoogleFonts.firaCode(
670-
textStyle:
671-
Theme.of(context).textTheme.titleSmall,
672-
color: Colors.red[800],
673-
fontWeight: FontWeight.bold,
674-
),
675-
),
676-
),
653+
itemBuilder: (context, idx) {
654+
return switch (messages[idx]) {
655+
DuktapeMessageCode code => Padding(
656+
padding: const EdgeInsets.symmetric(vertical: 2),
657+
child: Text(
658+
'> ${code.code}',
659+
style: GoogleFonts.firaCode(
660+
textStyle: Theme.of(context).textTheme.titleMedium,
661+
),
662+
),
677663
),
664+
DuktapeMessageResponse response => Padding(
665+
padding: const EdgeInsets.symmetric(vertical: 2),
666+
child: Text(
667+
'= ${response.result}',
668+
style: GoogleFonts.firaCode(
669+
textStyle: Theme.of(context).textTheme.titleMedium,
670+
color: Colors.blue[800],
671+
),
672+
),
673+
),
674+
DuktapeMessageError error => Padding(
675+
padding: const EdgeInsets.symmetric(vertical: 2),
676+
child: Text(
677+
error.log,
678+
style: GoogleFonts.firaCode(
679+
textStyle: Theme.of(context).textTheme.titleSmall,
680+
color: Colors.red[800],
681+
fontWeight: FontWeight.bold,
682+
),
683+
),
684+
),
685+
DuktapeMessage message => Padding(
686+
padding: const EdgeInsets.symmetric(vertical: 2),
687+
child: Text(
688+
'Unhandled message $message',
689+
style: GoogleFonts.firaCode(
690+
textStyle: Theme.of(context).textTheme.titleSmall,
691+
color: Colors.red[800],
692+
fontWeight: FontWeight.bold,
693+
),
694+
),
695+
),
696+
};
697+
},
678698
itemCount: messages.length,
679699
),
680700
),
@@ -719,10 +739,9 @@ steps:
719739
margin: const EdgeInsets.symmetric(horizontal: 4.0),
720740
child: IconButton(
721741
icon: const Icon(Icons.send),
722-
onPressed:
723-
_isComposing
724-
? () => _handleSubmitted(_controller.text)
725-
: null,
742+
onPressed: _isComposing
743+
? () => _handleSubmitted(_controller.text)
744+
: null,
726745
),
727746
),
728747
],
@@ -741,16 +760,16 @@ steps:
741760
import 'package:ffigen_app_example/main.dart';
742761
import 'package:flutter_riverpod/flutter_riverpod.dart';
743762
import 'package:flutter_test/flutter_test.dart';
744-
763+
745764
void main() {
746765
testWidgets('DuktapeApp displays the title', (tester) async {
747766
// Build our app and trigger a frame.
748767
await tester.pumpWidget(const ProviderScope(child: DuktapeApp()));
749-
768+
750769
// Verify that our app displays the title
751770
expect(find.text('Duktape REPL'), findsOneWidget);
752771
});
753-
772+
754773
test('Duktape.evalString', () {
755774
final duktape = Duktape();
756775
final response = duktape.evalString('1+2');
@@ -813,28 +832,28 @@ steps:
813832
dart: analyze --fatal-infos
814833
- name: Build iOS simulator bundle
815834
path: ffigen_app/example
816-
platforms: [ macos ]
835+
platforms: [macos]
817836
flutter: build ios --simulator
818837
- name: Build macOS app
819838
path: ffigen_app/example
820-
platforms: [ macos ]
839+
platforms: [macos]
821840
flutter: build macos --debug
822841
- name: Test macOS bundle
823842
path: ffigen_app/example
824-
platforms: [ macos ]
843+
platforms: [macos]
825844
flutter: test
826845
- name: Build Android app
827846
path: ffigen_app/example
828-
platforms: [ macos ]
829-
flutter: build apk --debug
847+
platforms: [macos]
848+
flutter: build apk --debug
830849
- name: Build Windows app
831850
path: ffigen_app/example
832-
platforms: [ windows ]
833-
flutter: build windows --debug
851+
platforms: [windows]
852+
flutter: build windows --debug
834853
- name: Build Linux app
835854
path: ffigen_app/example
836-
platforms: [ linux ]
837-
flutter: build linux --debug
855+
platforms: [linux]
856+
flutter: build linux --debug
838857
- name: Flutter clean
839858
path: ffigen_app/example
840859
flutter: clean
@@ -843,4 +862,4 @@ steps:
843862
from: ffigen_app
844863
to: step_07
845864
- name: Cleanup ffigen_app
846-
rmdir: ffigen_app
865+
rmdir: ffigen_app

ffigen_codelab/step_03/example/android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
android {
99
namespace = "com.example.ffigen_app_example"
1010
compileSdk = flutter.compileSdkVersion
11-
ndkVersion = flutter.ndkVersion
11+
ndkVersion = "27.0.12077973"
1212

1313
compileOptions {
1414
sourceCompatibility = JavaVersion.VERSION_11

0 commit comments

Comments
 (0)