feat(cli): create .cargo/config if needed

This commit is contained in:
LongYinan 2020-12-29 14:32:09 +08:00
parent cbd4e4d1fc
commit 84a6a8613b
No known key found for this signature in database
GPG key ID: A3FFE134A3E20881
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,18 @@
export const createCargoConfig = (
enableLinuxArm7: boolean,
enableLinuxArm8: boolean,
) => {
let result = ''
if (enableLinuxArm7) {
result = `[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"`
}
if (enableLinuxArm8) {
result = `${result}
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
`
}
return result
}

View file

@ -11,6 +11,7 @@ import { DefaultPlatforms } from '../parse-triple'
import { spawn } from '../spawn'
import { createCargoContent } from './cargo'
import { createCargoConfig } from './cargo-config'
import { createGithubActionsCIYml } from './ci-yml'
import { createIndexJs } from './indexjs'
import { LibRs } from './lib-rs'
@ -153,6 +154,19 @@ export class NewProjectCommand extends Command {
join(process.cwd(), this.dirname!),
join(process.cwd(), this.dirname!),
)
const enableLinuxArm8 = this.targets!.includes('aarch64-unknown-linux-gnu')
const enableLinuxArm7 = this.targets!.includes(
'armv7-unknown-linux-gnueabihf',
)
const cargoConfig = createCargoConfig(enableLinuxArm7, enableLinuxArm8)
if (cargoConfig.length) {
const configDir = join(process.cwd(), this.dirname!, '.config')
if (!this.dryRun) {
mkdirSync(configDir)
this.writeFile(join('.config', 'config.toml'), cargoConfig)
}
}
}
private writeFile(path: string, content: string) {