The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.5 KiB
132 lines
4.5 KiB
5 years ago
|
# Copyright 2017 The Meson development team
|
||
|
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
3 years ago
|
from __future__ import annotations
|
||
3 years ago
|
import itertools
|
||
3 years ago
|
import typing as T
|
||
|
|
||
2 years ago
|
from . import ExtensionModule, ModuleReturnValue, ModuleInfo
|
||
3 years ago
|
from .. import build
|
||
5 years ago
|
from .. import mesonlib
|
||
3 years ago
|
from ..interpreter.type_checking import CT_INPUT_KW
|
||
|
from ..interpreterbase.decorators import KwargInfo, typed_kwargs, typed_pos_args
|
||
5 years ago
|
|
||
3 years ago
|
if T.TYPE_CHECKING:
|
||
3 years ago
|
from typing_extensions import TypedDict
|
||
|
|
||
|
from . import ModuleState
|
||
|
from ..interpreter import Interpreter
|
||
3 years ago
|
from ..programs import ExternalProgram
|
||
5 years ago
|
|
||
3 years ago
|
class ProjectKwargs(TypedDict):
|
||
|
|
||
|
sources: T.List[T.Union[mesonlib.FileOrString, build.GeneratedTypes]]
|
||
|
constraint_file: T.Union[mesonlib.FileOrString, build.GeneratedTypes]
|
||
|
|
||
5 years ago
|
class IceStormModule(ExtensionModule):
|
||
|
|
||
2 years ago
|
INFO = ModuleInfo('FPGA/Icestorm', '0.45.0', unstable=True)
|
||
2 years ago
|
|
||
3 years ago
|
def __init__(self, interpreter: Interpreter) -> None:
|
||
5 years ago
|
super().__init__(interpreter)
|
||
3 years ago
|
self.tools: T.Dict[str, ExternalProgram] = {}
|
||
4 years ago
|
self.methods.update({
|
||
|
'project': self.project,
|
||
|
})
|
||
5 years ago
|
|
||
3 years ago
|
def detect_tools(self, state: ModuleState) -> None:
|
||
3 years ago
|
self.tools['yosys'] = state.find_program('yosys')
|
||
|
self.tools['arachne'] = state.find_program('arachne-pnr')
|
||
|
self.tools['icepack'] = state.find_program('icepack')
|
||
|
self.tools['iceprog'] = state.find_program('iceprog')
|
||
|
self.tools['icetime'] = state.find_program('icetime')
|
||
5 years ago
|
|
||
3 years ago
|
@typed_pos_args('icestorm.project', str,
|
||
|
varargs=(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex,
|
||
|
build.GeneratedList))
|
||
|
@typed_kwargs(
|
||
|
'icestorm.project',
|
||
|
CT_INPUT_KW.evolve(name='sources'),
|
||
|
KwargInfo(
|
||
|
'constraint_file',
|
||
|
(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList),
|
||
|
required=True,
|
||
|
)
|
||
|
)
|
||
|
def project(self, state: ModuleState,
|
||
|
args: T.Tuple[str, T.List[T.Union[mesonlib.FileOrString, build.GeneratedTypes]]],
|
||
|
kwargs: ProjectKwargs) -> ModuleReturnValue:
|
||
3 years ago
|
if not self.tools:
|
||
|
self.detect_tools(state)
|
||
3 years ago
|
proj_name, arg_sources = args
|
||
|
all_sources = self.interpreter.source_strings_to_files(
|
||
|
list(itertools.chain(arg_sources, kwargs['sources'])))
|
||
|
|
||
|
blif_target = build.CustomTarget(
|
||
|
f'{proj_name}_blif',
|
||
|
state.subdir,
|
||
|
state.subproject,
|
||
|
state.environment,
|
||
|
[self.tools['yosys'], '-q', '-p', 'synth_ice40 -blif @OUTPUT@', '@INPUT@'],
|
||
|
all_sources,
|
||
|
[f'{proj_name}.blif'],
|
||
|
)
|
||
|
|
||
|
asc_target = build.CustomTarget(
|
||
|
f'{proj_name}_asc',
|
||
|
state.subdir,
|
||
|
state.subproject,
|
||
|
state.environment,
|
||
|
[self.tools['arachne'], '-q', '-d', '1k', '-p', '@INPUT@', '-o', '@OUTPUT@'],
|
||
|
[kwargs['constraint_file'], blif_target],
|
||
|
[f'{proj_name}.asc'],
|
||
|
)
|
||
|
|
||
|
bin_target = build.CustomTarget(
|
||
|
f'{proj_name}_bin',
|
||
|
state.subdir,
|
||
|
state.subproject,
|
||
|
state.environment,
|
||
|
[self.tools['icepack'], '@INPUT@', '@OUTPUT@'],
|
||
|
[asc_target],
|
||
|
[f'{proj_name}.bin'],
|
||
|
build_by_default=True,
|
||
|
)
|
||
|
|
||
|
upload_target = build.RunTarget(
|
||
|
f'{proj_name}-upload',
|
||
|
[self.tools['iceprog'], bin_target],
|
||
|
[],
|
||
|
state.subdir,
|
||
|
state.subproject,
|
||
|
state.environment,
|
||
|
)
|
||
|
|
||
|
time_target = build.RunTarget(
|
||
|
f'{proj_name}-time',
|
||
|
[self.tools['icetime'], bin_target],
|
||
|
[],
|
||
|
state.subdir,
|
||
|
state.subproject,
|
||
|
state.environment,
|
||
|
)
|
||
|
|
||
|
return ModuleReturnValue(
|
||
|
None,
|
||
|
[blif_target, asc_target, bin_target, upload_target, time_target])
|
||
|
|
||
|
|
||
|
def initialize(interp: Interpreter) -> IceStormModule:
|
||
|
return IceStormModule(interp)
|