From: Tilman Sauerbeck Date: Sun, 29 Dec 2019 11:55:24 +0000 (+0100) Subject: build: Use rustc to link the binaries instead of gcc. X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=8b09b780219fb53132e4271e4e71f2c779c47321;p=gps-watch.git build: Use rustc to link the binaries instead of gcc. This simplifies the build system by removing the need for libapplication.a, libbootloader.a and the two start.c copies. --- diff --git a/SConscript.target b/SConscript.target index 1e5f402..7beba88 100644 --- a/SConscript.target +++ b/SConscript.target @@ -40,8 +40,10 @@ libgcc_path = \ env.Append(RUSTCFLAGS = [ '-C', 'opt-level=s', + '-C', 'link-arg={}'.format(libgcc_path), '--target=thumbv6m-none-eabi', '-L', '$LIBPATH', + '-l', 'common', ]) env.Append(LINKFLAGS = [ @@ -50,79 +52,53 @@ env.Append(LINKFLAGS = [ SConscript('SConscript.libcommon', exports='env', duplicate=0) -libbootloader_source_files = [ +bootloader_source_files = [ 'src/bootloader/main.rs', # Must be listed first (see below). 'src/bootloader/bootloader.rs', 'src/bootloader/flash.rs', ] -start_o = env.Object('src/bootloader/start.c') - for s in ['intermediate', 'final']: - libbootloader_env = env.Clone() + bootloader_env = env.Clone() - libbootloader_env.Append(RUSTCFLAGS = [ + bootloader_env.Append(RUSTCFLAGS = [ + '-C', 'link-arg=-Tsrc/bootloader/bootloader-{}.ld'.format(s), '--cfg', 'bootloader_type=\\"{}\\"'.format(s) ]) - libbootloader = libbootloader_env.Rustc('libbootloader-{}.a'.format(s), - libbootloader_source_files[0]) - - for f in libbootloader_source_files: - Depends(libbootloader, f) - - Depends(libbootloader, 'libcommon.rlib') - Depends(libbootloader, 'libcommon.a') - - bootloader_env = env.Clone() - - bootloader_env.Append(LINKFLAGS = [ - '-Tsrc/bootloader/bootloader-{}.ld'.format(s), - ]) + bootloader_elf = \ + bootloader_env.Rustc('gps-watch-bootloader-{}.elf'.format(s), + bootloader_source_files[0]) - bootloader_libs = [ - 'bootloader-{}'.format(s), - 'common', - File(libgcc_path), - ] + for f in bootloader_source_files: + Depends(bootloader_elf, f) - bootloader_elf = \ - bootloader_env.Program('gps-watch-bootloader-{}.elf'.format(s), - start_o, LIBS = bootloader_libs) + Depends(bootloader_elf, 'libcommon.rlib') + Depends(bootloader_elf, 'libcommon.a') bootloader_bin = bootloader_env.Objcopy(bootloader_elf) Default(bootloader_bin) -libapplication_source_files = [ +application_source_files = [ 'src/application/main.rs', # Must be listed first (see below). ] -libapplication = env.Rustc('libapplication.a', libapplication_source_files[0]) - -for f in libapplication_source_files: - Depends(libapplication, f) - -Depends(libapplication, 'libcommon.rlib') -Depends(libapplication, 'libcommon.a') - -start_o = env.Object('src/application/start.c') - application_env = env.Clone() -application_env.Append(LINKFLAGS = [ - '-Tsrc/application/application.ld' +application_env.Append(RUSTCFLAGS = [ + '-C', 'link-arg=-Tsrc/application/application.ld', ]) -application_libs = [ - 'application', - 'common', - File(libgcc_path), -] +application_elf = application_env.Rustc('gps-watch-application.elf', + application_source_files[0]) + +for f in application_source_files: + Depends(application_elf, f) -application_elf = application_env.Program('gps-watch-application.elf', - start_o, LIBS = application_libs) +Depends(application_elf, 'libcommon.rlib') +Depends(application_elf, 'libcommon.a') application_bin = application_env.Objcopy(application_elf) diff --git a/src/application/main.rs b/src/application/main.rs index b1bf3af..d2e391d 100644 --- a/src/application/main.rs +++ b/src/application/main.rs @@ -22,7 +22,7 @@ */ #![no_std] -#![crate_type="staticlib"] +#![no_main] #[link(name="libcommon.rlib")] extern crate common; @@ -44,7 +44,7 @@ extern { } #[no_mangle] -pub unsafe extern fn main() { +pub unsafe extern "C" fn _start() -> ! { clock::configure(); systick::init(); port::init(); diff --git a/src/application/start.c b/src/application/start.c deleted file mode 100644 index 5363ac0..0000000 --- a/src/application/start.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2019 Tilman Sauerbeck (tilman at code-monkey de) - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -extern void main(); - -__attribute__((noreturn)) void -_start (void) -{ - main(); - - for (;;) { - } -} diff --git a/src/bootloader/bootloader-final.ld b/src/bootloader/bootloader-final.ld index 86837c4..a30e47d 100644 --- a/src/bootloader/bootloader-final.ld +++ b/src/bootloader/bootloader-final.ld @@ -83,7 +83,7 @@ SECTIONS *(.rodata*) KEEP(*(.eh_frame*)) - } > FLASH =0xff + } > FLASH =0xffffffff .ARM.extab : { diff --git a/src/bootloader/main.rs b/src/bootloader/main.rs index 321166c..815429e 100644 --- a/src/bootloader/main.rs +++ b/src/bootloader/main.rs @@ -22,7 +22,7 @@ */ #![no_std] -#![crate_type="staticlib"] +#![no_main] #[link(name="libcommon.rlib")] extern crate common; @@ -84,7 +84,7 @@ fn bootloader_requested() -> bool { } #[no_mangle] -pub unsafe extern fn main() { +pub unsafe extern "C" fn _start() -> ! { watchdog::disable(); clock::configure(); systick::init(); diff --git a/src/bootloader/start.c b/src/bootloader/start.c deleted file mode 100644 index 5363ac0..0000000 --- a/src/bootloader/start.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2019 Tilman Sauerbeck (tilman at code-monkey de) - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -extern void main(); - -__attribute__((noreturn)) void -_start (void) -{ - main(); - - for (;;) { - } -}