From cee6c79eb21f769142ecc01fdc5c73fa17d95f7c Mon Sep 17 00:00:00 2001 From: main Date: Sun, 14 Nov 2021 09:56:04 +0100 Subject: [PATCH] Improve Meson + Cargo integration Signed-off-by: main --- i386-unknown-none.txt | 2 +- meson.build | 44 +++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/i386-unknown-none.txt b/i386-unknown-none.txt index 88adad9..1afaa77 100644 --- a/i386-unknown-none.txt +++ b/i386-unknown-none.txt @@ -12,7 +12,7 @@ has_function_printf = false [built-in options] c_args = [ '-ffreestanding' ] cpp_args = [ '-ffreestanding' ] -c_link_args = ['-ffreestanding', '-fno-pic', '-fno-pie', '-nostdlib', '--target=i386-unknown-none', '-march=i386' ] +c_link_args = ['-ffreestanding', '-fno-pic', '-fno-pie', '-nostdlib', '--target=i386-unknown-none' ] rust_link_args = ['-ffreestanding', '-nostdlib' ] cpp_link_args = ['-ffreestanding', '-nostdlib' ] diff --git a/meson.build b/meson.build index 13bf1bd..00c2842 100644 --- a/meson.build +++ b/meson.build @@ -25,33 +25,37 @@ if get_option('release') cargo_args += '--release' endif -## Run `cargo build` to generate the Rust static library containing all the Rust stuff -cargo_result = run_command( - 'sh' -, '-c' -, 'cd $MESON_SOURCE_ROOT ; ' + cargo.path() + ' build ' + ''.join(cargo_args) + ' --color always' +rust_lib = custom_target( + 'x86os-rust' +, output: 'libx86os.a' # target/i386-unknown-none/debug/ +, command: + [ cargo, 'build', '--color', 'always', '-Zunstable-options', '--out-dir', '@OUTDIR@' ] + cargo_args +, input: + [ 'Cargo.toml' + , 'Cargo.lock' + , 'src/gdt/access.rs' + , 'src/gdt/entry.rs' + , 'src/gdt/granularity.rs' + , 'src/gdt/mod.rs' + , 'src/idt/access.rs' + , 'src/idt/entry.rs' + , 'src/idt/mod.rs' + , 'src/rlibc/memory.rs' + , 'src/rlibc/mod.rs' + , 'src/screen/mod.rs' + , 'src/lib.rs' + , 'src/limited_pointer.rs' + , 'src/ring.rs' + ] ) -cargo_stdout = cargo_result.stdout().strip() -cargo_stderr = cargo_result.stderr().strip() -if cargo_stderr != '' - message(cargo_stderr) -elif cargo_stdout != '' - message(cargo_stdout) -else - message('Cargo is done') -endif -if cargo_result.returncode() > 0 - exit(1) -endif -# kernel = executable( 'x86os' , compiled_asm , link_args: [ '-Wl,-T../ld/linker.ld', '-Wl,-melf_i386' ] -, objects: [ 'target/i386-unknown-none/debug/libx86os.a' ] +, link_depends: [ 'ld/linker.ld' ] +, link_with: [ rust_lib ] , link_language: 'c' ) # include_directories: 'src', -# link_depends: 'ld/linker.ld'