meson.build (2821B)
1 rust = import('unstable-rust') 2 3 hb_rs = rust.bindgen( 4 input : '../hb.h', 5 output : 'hb.rs', 6 include_directories: incsrc, 7 args : ['--allowlist-function=hb_.*', 8 '--allowlist-type=hb_.*', 9 '--no-copy=hb_.*', 10 ], 11 ) 12 13 cargo = find_program('cargo') 14 rustfmt = find_program('rustfmt') 15 16 rust_flags = '' 17 cargo_args = [ 18 '--package', 'harfbuzz_rust', 19 '--lib', 20 '--target-dir', meson.current_build_dir(), 21 '--manifest-path', meson.current_source_dir() / 'Cargo.toml', 22 ] 23 24 features = [] 25 if conf.get('HAVE_FONTATIONS', 0) == 1 26 features += ['font'] 27 endif 28 if conf.get('HAVE_HARFRUST', 0) == 1 29 features += ['shape'] 30 endif 31 if features.length() > 0 32 cargo_args += ['--features', ','.join(features)] 33 endif 34 35 buildtype = get_option('buildtype') 36 if buildtype == 'release' or buildtype == 'debugoptimized' 37 cargo_args += [ 38 '-Z', 'build-std=std,panic_abort', 39 '-Z', 'build-std-features=optimize_for_size', 40 ] 41 cargo_args += ['--profile', buildtype] 42 endif 43 44 opt_level = get_option('optimization') 45 rust_flags += ' -C opt-level=' + opt_level 46 47 sources = [ 48 'lib.rs', 49 'font.rs', 50 'shape.rs', 51 ] 52 53 harfbuzz_rust = custom_target( 54 'harfbuzz_rust', 55 input: sources + ['Cargo.toml'], 56 output: ['libharfbuzz_rust.a'], 57 depends: [hb_rs], 58 env: ['OUT_DIR=' + meson.current_build_dir(), 59 'RUSTFLAGS=' + rust_flags, 60 ], 61 command: [ 62 cargo, 'build', 63 ] + cargo_args + [ 64 '-Z', 'unstable-options', 65 '--artifact-dir', meson.current_build_dir(), 66 ], 67 install: true, 68 install_dir: join_paths(get_option('prefix'), 'lib'), 69 ) 70 71 harfbuzz_rust_dep = declare_dependency( 72 link_with: harfbuzz_rust, 73 ) 74 75 clippy_fix = run_target( 76 'clippy-fix', 77 env: ['OUT_DIR=' + meson.current_build_dir()], 78 depends: [hb_rs, harfbuzz_rust], 79 command: [ 80 cargo, 'clippy', 81 ] + cargo_args + [ 82 '--allow-dirty', '--fix', 83 ], 84 ) 85 if get_option('tests').enabled() and cargo.found() 86 test( 87 'clippy', 88 cargo, 89 env: ['OUT_DIR=' + meson.current_build_dir()], 90 depends: [hb_rs, harfbuzz_rust], 91 args: [ 92 'clippy', 93 ] + cargo_args + [ 94 '--', '-D', 'warnings', 95 ], 96 timeout: 300, 97 ) 98 endif 99 100 # Convert source files in their src dir by transforming the `sources` list. 101 sources_in_source_dir = [] 102 foreach s : sources 103 sources_in_source_dir += meson.current_source_dir() / s 104 endforeach 105 106 rustfmt_fix = run_target( 107 'rustfmt-fix', 108 env: ['OUT_DIR=' + meson.current_build_dir()], 109 depends: [hb_rs], 110 command: [ 111 rustfmt, 112 '--edition', '2021', 113 '--', 114 sources_in_source_dir, 115 ], 116 ) 117 if get_option('tests').enabled() and rustfmt.found() 118 test( 119 'rustfmt', 120 rustfmt, 121 env: ['OUT_DIR=' + meson.current_build_dir()], 122 depends: [hb_rs], 123 args: [ 124 '--check', 125 '--edition', '2021', 126 '--', 127 sources_in_source_dir, 128 ], 129 ) 130 endif